Thanks again for all your help.
I believe I have something that is finally working:
class WideOrDeepNode(template.Node):
def __init__(self, photoobj, varname):
self.photoobj = photoobj
self.varname = varname
def render(self, context):
self.photoobj = resolve_variable(self.photoobj, context)
context[self.varname] = self.photoobj.width <=
self.photoobj.height
return ''
def do_get_wideordeep(parser, token):
"""
Checks to see if the photo is horizontal (and square) or
vertical. Will return '1' if it is vertical. Otherwise returns '0'.
Syntax::
{% get_wideordeep object.id [as varname] %}
"""
bits = token.contents.split()
if len(bits) == 2:
photoobj = bits[1]
varname = 'image_is_vertical'
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 Feb 22, 7:30 pm, Malcolm Tredinnick <[email protected]>
wrote:
> On Sun, 2009-02-22 at 16:23 -0800, David MacDougall wrote:
> > Hi Malcolm
> > You are right about the essence of the problem.
> > The value of photoobj is
> > "'homepage.get_piece_dict.lead_story.get_lead_photo" and I am trying
> > to get it to be an integer, the id of the photo I am trying to
> > measure.
>
> So you have to resolve that string the same way the template code does.
> In Django 0.91, that was the resolve_variable() function, which you can
> see being used a lot in django/core/templates/defaulttags.py.
>
> It's currently not even close to something you can use as a pk value in
> a filter.
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---