diff --git a/newsbox/admin.py b/newsbox/admin.py index 3c36e7a95931c159b592cc9094a870b20f9e41dd..2f22edbafb0c58d0665792c234bb7819a2bd29dc 100644 --- a/newsbox/admin.py +++ b/newsbox/admin.py @@ -13,7 +13,6 @@ from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext_lazy as _, ungettext_lazy from django.utils import six, formats - def get_fieldset_by_field(name, fieldsets): """ Return fieldset containing a field given by name @@ -104,32 +103,10 @@ def add_fields_to_fieldset( fieldsets.append(fieldset) -def changestatus_link(obj): - if obj.newsbox_published: - title = _('Unpublish this %s') % six.text_type( - obj._meta.verbose_name) - icon_url = static('admin/img/icon-yes.gif') - else: - title = _('Publish this %s') % six.text_type( - obj._meta.verbose_name) - icon_url = static('admin/img/icon-no.gif') - return '<a href="%s" title="%s"><img src="%s" alt="%s" /></a>' % ( - reverse('admin:admin_newsbox_%s_change_status' % ( - six.text_type(obj._meta.verbose_name)), - args=[obj.pk, ]), - title, icon_url, obj.newsbox_published) - - -changestatus_link.allow_tags = True -changestatus_link.admin_order_field = 'newsbox_published' -changestatus_link.short_description = _('published') - - class NewsboxBaseAdmin(admin.ModelAdmin): list_filter = ('newsbox_publication_start_date', 'newsbox_published', ) - list_display = ['get_newsbox_title', 'newsbox_date_short', - 'get_newsbox_slug', changestatus_link] + list_display = ['get_newsbox_title', 'newsbox_date_short', 'changestatus_link'] list_display_links = ('get_newsbox_title',) fieldsets = [ (None, { @@ -144,6 +121,26 @@ class NewsboxBaseAdmin(admin.ModelAdmin): self.prepopulated_fields = {"newsbox_slug": ("newsbox_title",)} super(NewsboxBaseAdmin, self).__init__(*args, **kwargs) + def changestatus_link(self, obj): + if obj.newsbox_published: + title = _('Unpublish this %s') % six.text_type( + obj._meta.verbose_name) + icon_url = static('admin/img/icon-yes.gif') + else: + title = _('Publish this %s') % six.text_type( + obj._meta.verbose_name) + icon_url = static('admin/img/icon-no.gif') + return '<a href="%s" title="%s"><img src="%s" alt="%s" /></a>' % ( + reverse('admin:admin_newsbox_%s_change_status' % ( + six.text_type(obj._meta.verbose_name)), + args=[obj.pk, ]), + title, icon_url, obj.newsbox_published) + + + changestatus_link.allow_tags = True + changestatus_link.admin_order_field = 'newsbox_published' + changestatus_link.short_description = _('published') + def newsbox_date_short(self, obj): if not obj.newsbox_date: return None @@ -165,10 +162,6 @@ class NewsboxBaseAdmin(admin.ModelAdmin): return obj.newsbox_title get_newsbox_title.short_description = _('Title') - def get_newsbox_slug(self, obj): - return obj.newsbox_slug - get_newsbox_slug.short_description = _('Slug') - def get_urls(self): urls = super(NewsboxBaseAdmin, self).get_urls() my_urls = patterns('', url( @@ -340,10 +333,12 @@ class NewsboxExpiredAdmin(NewsboxBaseAdmin): return fieldsets def get_list_display(self, request): - list_display = super(NewsboxExpiredAdmin, self).get_list_display(request) - - list_display = list_display[:2] +\ - ['newsbox_publication_dates_short',] + list_display[2:] + list_display = copy.copy(super(NewsboxExpiredAdmin, self).get_list_display(request)) + try: + index = list_display.index('newsbox_date_short') + list_display[index] = 'newsbox_publication_dates_short' + except ValueError: + list_display.append('newsbox_publication_dates_short') return list_display class NewsboxSEOAdmin(NewsboxBaseAdmin): diff --git a/newsbox_cms/admin.py b/newsbox_cms/admin.py index 7157262c9548ce1a90ac55584bbda02403b6e200..532374c246cf6b158ca233456ea059398c3a2324 100644 --- a/newsbox_cms/admin.py +++ b/newsbox_cms/admin.py @@ -134,6 +134,6 @@ class NewsboxCMSAdmin( def get_list_display(self, request): list_display = super(NewsboxCMSAdmin, self).get_list_display(request) - list_display.remove('newsbox_date_short') - list_display.remove('get_newsbox_slug') + if 'newsbox_date_short' in list_display: + list_display.remove('newsbox_date_short') return list_display