Skip to content

Commit

Permalink
Try validator other way
Browse files Browse the repository at this point in the history
  • Loading branch information
amCap1712 committed Apr 6, 2022
1 parent e3a52c9 commit 3a909d4
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions critiquebrainz/frontend/forms/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ def __call__(self, form, field):
raise ValidationError(self.message)


def optional_license(message):
def _license(form, field):
if form.state.data == "draft":
return
else:
# https://wtforms.readthedocs.io/en/2.3.x/_modules/wtforms/validators/#InputRequired
if not field.raw_data or not field.raw_data[0]:
raise ValidationError(message)
return _license


# Loading supported languages
languages = []
for language_code in supported_languages:
Expand All @@ -48,8 +37,7 @@ class ReviewEditForm(FlaskForm):
choices=[
('CC BY-SA 3.0', lazy_gettext('Allow commercial use of this review(<a href="https://creativecommons.org/licenses/by-sa/3.0/" target="_blank">CC BY-SA 3.0 license</a>)')), # noqa: E501
('CC BY-NC-SA 3.0', lazy_gettext('Do not allow commercial use of this review, unless approved by MetaBrainz Foundation (<a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">CC BY-NC-SA 3.0 license</a>)')), # noqa: E501
],
validators=[optional_license(lazy_gettext("You need to choose a license"))])
])
remember_license = BooleanField(lazy_gettext("Remember this license choice for further preference"))
language = SelectField(lazy_gettext("You need to accept the license agreement!"), choices=languages)
rating = IntegerField(lazy_gettext("Rating"), widget=Input(input_type='number'), validators=[validators.Optional()])
Expand All @@ -67,6 +55,14 @@ def validate(self):
return False
return True

def validate_license_choice(self, field):
if self.state.data == "draft":
return
else:
# https://wtforms.readthedocs.io/en/2.3.x/_modules/wtforms/validators/#InputRequired
if not field.raw_data or not field.raw_data[0]:
raise ValidationError(lazy_gettext("You need to choose a license"))


class ReviewCreateForm(ReviewEditForm):
agreement = BooleanField(validators=[
Expand Down

0 comments on commit 3a909d4

Please sign in to comment.