I am trying to set up a templatetag that will give me a variable to use in templates so we can modify our presentation of stories depending upon whether the accompanying photo is horizontal or vertical. I am using 0.91 EllingtonCMS.
I've made a templatetag in /ellington/media/photos.py that looks like this: class WideOrDeepNode(CachedNode): def __init__(self, photoobj, varname): self.photoobj = photoobj self.varname = varname self.cache_timeout = 180 def get_cache_key(self, context): return "ellington.media.templatetags.photos.do_get_wideordeep:%s" % (SITE_ID) def get_content(self, context): if self.photoobj.width <= self.photoobj.height: context[self.varname] = '0' else: context[self.varname] = '1' return "" def do_get_wideordeep(parser, token): """ Checks to see if the photo object's width is greater than its length and will return '0' if it is. Otherwise returns '1'. Syntax:: {% get_wideordeep object.id [as varname] %} """ bits = token.contents.split() if len(bits) == 2: photoobj = bits[1] varname = 'imageflag' elif len(bits) == 4: photoobj = bits[1] varname = bits[3] else: raise template.TemplateSyntaxError, "'%s' tag takes either one or two arguments" % bits[0] return WideOrDeepNode(photoobj,varname) on the template, here is how I am asking for it: {% get_wideordeep homepage.get_piece_dict.lead_story.get_lead_photo as imageflag %} {% ifequal imageflag 0 %} <h1>This story's image is square or wider than deeper<br /><a href="{{ homepage.get_piece_dict.lead_story.get_absolute_url }}">{{ homepage.get_piece_dict.lead_story.headline }}</a></h1> <p>{% if homepage.get_piece_dict.lead_story.get_lead_photo.get_photo_url %} <a href="{{ homepage.get_piece_dict.lead_story.get_absolute_url }}"> <img style="max-height:190px;padding-left:5px;float:right;border-width: 5px;border-color:#ffffff;" border=3 bordercolor="white" src="{{ homepage.get_piece_dict.lead_story.get_lead_photo.get_photo_url| thumbnail:"180" }}"></a>{% endif %} {% if homepage.get_piece_dict.lead_story.tease %} {{ homepage.get_piece_dict.lead_story.tease }}{% endif %} </p> {% endifequal %} {% endif %} the results I get are "AttributeError at /homepage/dmtest/ 'str' object has no attribute 'width'" the problem line seems to be this one: if self.photoobj.width <= self.photoobj.height: this code is also at dpaste -- http://dpaste.com/122889/ Am I going about this all wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---