I see that you mention wrapping the include tag on a "with" block. My
personal rule is to use an inclusion_tag everytime the snippet that I
want to include contains one or more variables -- you never know when
you'll want to use it with variables of different names.
--
Eduardo de Oliveira Padoan
http://djangopeople.net/edcrypt/
I tend to see filters more as a way to format text, and inclusion_tags
looks more like function calls:
{% show_fields comment_form %}
And all it takes is:
@register.inclusion_tag('form_snippet.html')
def show_fields(form):
return {'form': form}
The difference is a matter of taste :)
Yes, someone suggests to use as_* as filters like {{ form|as_p }}
months ago (I can't find the thread) and that was clearly an
improvement in terms of flexibility. Maybe it's time to discuss this
point?
David
I'm not sure it is good to the framework to force it to designers.
Some people prefer "*", other may have already a use for a "required"
class, and so on.
> On Mon, Sep 15, 2008 at 2:57 PM, David Larlet <lar...@gmail.com> wrote:
>>
>>
>> Le 15 sept. 08 à 14:39, Julien Phalip a écrit :
>>
>> >
>> > [...]
>> >
>> >> I see that you mention wrapping the include tag on a "with" block. My
>> >> personal rule is to use an inclusion_tag everytime the snippet that I
>> >> want to include contains one or more variables -- you never know when
>> >> you'll want to use it with variables of different names.
>> >
>> > That's a good point. Mixing {% include %} and {% with %} is both more
>> > verbose and less flexible than if using a custom tag. In this case,
>> > using a custom filter would also make sense since it's about
>> > presentation:
>> >
>> > {{ form|render_form:"thisway" }}
>>
>> Yes, someone suggests to use as_* as filters like {{ form|as_p }}
>> months ago (I can't find the thread) and that was clearly an
>> improvement in terms of flexibility. Maybe it's time to discuss this
>> point?
>>
>> David
>>
>>
>>
>
>
> >
>
--
Eduardo de Oliveira Padoan
http://djangopeople.net/edcrypt/
http://whoisi.com/p/514
http://pinax.hotcluboffrance.com/profiles/edcrypt/
I disagree with you here, but you're actually writing code so... :) (I
really need to change that soon.)
Regardless of whether we do rendering with tags or filters, both
approaches would benefit from some additional attributes in fields and
widgets. When I'm writing forms I want to do as little work as
possible, but be able to override things on a very granular level when
I need to. I think a good start here would be to expose the html
element name, attributes, and children as attributes of BoundField (or
possibly also a new BoundWidget class), the existing render methods
could then be changed to use those attributes and tags and filters
would have access to everything they needed to turn those structures
into (X)HTML (N). I haven't quite figured out the details of how to
handle multi widgets, radio inputs, or other widgets with multiple
child inputs, but it shouldn't be that difficult to work out, and all
in a backwards compatible way.
Joseph
For those who weren't around or don't remember, this was a much
debated issue some time ago. Currently, there are at least two open
tickets (#3512 & #3515) vying for inclusion with different solutions
for adding classes to fields. Unfortunately, neither has been updated
in some time and both are now out-of-date with trunk.
See this comment for how to do it in your template now:
http://code.djangoproject.com/ticket/3512#comment:15
For the record, I'm still of the opinion that #3512 is the right way
to go and anything else should be left for template others to do
manually as I argued in various comments in that ticket.
--
----
Waylan Limberg
way...@gmail.com
1) For a while I've thought that Forms should support "widget sets"
where you can replace the default widgets on every form field with one
setting in Meta (this would require Meta on non-model forms). This
would open things up so you could easily use Widget subclasses with
customized output. This would let people have template based widgets
if they wished, or easily specific JS libraries for complex widgets
like auto-complete, etc.
I'd personally like to have a template-based widget set that let me
specify a directory to load my customized templates from:
class MyForm(forms.Form):
class Meta:
widget_set = TemplateWidgetSet('my_jquery_widgets')
2) I've also thought that'd it would be really nice to have some way
of dynamically transforming template output from within the template.
Basically doing jQuery-type manipulations in templates, possibly with
XPath or jQuery-style selectors. You could add a required class like
this:
{% transform %}
{% addclass "tr:has(*.required) label" "required" %}
{{ form }}
{% endtransform %}
Where I want to us that isn't with forms, but with menus:
{% transform %}
{% select %}#menu_{{ section }}{% endselect %}
{% addclass "selected" %}
<li id="menu_home"><a>Home</a></li>
<li id="menu_foo"><a>Foo</a></li>
...etc...
{% endtransform %}
That would add a "selected" class to the current sections menu item.
Right now I have to include a template that has an {% if %} inside
every <li> tag.
Just thought I'd throw this out there...
Cheers,
Justin
That would be the idea. You of course noticed some wrinkles, but I
think it'd be awesome if you could install a djQuery or djojo app and
get a bunch of form widgets and view base classes effectively give you
AJAX support of of the box.
> One problem I see is that for AJAX, you need to add view support. If I
> were to switch from my regular form to an AJAX form with just a Meta
> setting, how is my once-a-plain-CharFeild-but-now-auto-complete Widget
> supposed to find its supporting view?
I don't think that's too much of an issue. A CharField is never going
to magically going to convert to an AutoCompleteField without
specifying the data source to work from, but an AutoCompleteField
could provide a common interface that would allow the dev to switch
implementations. Maybe class based views could then be used to easily
provide the correct output format. A ChoiceField could be AJAXified
without additional configuration.
>> 2) I've also thought that'd it would be really nice to have some way
>> of dynamically transforming template output from within the template.
>> Basically doing jQuery-type manipulations in templates, possibly with
>> XPath or jQuery-style selectors. You could add a required class like
>> this:
>>
>> {% transform %}
>> {% addclass "tr:has(*.required) label" "required" %}
>> {{ form }}
>> {% endtransform %}
>
> That seems wicked cool, even if I don't understand it fully :D What
> does "has(*.required)" select? A tr with a descendant with a
> "required" class? It doesn't seem like XPath to me
Yeah, tha'ts jQuery, not XPath. "tr:has(*.required)" would be
approximately "tr[*[contains(@class, 'required')]]" in XPath, I think.
XPath is ugly when using predicates.
> But, as Simon pointed out, it might be a pretty big performance hog.
> And generally the template library mostly contains easy-to-undestand
> functionality, while "transform" just screams XSLT :)
This is true, but since templates are usually used to generate HTML,
it seems like a good idea to offer some HTML/XML specific features
when there's a benefit. Not sure if this counts since it's easily
contained in a third-party app.
-Justin