Added Webapp type help text
This commit is contained in:
parent
f4ca49b912
commit
aa34f09fdd
|
@ -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(
|
||||
"<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)
|
||||
|
||||
|
@ -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():
|
||||
|
@ -69,5 +75,21 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
|||
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(
|
||||
"<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)
|
||||
|
|
|
@ -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/<app_name>-<site_name>")
|
||||
'help_text': _("This creates a Webalizer application under "
|
||||
"~/webapps/<app_name>-<site_name>")
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -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(
|
||||
"<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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue