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

Reducing the size of the quotas/forms.py and views.py #1315

Merged
merged 9 commits into from
Oct 31, 2024

Conversation

CPrich905
Copy link
Collaborator

@CPrich905 CPrich905 commented Oct 28, 2024

Refactor of quotas/views.py and forms.py

Why

Both the views.py and forms.py files are getting large (>1,000 lines long)
These are only going to grow further as we add functionality. Reducing the size of the files makes them easier to comprehend.

What

  • creates a forms and views folder.
  • renames the forms.py and views.py files to be base.py and puts them in the respective folders.
  • separates out the wizards forms and views into respective wizards.py files
  • separates out the forms and views based on the Definitions model to a definitions.py file
  • separates out the mixins to views/mixins.py
  • separates out the React forms to react_forms.py
    Note that the BulkQuotaDefinitionCreate wizard is a work in progress.

server.py Fixed Show fixed Hide fixed
@CPrich905 CPrich905 changed the title formatting Reducing the size of the quotas/forms.py and views.py Oct 28, 2024
@CPrich905 CPrich905 marked this pull request as ready for review October 30, 2024 12:35
@CPrich905 CPrich905 requested a review from a team as a code owner October 30, 2024 12:35
return initial


class QuotaSuspensionType(TextChoices):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also split this out into a forms/constants.py

from quotas import validators
from quotas.constants import QUOTA_ORIGIN_EXCLUSIONS_FORMSET_PREFIX

CATEGORY_HELP_TEXT = "Categories are required for the TAP database but will not appear as a TARIC3 object in your workbasket"
Copy link
Contributor

Choose a reason for hiding this comment

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

These could also go in a constants file but for now it's probably fine for them to live in here

from geo_areas.models import GeographicalArea
from quotas import models
from quotas import validators
from quotas.constants import QUOTA_EXCLUSIONS_FORMSET_PREFIX
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the only values we have in this constants file are used in forms only so I think it makes sense to move this to quotas/forms/constants.py and add some of the other ones that appear in here. Some might need renaming to avoid clashes

@@ -0,0 +1,309 @@
from crispy_forms_gds.helper import FormHelper

# from crispy_forms_gds.layout import Button
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented code

@CPrich905 CPrich905 requested a review from eadpearce October 31, 2024 11:12
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 93.21129% with 89 lines in your changes missing coverage. Please review.

Project coverage is 93.16%. Comparing base (c5eaaa0) to head (821238e).

Files with missing lines Patch % Lines
quotas/views/wizards.py 69.82% 33 Missing and 2 partials ⚠️
quotas/forms/definitions.py 86.03% 20 Missing and 5 partials ⚠️
quotas/forms/wizards.py 80.61% 17 Missing and 2 partials ⚠️
quotas/views/mixins.py 94.28% 3 Missing and 3 partials ⚠️
quotas/forms/react_forms.py 98.59% 1 Missing and 1 partial ⚠️
quotas/views/base.py 99.60% 0 Missing and 1 partial ⚠️
quotas/views/definitions.py 99.56% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1315      +/-   ##
==========================================
- Coverage   93.18%   93.16%   -0.02%     
==========================================
  Files         643      651       +8     
  Lines       49409    49556     +147     
  Branches     5305     5308       +3     
==========================================
+ Hits        46041    46171     +130     
- Misses       2711     2728      +17     
  Partials      657      657              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@CPrich905 CPrich905 merged commit 0c85431 into master Oct 31, 2024
8 checks passed
@CPrich905 CPrich905 deleted the splitting-quota-views-forms-files branch October 31, 2024 12:30
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.

3 participants