Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simon Willison  
View profile  
 More options Sep 9 2008, 7:28 pm
From: Simon Willison <si...@simonwillison.net>
Date: Tue, 9 Sep 2008 16:28:56 -0700 (PDT)
Local: Tues, Sep 9 2008 7:28 pm
Subject: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
Back in March there was a discussion about providing a way to output
django.forms widgets as HTML (at the moment they always use XHTML,
which leads to nastyness on sites using an HTML doctype):

http://groups.google.com/group/django-developers/browse_thread/thread...

On the plane back from DjangoCon I implemented the {% doctype %} and
{% field %} tags I proposed in that thread as custom template tags in
an application called "django_html". You can grab the code from here
and try it out:

http://code.google.com/p/django-html/

svn checkout http://django-html.googlecode.com/svn/trunk/django_html
django_html

(put django_html somewhere on your python path and add it to
INSTALLED_APPS)

I'm pretty confident this is the right approach. What do people think?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Hudson  
View profile  
 More options Sep 9 2008, 7:56 pm
From: "Rob Hudson" <treborhud...@gmail.com>
Date: Tue, 9 Sep 2008 16:56:43 -0700
Local: Tues, Sep 9 2008 7:56 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
On 9/9/08, Simon Willison <si...@simonwillison.net> wrote:

>  Back in March there was a discussion about providing a way to output
>  django.forms widgets as HTML (at the moment they always use XHTML,
>  which leads to nastyness on sites using an HTML doctype):

After I read that I created the doctype part in a patch on this ticket
but didn't have the genius idea of the {% field %} tag to take it the
rest of the way...
http://code.djangoproject.com/ticket/7281

So awesome and simple.  I love it.

I'll get rid of my weird form hack on my latest project and test this out soon.

Thanks,
Rob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ville Säävuori  
View profile  
 More options Sep 9 2008, 10:32 pm
From: Ville Säävuori <vi...@syneus.fi>
Date: Tue, 9 Sep 2008 19:32:48 -0700 (PDT)
Local: Tues, Sep 9 2008 10:32 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML

> On the plane back from DjangoCon I implemented the {% doctype %} and
> {% field %} tags I proposed in that thread as custom template tags in
> an application called "django_html". You can grab the code from here
> and try it out:
> I'm pretty confident this is the right approach. What do people think?

I *love* the idea behind this.

I hate the fact that Django only outputs XHTML out of the box, even
though it should be the Web framework for perfectionists (with
deadlines and no time to write custom renderers only to get valid
HTML :)

About the {% doctype %} tag, should we then maintain a (potentially
long?) list of different doctypes and/or should there be a way to
define your own?

- VS


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Willison  
View profile  
 More options Sep 10 2008, 4:49 am
From: Simon Willison <si...@simonwillison.net>
Date: Wed, 10 Sep 2008 01:49:08 -0700 (PDT)
Local: Wed, Sep 10 2008 4:49 am
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
On Sep 10, 3:32 am, Ville Säävuori <vi...@syneus.fi> wrote:

> About the {% doctype %} tag, should we then maintain a (potentially
> long?) list of different doctypes and/or should there be a way to
> define your own?

I think we should maintain a list of doctypes - there really aren't
that many: xhtml1, xhtml1trans, xhtml1frameset, html4, html4trans,
html4frameset, xhtml11 and html5 should cover everything.

The current design of the {% doctype %} tag supports setting your own
custom doctype using the "silent" argument. You need to pick a
supported doctype that is closest to your own, then supress output
with "silent" and add your own instead:

{% doctype "xhtml1" silent %}<!DOCTYPE my-custom-xhtml-doctype>

Cheers,

Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ivan Sagalaev  
View profile  
 More options Sep 10 2008, 5:19 am
From: Ivan Sagalaev <man...@softwaremaniacs.org>
Date: Wed, 10 Sep 2008 13:19:01 +0400
Local: Wed, Sep 10 2008 5:19 am
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML

Simon Willison wrote:
> {% doctype "xhtml1" silent %}<!DOCTYPE my-custom-xhtml-doctype>

To me it looks a bit weird but I'm afraid my English is not apt to dare
to describe it :-). May be this will look cleaner:

     {% doctype "xhtml1" "<!DOCTYPE my-custom-xhtml-doctype>" %}

E.g. instead of "doctype(mode, silent=False)" it's "doctype(mode,
override='')"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Legassick  
View profile  
 More options Sep 10 2008, 6:13 am
From: Sean Legassick <sean.legass...@gmail.com>
Date: Wed, 10 Sep 2008 11:13:04 +0100
Local: Wed, Sep 10 2008 6:13 am
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML

On 10 Sep 2008, at 09:49, Simon Willison wrote:

> I think we should maintain a list of doctypes - there really aren't
> that many: xhtml1, xhtml1trans, xhtml1frameset, html4, html4trans,
> html4frameset, xhtml11 and html5 should cover everything.

There's also xhtml-mp, wml and chtml for mobile apps...

> The current design of the {% doctype %} tag supports setting your own
> custom doctype using the "silent" argument. You need to pick a
> supported doctype that is closest to your own, then supress output
> with "silent" and add your own instead:

...which can always be handled by this mechanism if not directly  
supported.

--
Sean L


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Hudson  
View profile  
 More options Sep 10 2008, 12:29 pm
From: "Rob Hudson" <treborhud...@gmail.com>
Date: Wed, 10 Sep 2008 09:29:11 -0700
Local: Wed, Sep 10 2008 12:29 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
On 9/9/08, Simon Willison <si...@simonwillison.net> wrote:

As a 3rd party app this is awesome.  It's simple and clean and doesn't
require much from the user.

But as part of Django itself, it seems like fixing django.forms (the
source) would be a better solution.

To avoid adding yet another setting (unless it's warranted here) can
the setting of a doctype in a template tag set a value in
django.conf.settings that django.forms can then check (with a
reasonable default)?

I recall seeing a patch that adds a new setting and updates (at the
time) django.newforms with some if/else logic based on the setting to
the various widgets' render methods.  I can't seem to find it now.

I'm just trying to point out that for Django to output a string that
then later gets "fixed" smells funny to me (ask Malcolm likes to say).

-Rob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ivan Sagalaev  
View profile  
 More options Sep 10 2008, 3:34 pm
From: Ivan Sagalaev <man...@softwaremaniacs.org>
Date: Wed, 10 Sep 2008 23:34:13 +0400
Local: Wed, Sep 10 2008 3:34 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML

Rob Hudson wrote:
> To avoid adding yet another setting (unless it's warranted here) can
> the setting of a doctype in a template tag set a value in
> django.conf.settings that django.forms can then check (with a
> reasonable default)?

Why not just adopt {% field %} as a default way for rendering fields
instead of unicode()ing a them? As far as I recall Simon had already
proposed this some time ago.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Willison  
View profile  
 More options Sep 10 2008, 3:43 pm
From: Simon Willison <si...@simonwillison.net>
Date: Wed, 10 Sep 2008 12:43:17 -0700 (PDT)
Local: Wed, Sep 10 2008 3:43 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
On Sep 10, 5:29 pm, "Rob Hudson" <treborhud...@gmail.com> wrote:

> To avoid adding yet another setting (unless it's warranted here) can
> the setting of a doctype in a template tag set a value in
> django.conf.settings that django.forms can then check (with a
> reasonable default)?

> I recall seeing a patch that adds a new setting and updates (at the
> time) django.newforms with some if/else logic based on the setting to
> the various widgets' render methods.  I can't seem to find it now.

> I'm just trying to point out that for Django to output a string that
> then later gets "fixed" smells funny to me (ask Malcolm likes to say).

I completely agree, but I don't think the answer is to use a global
variable to influence django.forms. My plan for integration in to
Django proper was to modify Django's widget.render method to take an
optional as_xhtml=True/False argument. The {% form %} tag would then
set that argument based on context._doctype.

I would also modify Context to have an is_xhtml() method which does
the "self._doctype in xhtml_doctypes" check.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Fagnani  
View profile  
 More options Sep 10 2008, 4:46 pm
From: "Justin Fagnani" <justin.fagn...@gmail.com>
Date: Wed, 10 Sep 2008 13:46:09 -0700
Local: Wed, Sep 10 2008 4:46 pm
Subject: Re: Proposal: {% doctype %} and {% field %} tag for outputting form widgets as HTML or XHTML
On Wed, Sep 10, 2008 at 12:43 PM, Simon Willison

<si...@simonwillison.net> wrote:
> Django proper was to modify Django's widget.render method to take an
> optional as_xhtml=True/False argument. The {% form %} tag would then
> set that argument based on context._doctype.

> I would also modify Context to have an is_xhtml() method which does
> the "self._doctype in xhtml_doctypes" check.

This isn't forms specific, but I have various classes that output HTML
into templates and one pattern I've used is to take the context in
their render() method, then display the variable with a tag that calls
render(), like:

{% render my_variable %}

I think it'd be interesting to apply this pattern to general variable
lookups, as it would solve this issue, plus be applicable to many more
problems. Variable lookups could check for render() and call it if
it's there, passing the context. Then you just call {{ my_variable }},
or {{ field }}.

Too big of a change?

-Justin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »