Skip to content

Advanced Registration View#446

Open
alex-budko wants to merge 1 commit into
masterfrom
ical_download
Open

Advanced Registration View#446
alex-budko wants to merge 1 commit into
masterfrom
ical_download

Conversation

@alex-budko
Copy link
Copy Markdown
Contributor

Added linting changes to the advanced registration view

Advanced registration view changes for Penn Mobile
@alex-budko alex-budko closed this Dec 30, 2022
@alex-budko alex-budko reopened this Jan 4, 2023
@alex-budko
Copy link
Copy Markdown
Contributor Author

Unlinted copy of the PR for the advanced registration view

Copy link
Copy Markdown
Contributor

@AaDalal AaDalal left a comment

Choose a reason for hiding this comment

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

Good work here, but there are a few big things to handle before we merge:

  • Do we want to allow more than 1 advanced registration schedule per user per semester? If so, why? If not, we need to preserve that invariant, probably by overriding the save method of Schedule.
  • How can we make sure that the inputs to the view are properly validated?

Couple of general notes:

  • IMPORTANT: whenever you make changes to a model, you should run makemigrations and migrate and commit the migrations file that produces. I don't see the migration here, which could be problematic!
  • IMPORTANT: you need to test your code using the unit testing framework (see the backend/tests folder)
  • make the description of the pull request more descriptive (see some of our previous PRs, particular @mureytasroc's for inspo).
  • The title can similarly more clearly describe what this feature adds.

Comment thread backend/plan/models.py
)

advanced_registration = models.BooleanField(
blank=False,
Copy link
Copy Markdown
Contributor

@AaDalal AaDalal Jan 5, 2023

Choose a reason for hiding this comment

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

Do not need because blank should be false by default

Comment thread backend/plan/models.py
updated_at = models.DateTimeField(auto_now=True)

class Meta:
unique_together = (("name", "semester", "person"),)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think you need this.

Comment thread backend/plan/models.py

class Meta:
unique_together = (("name", "semester", "person"),)
unique_together = (("name", "semester", "person", "advanced_registration"), ("semester", "person", "advanced_registration"))
Copy link
Copy Markdown
Contributor

@AaDalal AaDalal Jan 5, 2023

Choose a reason for hiding this comment

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

Each tuple is anded together -- so both tuples have to be unique, otherwise everything fails. The first tuple ends up being redundant because it just a subset of the cases covered by the second tuple.

I would fix this by deleting the second constraint. When advanced registration is False (all of the cases prior to this PR, we have the original constraint of ("name", "semester", "person") which we want to enforce. When advanced_registration is true, we should only have 1 schedule per semester so the ("name", "semester", "person") constraint should always succeed.

Comment thread backend/plan/views.py
},
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would delete this space. Have you tried running the documentation locally to see how the auto docs look?

Comment thread backend/plan/views.py
reverse_func("advanced-registration-schedule"): {
"POST": {
200: "[DESCRIBE_RESPONSE_SCHEMA]Response returned successfully.",
201: "[UNDOCUMENTED]",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there ever a case where 201 is returned?

Comment thread backend/plan/views.py

if len(advanced_reg_sections) == 0:
return Response(
f"Empty Advanced Registration Schedule",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary formatted string (remove the leading f)

Comment thread backend/plan/views.py
try:
advanced_reg_sections = []
for advanced_reg_code in advanced_reg_codes:
advanced_reg_sections.append(Section.objects.filter(code=advanced_reg_code))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can simplify this for loop into Section.objects.filter(code__in=advanced_reg_codes)

Copy link
Copy Markdown
Contributor

@AaDalal AaDalal Jan 5, 2023

Choose a reason for hiding this comment

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

One other important note: we only want the Section objects from the semester in question, right? So I think it should be Section.objects.filter(code__in=advanced_reg_codes, semester=semester)

Comment thread backend/plan/views.py

if len(advanced_reg_sections) == 0:
return Response(
f"Empty Advanced Registration Schedule",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe an error code would be No valid sections provided (or something along those lines)

Comment thread backend/plan/views.py
semester=semester, name=advanced_reg_schedule_name, advanced_registration=True)
advanced_reg_schedule.save()

except ValueError as e:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What causes this ValueError? It's generally better practice to avoid try-except clauses and instead ensure your inputs are correct before using them.

Comment thread backend/plan/views.py
str(e),
status=status.HTTP_400_BAD_REQUEST,
)
return Response({"message": "success", "advanced_reg_schedule": advanced_reg_schedule}, status=status.HTTP_200_OK)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this response look correct? I'm actually unsure whether returning a django model instance automatically serializes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants