From 0aa0f7d4e2cdea9868091b1177464957d8bc867f Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Thu, 27 Aug 2020 16:35:38 +0000 Subject: [PATCH] Make the IPR search form initialize the state field upon form initialization instead of evaluating the queryset upon importing the module. This is probably never a problem in practice in this case in the live environment, but it's a confusing practice, and when running the tests sometimes a bug seems to throw Django off and the error is then shadowed by Django crashing when trying to access the (non-existing) database. - Legacy-Id: 18425 --- ietf/ipr/forms.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ietf/ipr/forms.py b/ietf/ipr/forms.py index 6898137e3..6a83cb191 100644 --- a/ietf/ipr/forms.py +++ b/ietf/ipr/forms.py @@ -24,12 +24,6 @@ from ietf.message.models import Message from ietf.utils.fields import DatepickerDateField from ietf.utils.text import dict_to_text -# ---------------------------------------------------------------- -# Globals -# ---------------------------------------------------------------- -STATE_CHOICES = [ (x.slug, x.name) for x in IprDisclosureStateName.objects.all() ] -STATE_CHOICES.insert(0,('all','All States')) - # ---------------------------------------------------------------- # Base Classes # ---------------------------------------------------------------- @@ -418,7 +412,7 @@ class ThirdPartyIprDisclosureForm(IprDisclosureFormBase): return obj class SearchForm(forms.Form): - state = forms.MultipleChoiceField(choices=STATE_CHOICES,widget=forms.CheckboxSelectMultiple,required=False) + state = forms.MultipleChoiceField(choices=[], widget=forms.CheckboxSelectMultiple,required=False) draft = forms.CharField(label="Draft name", max_length=128, required=False) rfc = forms.IntegerField(label="RFC number", required=False) holder = forms.CharField(label="Name of patent owner/applicant", max_length=128,required=False) @@ -427,6 +421,10 @@ class SearchForm(forms.Form): doctitle = forms.CharField(label="Words in document title", max_length=128,required=False) iprtitle = forms.CharField(label="Words in IPR disclosure title", max_length=128,required=False) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['state'].choices = [('all','All States')] + [(n.pk, n.name) for n in IprDisclosureStateName.objects.all()] + class StateForm(forms.Form): state = forms.ModelChoiceField(queryset=IprDisclosureStateName.objects,label="New State",empty_label=None) comment = forms.CharField(required=False, widget=forms.Textarea, help_text="You may add a comment to be included in the disclosure history.", strip=False)