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

Fix for #1778. #1780

Merged
merged 1 commit into from
Dec 20, 2017
Merged

Fix for #1778. #1780

merged 1 commit into from
Dec 20, 2017

Conversation

explody
Copy link
Contributor

@explody explody commented Dec 16, 2017

This will set initial values for visible bulk-add form fields from query args.

Fixes:

#1778

This is a simple fix to allow bulk-addition of addresses to receive initial values set in the single-address-addition form, which are already passed as query args in the URL.

The approach I took is just to loop through the form's visible Meta fields, and build a dict of initial form field values from query args that match field names. (initial vals described here):

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#providing-initial-values

Query args that don't match field names are ignored since we loop on meta fields, not the query args, and Django quietly ignores invalid initial values.

There are alternate approaches to comparing the fields but they seemed like micro optimizations and slightly less easy to read:

        fields = getattr(self.model_form._meta, 'fields', [])
        for field in set(fields).intersection(request.GET.keys()):
            if request.GET[field]:
                initial[field] = request.GET[field]

This will set initial values for visible bulk-add form fields from query args.
@jeremystretch jeremystretch merged commit 4d1e798 into netbox-community:develop Dec 20, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants