Opened 17 years ago
Closed 14 years ago
#7511 closed New feature (wontfix)
Automatically generate templates for newforms
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | wishlist |
| Cc: | Triage Stage: | Design decision needed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
One of the problems with using newforms at the moment is that while the form.as_*() methods offer a shortcut for generating a functional form, there is no simple migration path to go from using {{form.as_p}} in templates, to the template syntax for the same, as is necessary for further customisation.
I suggest there should be a management command to generate template code for a given form:
With this in myapp/myproject/forms.py:
class MyForm(forms.Form):
name = forms.CharField(help_text=u"Lorem ipsum dolor sit amet")
type = forms.ChoiceField(choices=[('a', 'Type A'), ('b', 'Type B')], widget=forms.RadioSelect)
you might do:
$ python manage.py formtemplate myapp.myproject.forms.MyForm
<p>{{form.name.label_tag}} {{form.name}}</p>
<p class="help_text">{{form.name.help_text}}</p>
{{form.name.errors}}
<p>{{form.type.label_tag}}</p>
{{form.type}}
{{form.type.errors}}
This could be pasted or piped into a template.
There is some complication for the same reason as #6388, as illustrated above, and the choice of what to output statically at compile time and what to determine at runtime is somewhat arbitrary. But the aim of this tool would be to assist in generating something editable, so if the form has been made dynamic in some way (eg. self.fields modified in the form constructor) this would still provide a useful foundation to customise manually.
Change History (4)
comment:1 by , 17 years ago
| milestone: | → post-1.0 |
|---|---|
| Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
| milestone: | post-1.0 |
|---|
comment:3 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:4 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
| UI/UX: | unset |
This is a great example of the kind of utility that would be a really nice contribution as an external app for those who want it, but has no need to be in core.
Milestone post-1.0 deleted