[PATCH 1/2] templates: Use form.as_table in registration template.

Stephen Finucane stephen at that.guru
Fri Aug 13 02:32:40 AEST 2021


On Sat, 2021-02-27 at 09:59 +0000, Christopher Baines wrote:
> This should make changes to the registration form easier. I'm
> particularly thinking about adding in the Django simple math captcha.
> ---
>  htdocs/css/style.css                          |  4 +-
>  patchwork/forms.py                            |  9 ++-
>  .../templates/patchwork/registration.html     | 81 +------------------
>  3 files changed, 11 insertions(+), 83 deletions(-)
> 
> diff --git a/htdocs/css/style.css b/htdocs/css/style.css
> index 243caa0..e417c69 100644
> --- a/htdocs/css/style.css
> +++ b/htdocs/css/style.css
> @@ -398,10 +398,10 @@ table.form th {
>      padding-top: 0.6em;
>  }
>  
> -table.form td.form-help {
> +span.helptext {
>      font-size: smaller;
>      padding-bottom: 1em;
> -    padding-top: 0em;
> +    padding-top: 1em;
>  }
>  

This is related to later changes, I guess. Are we sure this doesn't have a knock
on impact for other forms? Maybe there are none?

>  table.form tr td.submitrow {
> diff --git a/patchwork/forms.py b/patchwork/forms.py
> index 24322c7..e06cfc1 100644
> --- a/patchwork/forms.py
> +++ b/patchwork/forms.py
> @@ -16,10 +16,15 @@ from patchwork.models import UserProfile
>  
>  class RegistrationForm(forms.Form):
>      first_name = forms.CharField(max_length=30, required=False)
> -    last_name = forms.CharField(max_length=30, required=False)
> +    last_name = forms.CharField(max_length=30,
> +                                required=False,
> +                                help_text='Your name is used to identify you on '
> +                                          'the site')
> +    email = forms.EmailField(max_length=100, label=u'Email address',
> +                             help_text='Patchwork will send a confirmation email '
> +                                       'to this address')
>      username = forms.RegexField(regex=r'^\w+$', max_length=30,
>                                  label=u'Username')
> -    email = forms.EmailField(max_length=100, label=u'Email address')
>      password = forms.CharField(widget=forms.PasswordInput(),
>                                 label='Password')
> 

I was going to suggest that this would requires a database migration but it's a
form, not a model. Silly me /o\

> diff --git a/patchwork/templates/patchwork/registration.html b/patchwork/templates/patchwork/registration.html
> index 5280b66..6cdbc5a 100644
> --- a/patchwork/templates/patchwork/registration.html
> +++ b/patchwork/templates/patchwork/registration.html
> @@ -27,86 +27,9 @@
>    <tr>
>     <td colspan="2">{{ error }}</td>
>    </tr>
> - {% endif %}
> +  {% endif %}
>  
> -  <tr>
> -   <td>{{ form.first_name.label_tag }}</td>
> -   <td>
> -{% if form.first_name.errors %}
> -    {{ form.first_name.errors }}
> -{% endif %}
> -    {{ form.first_name }}
> -{% if form.first_name.help_text %}
> -    <div class="help_text"/>{{ form.first_name.help_text }}</div>
> -{% endif %}
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td>{{ form.last_name.label_tag }}</td>
> -   <td>
> -{% if form.last_name.errors %}
> -    {{ form.last_name.errors }}
> -{% endif %}
> -    {{ form.last_name }}
> -{% if form.last_name.help_text %}
> -    <div class="help_text"/>{{ form.last_name.help_text }}</div>
> -{% endif %}
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td></td>
> -   <td class="form-help">
> -    Your name is used to identify you on the site
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td>{{ form.email.label_tag }}</td>
> -   <td>
> -{% if form.email.errors %}
> -    {{ form.email.errors }}
> -{% endif %}
> -    {{ form.email }}
> -{% if form.email.help_text %}
> -    <div class="help_text"/>{{ form.email.help_text }}</div>
> -{% endif %}
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td></td>
> -   <td class="form-help">
> -    Patchwork will send a confirmation email to this address
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td>{{ form.username.label_tag }}</td>
> -   <td>
> -{% if form.username.errors %}
> -    {{ form.username.errors }}
> -{% endif %}
> -    {{ form.username }}
> -{% if form.username.help_text %}
> -    <div class="help_text"/>{{ form.username.help_text }}</div>
> -{% endif %}
> -   </td>
> -  </tr>
> -
> -  <tr>
> -   <td>{{ form.password.label_tag }}</td>
> -   <td>
> -{% if form.password.errors %}
> -    {{ form.password.errors }}
> -{% endif %}
> -    {{ form.password }}
> -{% if form.password.help_text %}
> -    <div class="help_text"/>{{ form.password.help_text }}</div>
> -{% endif %}
> -   </td>
> -  </tr>
> +  {{ form.as_table }}
>  
>     <tr>
>    <td colspan="2" class="submitrow">

While I like what you're going for here, this is pretty much the opposite of
what we plan to do here over the long term /o\ These forms are pretty tough to
customize and, in a more AJAX'y future, probably won't be used much for anything
bar validation. Would it be possible to keep what we have here and instead
render the form element manually, assuming it's present in the context (so we
can make the feature optional for now).

Cheers,
Stephen



More information about the Patchwork mailing list