-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Improvements to AMY docs and UI #2337
Improvements to AMY docs and UI #2337
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor styling could be improved, but overall it looks good.
amy/workshops/forms.py
Outdated
raise forms.ValidationError( | ||
"You must add tags corresponding to these curricula." | ||
) | ||
missing_tags.add(tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively:
missing_tags = expected_tags - set(tags.values_list('name', flat=True))
amy/workshops/forms.py
Outdated
if missing_tags: | ||
raise forms.ValidationError( | ||
f"You must add tags corresponding to these curricula. Missing tags: {', '.join(missing_tags)}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this method clean_curricula
validates tags based on selected curricula. I think it should be clean_tags
, so that at least the error shows up in proper place.
Also it could be beneficial for user experience if the fields in the form switched places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - though updating this was less straightforward than I thought. In short, curricula
wasn't in cleaned_data
at the time clean_tags
was run during validation, so I've changed this method to be called during clean()
- following these Django docs https://docs.djangoproject.com/en/4.1/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other. Can you do a quick re-review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elichad Looks okay except for the way validation error is handled.
We have this pattern:
errors = {}
if validation_failed_for_a_field:
errors["field"] = ValidationError("Text")
# ...
if errors:
raise ValidationError(errors)
For example: CommunityRoleForm.clean
, amy/communityroles/forms.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the reference, done
amy/workshops/forms.py
Outdated
@@ -580,7 +580,8 @@ def clean_curricula(self): | |||
missing_tags.add(tag) | |||
if missing_tags: | |||
raise forms.ValidationError( | |||
f"You must add tags corresponding to these curricula. Missing tags: {', '.join(missing_tags)}" | |||
f"""You must add tags corresponding to these curricula. """ | |||
f"""Missing tags: {', '.join(missing_tags)}""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In lines 583 and 584 you don't need to use """
. You can use "
just fine.
Additionally, in L583 you defined an f-string, which is not used and will highlight in some linters. Drop f
and you should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
if not cleaned_data: | ||
return cleaned_data | ||
|
||
errors: defaultdict[str, list[ValidationError]] = defaultdict(list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice typing!
Fixes some items in #2328, fixes #2331