From ffeda432344ccffbc08bc9f913fb82ec92d7df7b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 12 Mar 2015 18:38:34 +0100 Subject: [PATCH] Do not request the db at loading time Modify choices in the constructor of the AttributeReleaselineForm class. --- authentic2_idp_oauth2/admin.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/authentic2_idp_oauth2/admin.py b/authentic2_idp_oauth2/admin.py index 883e3e3..179c1d1 100644 --- a/authentic2_idp_oauth2/admin.py +++ b/authentic2_idp_oauth2/admin.py @@ -12,14 +12,18 @@ class WebServiceAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('name',)} class AttributeReleaselineForm(forms.ModelForm): - class Meta: - def choices(ctx): - return [('', _('None'))] + get_attribute_names(ctx) + def __init__(self, *args, **kwargs): + super(AttributeReleaselineForm, self).__init__(*args, **kwargs) + choices = self.choices({'user': None, 'request': None}) + self.fields['attribute_name'].choices = choices + self.fields['attribute_name'].widget = forms.Select(choices=choices) + @to_iter + def choices(self, ctx): + return [('', _('None'))] + get_attribute_names(ctx) + + class Meta: model = models.AttributeRelease - widgets = { - 'attribute_name': forms.Select(choices=to_iter(choices)({'user': None, 'request': None})) - } class AttributeReleaseInline(admin.TabularInline): model = models.AttributeRelease