Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS-4865: validating empty spaces between short names of the fund and round and also updating intelij idea setting #143

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .idea/runConfigurations/FAB.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/blueprints/fund_builder/forms/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from wtforms.validators import Length

from app.db.models.fund import FundingType
from app.shared.helpers import no_spaces_between_letters


class GovUkRadioEnumField(RadioField):
Expand Down Expand Up @@ -36,7 +37,7 @@ class FundForm(FlaskForm):
name_cy = StringField("Name (Welsh)", description="Leave blank for English-only funds")
title_en = StringField("Title (English)", validators=[DataRequired()])
title_cy = StringField("Title (Welsh)", description="Leave blank for English-only funds")
short_name = StringField("Short Name", validators=[DataRequired(), Length(max=10)])
short_name = StringField("Short Name", validators=[DataRequired(), Length(max=10), no_spaces_between_letters])
description_en = TextAreaField("Description", validators=[DataRequired()])
description_cy = TextAreaField("Description (Welsh)", description="Leave blank for English-only funds")
welsh_available = RadioField("Welsh Available", choices=[("true", "Yes"), ("false", "No")], default="false")
Expand Down
4 changes: 3 additions & 1 deletion app/blueprints/fund_builder/forms/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from wtforms.validators import Length
from wtforms.validators import ValidationError

from app.shared.helpers import no_spaces_between_letters


def validate_json_field(form, field):
str_content = field.data
Expand Down Expand Up @@ -126,7 +128,7 @@ class RoundForm(FlaskForm):
short_name = StringField(
"Short Name",
description="Choose a unique short name with 6 or fewer characters",
validators=[DataRequired(), Length(max=6)],
validators=[DataRequired(), Length(max=6), no_spaces_between_letters],
)
opens = FormField(DateInputForm, label="Opens")
deadline = FormField(DateInputForm, label="Deadline")
Expand Down
13 changes: 12 additions & 1 deletion app/shared/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re
from dataclasses import asdict
from dataclasses import is_dataclass
from wtforms.validators import ValidationError

from app.db.models import Page

Expand Down Expand Up @@ -51,4 +53,13 @@ def error_formatter(errors):
errorsList.append({'text': "Enter valid datetime", 'href': f'#{field}'})
if errorsList:
error = {'titleText': "There is a problem", 'errorList': errorsList}
return error
return error


# Custom validator to check for spaces between letters
def no_spaces_between_letters(form, field):
# Regular expression to check for spaces between letters
if not field.data:
return
if re.search(r'\b\w+\s+\w+\b', field.data): # Matches sequences with spaces in between
raise ValidationError("Spaces between letters are not allowed.")
Loading