From 415ddc2315e495f7d198c6e25f2521c1ae2ebe83 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Sat, 7 May 2016 20:09:05 +0000 Subject: [PATCH] Fixed bugs on miscellaneous admin UI --- orchestra/contrib/miscellaneous/admin.py | 9 +++++---- orchestra/plugins/options.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/orchestra/contrib/miscellaneous/admin.py b/orchestra/contrib/miscellaneous/admin.py index d240dd42..1c5efd63 100644 --- a/orchestra/contrib/miscellaneous/admin.py +++ b/orchestra/contrib/miscellaneous/admin.py @@ -86,9 +86,9 @@ class MiscellaneousAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedMode else: return obj.service - def get_fields(self, request, obj=None): - fields = super().get_fields(request, obj) - fields = list(fields) + def get_fieldsets(self, request, obj=None): + fieldsets = super().get_fieldsets(request, obj) + fields = list(fieldsets[0][1]['fields']) service = self.get_service(obj) if obj: fields.insert(1, 'account_link') @@ -96,7 +96,8 @@ class MiscellaneousAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedMode fields.insert(-1, 'amount') if service.has_identifier: fields.insert(2, 'identifier') - return fields + fieldsets[0][1]['fields'] = fields + return fieldsets def get_form(self, request, obj=None, **kwargs): if obj: diff --git a/orchestra/plugins/options.py b/orchestra/plugins/options.py index 2dc4db1a..477f4dc1 100644 --- a/orchestra/plugins/options.py +++ b/orchestra/plugins/options.py @@ -14,9 +14,11 @@ class Plugin(object): def __init__(self, instance=None): # Related model instance of this plugin - self.instance = instance - from .forms import PluginForm - self.form = PluginForm + if self.form is None: + self.instance = instance + from .forms import PluginForm + self.form = PluginForm + super().__init__() @classmethod def get_name(cls): @@ -93,11 +95,13 @@ class PluginModelAdapter(Plugin): """ Adapter class for using model classes as plugins """ model = None name_field = None + form = None def __init__(self, instance=None): + if self.form is None: + from .forms import PluginModelAdapterForm + self.form = PluginModelAdapterForm super().__init__(instance) - from .forms import PluginModelAdapterForm - self.form = PluginModelAdapterForm @classmethod def get_plugins(cls):