Added Webapp type help text

This commit is contained in:
Marc Aymerich 2014-11-10 15:15:37 +00:00
parent f4ca49b912
commit aa34f09fdd
3 changed files with 32 additions and 10 deletions

View file

@ -15,10 +15,10 @@ class WebAppOptionInline(admin.TabularInline):
model = WebAppOption model = WebAppOption
extra = 1 extra = 1
OPTIONS_HELP_TEXT = str({ OPTIONS_HELP_TEXT = {
k: str(unicode(v[1])) if len(v) == 3 else '' k: str(unicode(v[1])) if len(v) == 3 else ''
for k, v in settings.WEBAPPS_OPTIONS.iteritems() for k, v in settings.WEBAPPS_OPTIONS.iteritems()
}) }
class Media: class Media:
css = { css = {
@ -30,6 +30,7 @@ class WebAppOptionInline(admin.TabularInline):
if db_field.name == 'value': if db_field.name == 'value':
kwargs['widget'] = forms.TextInput(attrs={'size':'100'}) kwargs['widget'] = forms.TextInput(attrs={'size':'100'})
if db_field.name == 'name': if db_field.name == 'name':
# Help text based on select widget
kwargs['widget'] = forms.Select(attrs={ kwargs['widget'] = forms.Select(attrs={
'onChange': """ 'onChange': """
siteoptions = %s; siteoptions = %s;
@ -38,7 +39,7 @@ class WebAppOptionInline(admin.TabularInline):
valueelement.parent().append( valueelement.parent().append(
"<p class='help'>" + siteoptions[this.options[this.selectedIndex].value] + "</p>" "<p class='help'>" + siteoptions[this.options[this.selectedIndex].value] + "</p>"
); );
""" % self.OPTIONS_HELP_TEXT, """ % str(self.OPTIONS_HELP_TEXT),
}) })
return super(WebAppOptionInline, self).formfield_for_dbfield(db_field, **kwargs) return super(WebAppOptionInline, self).formfield_for_dbfield(db_field, **kwargs)
@ -53,6 +54,11 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
change_readonly_fields = ('name', 'type') change_readonly_fields = ('name', 'type')
prefetch_related = ('content_set__website',) 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): def display_websites(self, webapp):
websites = [] websites = []
for content in webapp.content_set.all(): for content in webapp.content_set.all():
@ -69,5 +75,21 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
display_websites.short_description = _("web sites") display_websites.short_description = _("web sites")
display_websites.allow_tags = True 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(
"<p class='help'>" + siteoptions[this.options[this.selectedIndex].value] + "</p>"
);
""" % 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) admin.site.register(WebApp, WebAppAdmin)

View file

@ -56,7 +56,8 @@ WEBAPPS_TYPES = getattr(settings, 'WEBAPPS_TYPES', {
'webalizer': { 'webalizer': {
'verbose_name': "Webalizer", 'verbose_name': "Webalizer",
'directive': ('static', '%(app_path)s%(site_name)s'), 'directive': ('static', '%(app_path)s%(site_name)s'),
'help_text': _("This creates a Webalizer application under ~/webapps/<app_name>-<site_name>") 'help_text': _("This creates a Webalizer application under "
"~/webapps/&lt;app_name&gt;-&lt;site_name&gt;")
}, },
}) })

View file

@ -14,10 +14,10 @@ class WebsiteOptionInline(admin.TabularInline):
model = WebsiteOption model = WebsiteOption
extra = 1 extra = 1
OPTIONS_HELP_TEXT = str({ OPTIONS_HELP_TEXT = {
k: str(unicode(v[1])) if len(v) == 3 else '' k: str(unicode(v[1])) if len(v) == 3 else ''
for k, v in settings.WEBSITES_OPTIONS.iteritems() for k, v in settings.WEBSITES_OPTIONS.iteritems()
}) }
# class Media: # class Media:
# css = { # css = {
@ -29,8 +29,7 @@ class WebsiteOptionInline(admin.TabularInline):
if db_field.name == 'value': if db_field.name == 'value':
kwargs['widget'] = forms.TextInput(attrs={'size':'100'}) kwargs['widget'] = forms.TextInput(attrs={'size':'100'})
if db_field.name == 'name': if db_field.name == 'name':
options = { # Help text based on select widget
}
kwargs['widget'] = forms.Select(attrs={ kwargs['widget'] = forms.Select(attrs={
'onChange': """ 'onChange': """
siteoptions = %s; siteoptions = %s;
@ -39,7 +38,7 @@ class WebsiteOptionInline(admin.TabularInline):
valueelement.parent().append( valueelement.parent().append(
"<p class='help'>" + siteoptions[this.options[this.selectedIndex].value] + "</p>" "<p class='help'>" + siteoptions[this.options[this.selectedIndex].value] + "</p>"
); );
""" % self.OPTIONS_HELP_TEXT, """ % str(self.OPTIONS_HELP_TEXT),
}) })
return super(WebsiteOptionInline, self).formfield_for_dbfield(db_field, **kwargs) return super(WebsiteOptionInline, self).formfield_for_dbfield(db_field, **kwargs)