Joel wrote:
> I gave django a try at work to develop a survey application. Turned out
> pretty sweet, I felt very productive and spent most of my time
> concentrating on survey tasks. I felt frustrated twice, these are the
> hurdles I faced that I feel I have probably missed obvious solutions
> 
> - Parsing data from the users. I decided not to use the admin framework
> to get the answers from the questions. I needed fine grained control
> over user input and it looked too complicated and not geared towards
> what I was doing. So I made my own function that turned the ID's of
> checkboxes, radio buttons etc, into ID's to lookup in the question
> table. It worked o.k. but was a bit of a hack in parts.

Did you look at the forms and manipulators docs:

http://www.djangoproject.com/documentation/forms/

> - Printing questions. I wanted to have a question template that defined
> how questions should be printed, then I could print them in multiple
> contexts. Except I couldn't find an easy way to do this. I saw I could
> define a filter and pass the question object into a "printQuestion"
> filter but this seemed counterintuitive. Perhaps I could have
> pre-rendered and passed rendered questions to the templates but this
> didn't seem right either. When I used Mason we componentized everything
> and plugged bits and pieces back together in all kinds of ways.
> Obviously, to get that level of control you need to have code at the
> template level, and I understand django's aims of moving the code away
> from the templates (and I agree with it). What is the right way to
> define a standard way you want an object to be printed?
> 

There are two solutions here, that are both in trunk, but not in 0.90.

1. {% include "path/to/template" %}

There is a not very nice way of doing this in 0.90, which is the {%ssi
"/absolute/path/to/template/no/really.html" parsed %} tag.

2. Inclusion tag. This is an example I wrote earlier on the list:

(python 2.4 decorator syntax, no i18n) :

in a templatetag module: (read the template docs)
-----------------------
from django.core import template
register = template.Library()

names = ['mushrooms','cheese','tomatoes','onion']

@register.inclusion_tag("myapp/menu")
def menu(selected):
    return {
        'items': [ { 'name':name,
                     'selected': name == selected } for name in  ]
    }

-----------------------
myapp/menu.html:
-----------------------
<ul>
{%for item in items%}
<li {%if item.selected%}class='selected'{%endif%} >
{%endfor%}
</ul>

Reply via email to