django-dbtemplates/dbtemplates/admin.py
leidel 391b00c655 Added support for django-reversion to versionize Template instances. Enabled only if django-reversion is installed.
Makes the template textarea appear larger and use monospace fonts.
Enables filtering by sites in the changelist view.

git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@57 cfb8ba98-e953-0410-9cff-959ffddf5974

committer: leidel <leidel@cfb8ba98-e953-0410-9cff-959ffddf5974>

--HG--
extra : convert_revision : b1e31a43061323c6935659312f86f32084a54b9e
2008-11-02 00:05:26 +00:00

46 lines
1.5 KiB
Python

from django import forms
from django.contrib import admin
from django.db.models import get_app
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ImproperlyConfigured
from dbtemplates.models import Template
# Check if django-reversion is installed and use reversions' VersionAdmin
# as the base admin class if yes
try:
get_app('reversion')
from reversion.admin import VersionAdmin as TemplateModelAdmin
except ImproperlyConfigured:
from django.contrib.admin import ModelAdmin as TemplateModelAdmin
class TemplateAdminForm(forms.ModelForm):
"""
Custom AdminForm to make the content textarea wider.
"""
content = forms.CharField(
widget=forms.Textarea({'cols': '80', 'rows': '24'}),
help_text=_("Leaving this empty causes Django to look for a template "
"with the given name and populate this field with its content."),
required=False)
class Meta:
model = Template
class TemplateAdmin(TemplateModelAdmin):
form = TemplateAdminForm
fieldsets = (
(None, {
'fields': ('name', 'content', 'sites'),
'classes': ('monospace',),
}),
(_('Date information'), {
'fields': (('creation_date', 'last_changed'),),
'classes': ('collapse',),
}),
)
list_display = ('name', 'creation_date', 'last_changed')
list_filter = ('sites',)
search_fields = ('name', 'content')
admin.site.register(Template, TemplateAdmin)