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

[DNM] Edit multiple measures #724

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
File renamed without changes.
61 changes: 61 additions & 0 deletions measures/conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from measures import constants


def show_step_end_dates(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.END_DATES in cleaned_data.get("fields_to_edit")


def show_step_regulation_id(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.REGULATION_ID in cleaned_data.get("fields_to_edit")


def show_step_quota_order_number(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.QUOTA_ORDER_NUMBER in cleaned_data.get("fields_to_edit")


def show_step_geographical_area(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.GEOGRAPHICAL_AREA in cleaned_data.get("fields_to_edit")


def show_step_duties(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.DUTIES in cleaned_data.get("fields_to_edit")


def show_step_additional_code(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.ADDITIONAL_CODE in cleaned_data.get("fields_to_edit")


def show_step_conditions(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.CONDITIONS in cleaned_data.get("fields_to_edit")


def show_step_footnotes(wizard):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these be refactored into one generic method?

Copy link
Contributor

Choose a reason for hiding this comment

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

After refactoring it might be worth considering whether these belong in their own file or whether they should sit on/above a class somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree it'd be nice to be able to parametrise these with the different step names but due to how formtools is expecting them to be passed to the view (as a dictionary in urls.py) I don't think this is an easy fix. Maybe a future tech debt ticket?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah that's a bit awkward. I feel like there's a way to do it with lambdas, but might be worth creating ticket, as you say

cleaned_data = wizard.get_cleaned_data_for_step(constants.START)
if cleaned_data:
return constants.FOOTNOTES in cleaned_data.get("fields_to_edit")


measure_edit_condition_dict = {
constants.END_DATES: show_step_end_dates,
constants.REGULATION_ID: show_step_regulation_id,
constants.QUOTA_ORDER_NUMBER: show_step_quota_order_number,
constants.GEOGRAPHICAL_AREA: show_step_geographical_area,
constants.DUTIES: show_step_duties,
constants.ADDITIONAL_CODE: show_step_additional_code,
constants.CONDITIONS: show_step_conditions,
constants.FOOTNOTES: show_step_footnotes,
}
14 changes: 14 additions & 0 deletions measures/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
START = "start"
END_DATES = "end_dates"
VALIDITY_DATES = "validity_dates"
MEASURE_DETAILS = "measure_details"
REGULATION_ID = "regulation_id"
QUOTA_ORDER_NUMBER = "quota_order_number"
GEOGRAPHICAL_AREA = "geographical_area"
COMMODITIES = "commodities"
DUTIES = "duties"
ADDITIONAL_CODE = "additional_code"
CONDITIONS = "conditions"
FOOTNOTES = "footnotes"
SUMMARY = "summary"
COMPLETE = "complete"
Loading