From: Stephen Burrows Date: Mon, 10 Jan 2011 15:24:15 +0000 (-0500) Subject: Improved NewsletterArticleAdmin. Corrected embed templatetag errors related to Consta... X-Git-Tag: philo-0.9~22^2~18 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/2371c4b82b7f9ea5121e95b42e1f9dc2e25eb148?ds=sidebyside;hp=--cc Improved NewsletterArticleAdmin. Corrected embed templatetag errors related to ConstantEmbedNode.object_pk and the parse_content_type helper function (formerly get_content_type). --- 2371c4b82b7f9ea5121e95b42e1f9dc2e25eb148 diff --git a/contrib/penfield/admin.py b/contrib/penfield/admin.py index 5faf4ef..c758e67 100644 --- a/contrib/penfield/admin.py +++ b/contrib/penfield/admin.py @@ -26,6 +26,13 @@ class NewsletterAdmin(TitledAdmin): class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin): filter_horizontal = TitledAdmin.filter_horizontal + ('tags', 'authors') + list_display = ['title', 'date', 'author_names'] + search_fields = ('title', 'authors__name',) + date_hierarchy = 'date' + + def author_names(self, obj): + return ', '.join([author.get_full_name() for author in obj.authors.all()]) + author_names.short_description = "Authors" class NewsletterIssueAdmin(TitledAdmin): diff --git a/templatetags/embed.py b/templatetags/embed.py index db5cea5..eb4cd68 100644 --- a/templatetags/embed.py +++ b/templatetags/embed.py @@ -146,7 +146,6 @@ class ConstantEmbedNode(template.Node): self.template = None def compile_instance(self, object_pk): - self.object_pk = object_pk model = self.content_type.model_class() try: return model.objects.get(pk=object_pk) @@ -275,15 +274,15 @@ def get_embedded(self): setattr(ConstantEmbedNode, LOADED_TEMPLATE_ATTR, property(get_embedded)) -def get_content_type(bit): +def parse_content_type(bit, tagname): try: app_label, model = bit.split('.') except ValueError: - raise template.TemplateSyntaxError('"%s" template tag expects the first argument to be of the form app_label.model' % tag) + raise template.TemplateSyntaxError('"%s" template tag expects the first argument to be of the form app_label.model' % tagname) try: ct = ContentType.objects.get(app_label=app_label, model=model) except ContentType.DoesNotExist: - raise template.TemplateSyntaxError('"%s" template tag requires an argument of the form app_label.model which refers to an installed content type (see django.contrib.contenttypes)' % tag) + raise template.TemplateSyntaxError('"%s" template tag requires an argument of the form app_label.model which refers to an installed content type (see django.contrib.contenttypes)' % tagname) return ct @@ -300,7 +299,7 @@ def do_embed(parser, token): raise template.TemplateSyntaxError('"%s" template tag must have at least two arguments.' % tag) if len(bits) == 3 and bits[-2] == 'with': - ct = get_content_type(bits[0]) + ct = parse_content_type(bits[0], tag) if bits[2][0] in ['"', "'"] and bits[2][0] == bits[2][-1]: return ConstantEmbedNode(ct, template_name=bits[2]) @@ -323,7 +322,7 @@ def do_embed(parser, token): return InstanceEmbedNode(instance, kwargs) elif len(bits) > 2: raise template.TemplateSyntaxError('"%s" template tag expects at most 2 non-keyword arguments when embedding instances.') - ct = get_content_type(bits[0]) + ct = parse_content_type(bits[0], tag) pk = bits[1] try: