From aa34f09fdd9e2d91225311ef68301fab19201c0e Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Mon, 10 Nov 2014 15:15:37 +0000 Subject: [PATCH] Added Webapp type help text --- orchestra/apps/webapps/admin.py | 30 ++++++++++++++++++++++++++---- orchestra/apps/webapps/settings.py | 3 ++- orchestra/apps/websites/admin.py | 9 ++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/orchestra/apps/webapps/admin.py b/orchestra/apps/webapps/admin.py index 7e624fcf..a847cdaf 100644 --- a/orchestra/apps/webapps/admin.py +++ b/orchestra/apps/webapps/admin.py @@ -15,10 +15,10 @@ class WebAppOptionInline(admin.TabularInline): model = WebAppOption extra = 1 - OPTIONS_HELP_TEXT = str({ + OPTIONS_HELP_TEXT = { k: str(unicode(v[1])) if len(v) == 3 else '' for k, v in settings.WEBAPPS_OPTIONS.iteritems() - }) + } class Media: css = { @@ -30,6 +30,7 @@ class WebAppOptionInline(admin.TabularInline): if db_field.name == 'value': kwargs['widget'] = forms.TextInput(attrs={'size':'100'}) if db_field.name == 'name': + # Help text based on select widget kwargs['widget'] = forms.Select(attrs={ 'onChange': """ siteoptions = %s; @@ -38,7 +39,7 @@ class WebAppOptionInline(admin.TabularInline): valueelement.parent().append( "

" + siteoptions[this.options[this.selectedIndex].value] + "

" ); - """ % self.OPTIONS_HELP_TEXT, + """ % str(self.OPTIONS_HELP_TEXT), }) return super(WebAppOptionInline, self).formfield_for_dbfield(db_field, **kwargs) @@ -53,6 +54,11 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin): change_readonly_fields = ('name', 'type') prefetch_related = ('content_set__website',) + TYPE_HELP_TEXT = { + k: str(unicode(v.get('help_text', ''))) + for k, v in settings.WEBAPPS_TYPES.iteritems() + } + def display_websites(self, webapp): websites = [] for content in webapp.content_set.all(): @@ -68,6 +74,22 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin): return '
'.join(websites) display_websites.short_description = _("web sites") display_websites.allow_tags = True - + + def formfield_for_dbfield(self, db_field, **kwargs): + """ Make value input widget bigger """ + if db_field.name == 'type': + # Help text based on select widget + kwargs['widget'] = forms.Select(attrs={ + 'onChange': """ + siteoptions = %s; + valueelement = $("#"+this.id); + valueelement.parent().find('p').remove(); + valueelement.parent().append( + "

" + siteoptions[this.options[this.selectedIndex].value] + "

" + ); + """ % str(self.TYPE_HELP_TEXT), + }) + kwargs['help_text'] = self.TYPE_HELP_TEXT.get(db_field.default, '') + return super(WebAppAdmin, self).formfield_for_dbfield(db_field, **kwargs) admin.site.register(WebApp, WebAppAdmin) diff --git a/orchestra/apps/webapps/settings.py b/orchestra/apps/webapps/settings.py index fad8cbc4..d4300353 100644 --- a/orchestra/apps/webapps/settings.py +++ b/orchestra/apps/webapps/settings.py @@ -56,7 +56,8 @@ WEBAPPS_TYPES = getattr(settings, 'WEBAPPS_TYPES', { 'webalizer': { 'verbose_name': "Webalizer", 'directive': ('static', '%(app_path)s%(site_name)s'), - 'help_text': _("This creates a Webalizer application under ~/webapps/-") + 'help_text': _("This creates a Webalizer application under " + "~/webapps/<app_name>-<site_name>") }, }) diff --git a/orchestra/apps/websites/admin.py b/orchestra/apps/websites/admin.py index 36b8ad54..93fd52df 100644 --- a/orchestra/apps/websites/admin.py +++ b/orchestra/apps/websites/admin.py @@ -14,10 +14,10 @@ class WebsiteOptionInline(admin.TabularInline): model = WebsiteOption extra = 1 - OPTIONS_HELP_TEXT = str({ + OPTIONS_HELP_TEXT = { k: str(unicode(v[1])) if len(v) == 3 else '' for k, v in settings.WEBSITES_OPTIONS.iteritems() - }) + } # class Media: # css = { @@ -29,8 +29,7 @@ class WebsiteOptionInline(admin.TabularInline): if db_field.name == 'value': kwargs['widget'] = forms.TextInput(attrs={'size':'100'}) if db_field.name == 'name': - options = { - } + # Help text based on select widget kwargs['widget'] = forms.Select(attrs={ 'onChange': """ siteoptions = %s; @@ -39,7 +38,7 @@ class WebsiteOptionInline(admin.TabularInline): valueelement.parent().append( "

" + siteoptions[this.options[this.selectedIndex].value] + "

" ); - """ % self.OPTIONS_HELP_TEXT, + """ % str(self.OPTIONS_HELP_TEXT), }) return super(WebsiteOptionInline, self).formfield_for_dbfield(db_field, **kwargs)