views:

285

answers:

3

I've got a variable number of items, somewhere between 0 and 20.

I'd like to list these with Google Static Maps, showing a little "a" for the first one, a "b" for the second one and so on.

I'm a newbie using Google App Engine so I'm constrained to 0.96 (unless I use various patches, which I don't want to do. Because I'm a newbie.)

&markers={% for item in results %}{{item.latitude}},{{item.longitude}}{% if not forloop.last %}|{% endif %}{% endfor %}

is working fine to provide a list of red markers.

&markers={% for item in results %}{{item.latitude}},{{item.longitude}},{{forloop.counter0}}{% if not forloop.last %}|{% endif %}{% endfor %}

gets me 0-9 on the map.

For now, I've cut the result set down to 10. I'd like to go back to 20. Is there a way of using the loopcounter and slice (as in {{ alpha_list|slice:":loop_counter"}} ? I struggled with various incantations, trying {{ }} around loop_counter and without and couldn't get it to work.

Thanks!

+2  A: 

Easiest would be to write a template tag. There's a good tut, but the code would basically be:

def inttoalpha(n):
    a = ord('A')
    return chr(a+n)
tghw
Thanks for the lead. Implementing tags looks like something I will circle back to later. I'll stick with 10 items for now.
jdeibele
A: 

create a template tag using method provided here

http://stackoverflow.com/questions/228730/how-do-i-iterate-through-the-alphabet-in-python

phillc
A: 

If you want do it entirely within the template, you can use the cycle tag.

Something like the following, with ... expanded:

{% cycle 'a' 'b' ... 'z' as alphabet %}
&markers={% for item in results %}{{item.latitude}},{{item.longitude}},{% cycle alphabet %}{% if not forloop.last %}|{% endif %}{% endfor %}
Dave W. Smith
I like that a lot! Thanks.
jdeibele