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

Improvements to AMY docs and UI #2337

Conversation

elichad
Copy link
Contributor

@elichad elichad commented Feb 9, 2023

Fixes some items in #2328, fixes #2331

@elichad elichad self-assigned this Feb 9, 2023
@elichad elichad requested review from pbanaszkiewicz and maneesha and removed request for maneesha February 9, 2023 10:48
Copy link
Contributor

@pbanaszkiewicz pbanaszkiewicz left a 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.

mkdocs.yml Show resolved Hide resolved
raise forms.ValidationError(
"You must add tags corresponding to these curricula."
)
missing_tags.add(tag)
Copy link
Contributor

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))

if missing_tags:
raise forms.ValidationError(
f"You must add tags corresponding to these curricula. Missing tags: {', '.join(missing_tags)}"
)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -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)}"""
Copy link
Contributor

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.

Copy link
Contributor

@pbanaszkiewicz pbanaszkiewicz left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice typing!

@elichad elichad merged commit fe82d30 into develop Feb 17, 2023
@elichad elichad deleted the feature/2328-Comments-from-review-of-AMY-docs-and-corresponding-UI-operations branch August 2, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different URLs on /workshops/events vs /workshops/event/<slug>
2 participants