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

Refactor forms #1005

Merged
merged 4 commits into from
Mar 13, 2019
Merged

Refactor forms #1005

merged 4 commits into from
Mar 13, 2019

Conversation

lfdebrux
Copy link
Contributor

@lfdebrux lfdebrux commented Mar 11, 2019

Here's some refactoring I did of some of the forms in the supplier frontend.

The changes are part of what I was doing https://github.com/alphagov/digitalmarketplace-supplier-frontend/tree/ldeb-107-wtforms-dmfields-supplier-forms, but packaged nicer.

I want these changes to be in the supplier frontend now because I intend to reuse (some of) the code for the admin frontend, and it would be helpful to be able to point to the supplier frontend code in master as an exemplar.

- Refactor what-buyers-will-see view
- Refactor EditSupplierForm and EditContactInformationForm classes
- Refactor EditSupplierForm and EditContactInformation form template
- Combine EditSupplierForm and EditContactInformationForm
- Refactor EditRegisteredAddressForm and EditRegisteredCountryForm
- Refactor registered_address template
- Refactor CompanyOrganisationSizeForm
- Refactor edit_supplier_organisation_size template
- Add TODO to edit_supplier_organisation_size view
- Refactor CompanyTradingStatusForm
- Refactor edit_supplier_trading_status template
- Refactor edit_supplier_trading_status view
registered_address_form.address1.data = supplier['contact'].get('address1')
registered_address_form.city.data = supplier['contact'].get('city')
registered_address_form.postcode.data = supplier['contact'].get('postcode')
data_api_client.update_contact_information(
Copy link
Contributor

Choose a reason for hiding this comment

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

Sigh, we really don't have a way of updating both Supplier and ContactInformation together transactionally do we? I guess that's one reason we have so much FE validation for this data...

form = CompanyTradingStatusForm()

prefill_data = {}
if request.method == "GET":
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this view only conditionally load the existing supplier data and the others load it for both GET and POST?

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 was worried about making the GET more expensive; the other views GET was already including the api requests.

I'm happy to take it out though, it is a bit premature optimisation-y

Copy link
Contributor

@risicle risicle Mar 11, 2019

Choose a reason for hiding this comment

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

I was actually looking at it the other way around - why don't we do it in all the others too? One advantage I can think of is a small amount of added clarity - it's more clear the prefill_data can't have any effect in the POST case if it never gets filled out in the first place.

Unless, I reasoned, the use of supplier-fetching here is being used as a guard to generate 404s if the supplier doesn't exist - but... that's ... not possible here? Guessing most of this app's views use a login_required decorator that requires role == "supplier"? (edit: just checked, yes it does)

Copy link
Contributor

@katstevens katstevens left a comment

Choose a reason for hiding this comment

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

Works for me locally - happy to give this a go.

Copy link
Contributor

@risicle risicle left a comment

Choose a reason for hiding this comment

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

Yeah this works for me too.

@lfdebrux lfdebrux merged commit df10f66 into master Mar 13, 2019
@lfdebrux lfdebrux deleted the ldeb-refactor-forms branch March 13, 2019 08:52
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