From 7990ee11b4649911cf8f2ca4c7ac7ab19248d73f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 15 Jul 2014 15:20:22 +0200 Subject: [PATCH] models,admin: do not put choice for attribut name in models only admin --- authentic2_idp_oauth2/admin.py | 7 +++++++ authentic2_idp_oauth2/models.py | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/authentic2_idp_oauth2/admin.py b/authentic2_idp_oauth2/admin.py index 4b66a3f..dfc1b9a 100644 --- a/authentic2_idp_oauth2/admin.py +++ b/authentic2_idp_oauth2/admin.py @@ -1,6 +1,8 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib import admin +from authentic2.decorators import to_iter +from authentic2.attributes_ng.engine import get_attribute_names from provider.oauth2.admin import ClientAdmin from . import models @@ -11,6 +13,11 @@ class WebServiceAdmin(admin.ModelAdmin): class AttributeReleaseInline(admin.TabularInline): model = models.AttributeRelease + def formfield_for_choice_field(self, db_field, request, **kwargs): + if db_field.name == 'attribute_name': + kwargs['choices'] = to_iter(get_attribute_names)({'user': None, 'request': None}) + return super(AttributeReleaseInline, self).formfield_for_choice_field(db_field, request, **kwargs) + class A2ClientAdmin(ClientAdmin): inlines = [AttributeReleaseInline] fieldsets = ( diff --git a/authentic2_idp_oauth2/models.py b/authentic2_idp_oauth2/models.py index 5bd2ff7..0f52c65 100644 --- a/authentic2_idp_oauth2/models.py +++ b/authentic2_idp_oauth2/models.py @@ -7,8 +7,6 @@ from provider.oauth2.models import Client from authentic2.models import LogoutUrlAbstract from authentic2.managers import GetBySlugManager -from authentic2.decorators import to_iter -from authentic2.attributes_ng.engine import get_attribute_names class A2Client(LogoutUrlAbstract, Client): class Meta: @@ -21,7 +19,7 @@ class AttributeRelease(models.Model): name = models.CharField(verbose_name=_('name'), max_length=64) attribute_name = models.CharField(max_length=64, verbose_name=_('attribute name'), - choices=to_iter(get_attribute_names)({'user': None, 'request': None})) + choices=(('', 'None'),)) class Meta: verbose_name = _('OAuth2 attribute release')