Skip to content

Commit

Permalink
Pretify the admin interface with helper texts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amalia Gherasim committed Apr 12, 2012
1 parent 683a671 commit a0cb375
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
15 changes: 10 additions & 5 deletions smartsnippets/admin.py
Expand Up @@ -57,7 +57,9 @@ def get_queryset(self):
class SnippetVariablesAdmin(admin.StackedInline): class SnippetVariablesAdmin(admin.StackedInline):
model = SmartSnippetVariable model = SmartSnippetVariable
extra = 0 extra = 0

verbose_name = 'Smart Snippet Simple Variable'
verbose_name_plural = 'Smart Snippet Simple Variables'
SmartSnippetVariable.__unicode__ = lambda x: ''
def formfield_for_dbfield(self, db_field, **kwargs): def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'widget': if db_field.name == 'widget':
kwargs['widget'] = Select(choices=tuple([(x.__name__, x.name) for x in widget_pool.get_all_widgets()])) kwargs['widget'] = Select(choices=tuple([(x.__name__, x.name) for x in widget_pool.get_all_widgets()]))
Expand All @@ -66,7 +68,8 @@ def formfield_for_dbfield(self, db_field, **kwargs):


class RegularSnippetVariablesAdmin(SnippetVariablesAdmin): class RegularSnippetVariablesAdmin(SnippetVariablesAdmin):
formset = SnippetVariablesFormSet formset = SnippetVariablesFormSet



class SnippetAdmin(admin.ModelAdmin): class SnippetAdmin(admin.ModelAdmin):
inlines = [RegularSnippetVariablesAdmin,] inlines = [RegularSnippetVariablesAdmin,]
shared_sites = shared_sites shared_sites = shared_sites
Expand Down Expand Up @@ -128,12 +131,14 @@ def queryset(self, request):
class DropDownVariableAdmin(SnippetVariablesAdmin): class DropDownVariableAdmin(SnippetVariablesAdmin):
model = DropDownVariable model = DropDownVariable
exclude = ('widget',) exclude = ('widget',)

verbose_name = 'Smart Snippet Dropdown Variable'

verbose_name_plural = 'Smart Snippet Dropdown Variables'
DropDownVariable.__unicode__ = lambda x: ''


class ExtendedSnippetAdmin(SnippetAdmin): class ExtendedSnippetAdmin(SnippetAdmin):
inlines = [RegularSnippetVariablesAdmin, DropDownVariableAdmin] inlines = [RegularSnippetVariablesAdmin, DropDownVariableAdmin]



admin.site.register(SmartSnippet, SnippetAdmin) admin.site.register(SmartSnippet, SnippetAdmin)
admin.site.unregister(SmartSnippet) admin.site.unregister(SmartSnippet)
admin.site.register(SmartSnippet, ExtendedSnippetAdmin) admin.site.register(SmartSnippet, ExtendedSnippetAdmin)
17 changes: 9 additions & 8 deletions smartsnippets/models.py
Expand Up @@ -42,15 +42,15 @@ def __unicode__(self):




class SmartSnippetVariable(models.Model): class SmartSnippetVariable(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50,
widget = models.CharField(max_length=50) help_text=_('Enter the name of the variable defined in the smart snippet template.'))
widget = models.CharField(max_length=50,
help_text=_('Select the type of the variable defined in the smart snippet template.'))
snippet = models.ForeignKey(SmartSnippet, related_name="variables") snippet = models.ForeignKey(SmartSnippet, related_name="variables")


class Meta: class Meta:
unique_together = (('snippet', 'name')) unique_together = (('snippet', 'name'))
ordering = ['name'] ordering = ['name']
verbose_name = 'Smart Snippet Variable'
verbose_name_plural = 'Smart Snippet Variables'


def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(SmartSnippetVariable, self).save(*args, **kwargs) super(SmartSnippetVariable, self).save(*args, **kwargs)
Expand Down Expand Up @@ -91,12 +91,13 @@ def widget(self):




class DropDownVariable(SmartSnippetVariable): class DropDownVariable(SmartSnippetVariable):
choices = models.CharField(max_length=512) choices = models.CharField(max_length=512,

help_text=_('Enter a comma separated list of choices that will be available in the dropdown variable when adding and configuring the smart snippet on a page.'))

@property @property
def choices_list(self): def choices_list(self):
return [choice.strip() for choice in self.choices.split(',')] return [choice.strip() for choice in self.choices.split(',')]


def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.widget = 'DropDownField' self.widget = 'DropDownField'
super(DropDownVariable, self).save(*args, **kwargs) super(DropDownVariable, self).save(*args, **kwargs)

0 comments on commit a0cb375

Please sign in to comment.