diff options
author | gnowgi <nagarjun@gnowledge.org> | 2012-03-15 16:19:20 +0530 |
---|---|---|
committer | gnowgi <nagarjun@gnowledge.org> | 2012-03-15 16:19:20 +0530 |
commit | 7a4f561e851fdc7246d804c3abb6748b8a4199a6 (patch) | |
tree | d2afc3463fd49625a9be482012f5c3bfcf7c42b9 /gstudio/admin/metatype.py | |
download | gnowsys-7a4f561e851fdc7246d804c3abb6748b8a4199a6.tar.gz |
master trunk of gnowsys-studio
Diffstat (limited to 'gstudio/admin/metatype.py')
-rw-r--r-- | gstudio/admin/metatype.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gstudio/admin/metatype.py b/gstudio/admin/metatype.py new file mode 100644 index 0000000..bb24fc7 --- /dev/null +++ b/gstudio/admin/metatype.py @@ -0,0 +1,30 @@ +"""MetatypeAdmin for Gstudio""" +from django.contrib import admin +from django.core.urlresolvers import NoReverseMatch +from django.utils.translation import ugettext_lazy as _ + +from gstudio.admin.forms import MetatypeAdminForm +import reversion + +class MetatypeAdmin(reversion.VersionAdmin): + """Admin for Metatype model""" + form = MetatypeAdminForm + fields = ('title','altnames', 'parent', 'description', 'slug') + list_display = ('title', 'slug', 'get_tree_path', 'description') + prepopulated_fields = {'slug': ('title', )} + search_fields = ('title', 'description') + list_filter = ('parent',) + + def __init__(self, model, admin_site): + self.form.admin_site = admin_site + super(MetatypeAdmin, self).__init__(model, admin_site) + + def get_tree_path(self, metatype): + """Return the metatype's tree path in HTML""" + try: + return '<a href="%s" target="blank">/%s/</a>' % \ + (metatype.get_absolute_url(), metatype.tree_path) + except NoReverseMatch: + return '/%s/' % metatype.tree_path + get_tree_path.allow_tags = True + get_tree_path.short_description = _('tree path') |