Просмотр исходного кода

User CP is powered by floppy forms. #114

Ralfp 12 лет назад
Родитель
Сommit
141f17e5ca

+ 4 - 11
misago/apps/usercp/avatar/forms.py

@@ -1,23 +1,16 @@
 from PIL import Image
-from django import forms
+import floppyforms as forms
 from django.core.exceptions import ValidationError
 from django.utils.translation import ugettext_lazy as _
 from misago.conf import settings
 from misago.forms import Form
 
 class UploadAvatarForm(Form):
-    avatar_upload = forms.ImageField(error_messages={'invalid_image': _("Uploaded file is not correct image.")})
+    avatar_upload = forms.ImageField(label= _("Upload Image File"),
+                                     help_text= _("Select image file on your computer you wish to use as forum avatar. You will be able to crop image after upload. Animations will be stripped."),
+                                     error_messages={'invalid_image': _("Uploaded file is not correct image.")})
     error_source = 'avatar_upload'
 
-    layout = [
-              [
-               None,
-               [
-                ('avatar_upload', {'label': _("Upload Image File"), 'help_text': _("Select image file on your computer you wish to use as forum avatar. You will be able to crop image after upload. Animations will be stripped.")}),
-                ],
-               ],
-              ]
-
     def clean_avatar_upload(self):
         image = self.cleaned_data.get('avatar_upload', False)
         if image:

+ 1 - 2
misago/apps/usercp/avatar/views.py

@@ -9,7 +9,6 @@ from django.utils.translation import ugettext as _
 from misago.apps.errors import error404
 from misago.conf import settings
 from misago.decorators import block_guest
-from misago.forms import FormLayout
 from misago.messages import Message
 from misago.shortcuts import render_to_response
 from misago.utils.strings import random_string
@@ -163,7 +162,7 @@ def upload(request):
     return render_to_response('usercp/avatar_upload.html',
                               context_instance=RequestContext(request, {
                                   'message': message,
-                                  'form': FormLayout(form),
+                                  'form': form,
                                   'tab': 'avatar'}));
 
 

+ 10 - 15
misago/apps/usercp/credentials/forms.py

@@ -1,5 +1,5 @@
 import hashlib
-from django import forms
+import floppyforms as forms
 from django.core.exceptions import ValidationError
 from django.utils.translation import ugettext_lazy as _
 from misago.forms import Form
@@ -7,20 +7,15 @@ from misago.models import User
 from misago.validators import validate_password, validate_email
 
 class CredentialsChangeForm(Form):
-    new_email = forms.EmailField(max_length=255, required=False)
-    new_password = forms.CharField(max_length=255, widget=forms.PasswordInput, required=False)
-    current_password = forms.CharField(max_length=255, widget=forms.PasswordInput)
-
-    layout = [
-              (
-               None,
-               [
-                ('new_email', {'label': _('New E-mail'), 'help_text': _("Enter new e-mail address or leave this field empty if you want only to change your password.")}),
-                ('new_password', {'label': _('New Password'), 'help_text': _("Enter new password or leave this empty if you only want to change your e-mail address.")}),
-                ('current_password', {'label': _('Current Password'), 'help_text': _("Confirm changes by entering your current password.")})
-                ]
-               ),
-              ]
+    new_email = forms.EmailField(label=_('New E-mail'),
+                                 help_text=_("Enter new e-mail address or leave this field empty if you want only to change your password."),
+                                 max_length=255, required=False)
+    new_password = forms.CharField(label=_('New Password'),
+                                   help_text=_("Enter new password or leave this empty if you only want to change your e-mail address."),
+                                   max_length=255, widget=forms.PasswordInput, required=False)
+    current_password = forms.CharField(label= _('Current Password'),
+                                       help_text=_("Confirm changes by entering your current password."),
+                                       max_length=255, widget=forms.PasswordInput)
 
     def clean_new_email(self):
         if self.cleaned_data['new_email']:

+ 1 - 2
misago/apps/usercp/credentials/views.py

@@ -4,7 +4,6 @@ from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
 from misago.apps.errors import error404
 from misago.decorators import block_guest
-from misago.forms import FormLayout
 from misago.messages import Message
 from misago.shortcuts import render_to_response
 from misago.utils.strings import random_string
@@ -43,7 +42,7 @@ def credentials(request):
     return render_to_response('usercp/credentials.html',
                               context_instance=RequestContext(request, {
                                   'message': message,
-                                  'form': FormLayout(form),
+                                  'form': form,
                                   'tab': 'credentials'}));
 
 

+ 17 - 31
misago/apps/usercp/options/forms.py

@@ -1,53 +1,39 @@
-from django import forms
+import floppyforms as forms
 from django.utils.translation import ugettext_lazy as _
 from misago.forms import Form
 from misago.utils.timezones import tzlist
 
 class UserForumOptionsForm(Form):
-    newsletters = forms.BooleanField(required=False)
-    timezone = forms.ChoiceField(choices=tzlist())
-    hide_activity = forms.TypedChoiceField(choices=(
+    newsletters = forms.BooleanField(label=_("Newsletters"),
+                                     help_text=_("On occasion board administrator may want to send e-mail message to multiple members."),
+                                     required=False)
+    timezone = forms.ChoiceField(label=_("Your Current Timezone"),
+                                 help_text=_("If dates and hours displayed by forums are inaccurate, you can fix it by adjusting timezone setting."),
+                                 choices=tzlist())
+    hide_activity = forms.TypedChoiceField(label=_("Your Visibility"),
+                                           help_text=_("If you want to, you can limit other members ability to track your presence on forums."),
+                                           choices=(
                                                     (0, _("Show my presence to everyone")),
                                                     (1, _("Show my presence to people I follow")),
                                                     (2, _("Show my presence to nobody")),
                                                     ), coerce=int)
-    subscribe_start = forms.TypedChoiceField(choices=(
+    subscribe_start = forms.TypedChoiceField(label=_("Threads I start"),
+                                             choices=(
                                                       (0, _("Don't watch")),
                                                       (1, _("Put on watched threads list")),
                                                       (2, _("Put on watched threads list and e-mail me when somebody replies")),
                                                       ), coerce=int)
-    subscribe_reply = forms.TypedChoiceField(choices=(
+    subscribe_reply = forms.TypedChoiceField(label=_("Threads I reply to"),
+                                             choices=(
                                                       (0, _("Don't watch")),
                                                       (1, _("Put on watched threads list")),
                                                       (2, _("Put on watched threads list and e-mail me when somebody replies")),
                                                       ), coerce=int)
-    allow_pds = forms.TypedChoiceField(choices=(
+    allow_pds = forms.TypedChoiceField(label=_("Allow Private Threads Invitations"),
+                                       help_text=_("If you wish, you can restrict who can invite you to private threads. Keep in mind some groups or members may be allowed to override this preference."),
+                                       choices=(
                                                 (0, _("From everyone")),
                                                 (1, _("From everyone but not members I ignore")),
                                                 (2, _("From members I follow")),
                                                 (2, _("From nobody")),
                                                 ), coerce=int)
-
-    layout = (
-              (
-               _("Privacy"),
-               (
-                ('hide_activity', {'label': _("Your Visibility"), 'help_text': _("If you want to, you can limit other members ability to track your presence on forums.")}),
-                ('allow_pds', {'label': _("Allow Private Threads Invitations"), 'help_text': _("If you wish, you can restrict who can invite you to private threads. Keep in mind some groups or members may be allowed to override this preference.")}),
-                )
-               ),
-              (
-               _("Forum Options"),
-               (
-                ('timezone', {'label': _("Your Current Timezone"), 'help_text': _("If dates and hours displayed by forums are inaccurate, you can fix it by adjusting timezone setting.")}),
-                ('newsletters', {'label': _("Newsletters"), 'help_text': _("On occasion board administrator may want to send e-mail message to multiple members."), 'inline': _("Yes, I want to subscribe forum newsletter")}),
-                )
-               ),
-              (
-               _("Watching Threads"),
-               (
-                ('subscribe_start', {'label': _("Threads I start")}),
-                ('subscribe_reply', {'label': _("Threads I reply to")}),
-                )
-               ),
-              )

+ 1 - 2
misago/apps/usercp/options/views.py

@@ -2,7 +2,6 @@ from django.core.urlresolvers import reverse
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
 from misago.decorators import block_guest
-from misago.forms import FormLayout
 from misago.messages import Message
 from misago.shortcuts import render_to_response
 from misago.apps.usercp.options.forms import UserForumOptionsForm
@@ -38,4 +37,4 @@ def options(request):
                               context_instance=RequestContext(request, {
                                   'message': message,
                                   'tab': 'options',
-                                  'form': FormLayout(form)}));
+                                  'form': form}));

+ 1 - 11
misago/apps/usercp/signature/forms.py

@@ -1,16 +1,6 @@
-from django import forms
+import floppyforms as forms
 from django.utils.translation import ugettext_lazy as _
 from misago.forms import Form
 
-
 class SignatureForm(Form):
     signature = forms.CharField(widget=forms.Textarea, required=False)
-
-    layout = (
-              (
-               None,
-               (
-                ('signature', {'label': _("Your Signature"), 'attrs': {'rows': 10}}),
-                )
-               ),
-              )

+ 1 - 2
misago/apps/usercp/signature/views.py

@@ -3,7 +3,6 @@ from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
 from misago.apps.errors import error403, error404
 from misago.decorators import block_guest
-from misago.forms import FormLayout
 from misago.markdown import signature_markdown
 from misago.messages import Message
 from misago.shortcuts import render_to_response
@@ -43,4 +42,4 @@ def signature(request):
                               context_instance=RequestContext(request, {
                                   'message': message,
                                   'tab': 'signature',
-                                  'form': FormLayout(form)}));
+                                  'form': form}));

+ 4 - 11
misago/apps/usercp/username/forms.py

@@ -1,22 +1,15 @@
-from django import forms
+import floppyforms as forms
 from django.core.exceptions import ValidationError
 from django.utils.translation import ugettext_lazy as _
 from misago.forms import Form
 from misago.validators import validate_username
 
 class UsernameChangeForm(Form):
-    username = forms.CharField(max_length=255)
+    username = forms.CharField(label=_("Change Username to"),
+                               help_text=_("Enter new desired username."),
+                               max_length=255)
     error_source = 'username'
 
-    layout = [
-              [
-               None,
-               [
-                ('username', {'label': _("Change Username to"), 'help_text': _("Enter new desired username.")}),
-                ],
-               ],
-              ]
-
     def clean_username(self):
         org_username = self.request.user.username
         if org_username == self.cleaned_data['username']:

+ 1 - 2
misago/apps/usercp/username/views.py

@@ -6,7 +6,6 @@ from django.utils import timezone
 from django.utils.translation import ugettext as _
 from misago.apps.errors import error404
 from misago.decorators import block_guest
-from misago.forms import FormLayout
 from misago.messages import Message
 from misago.models import Alert, User, UsernameChange
 from misago.shortcuts import render_to_response
@@ -65,7 +64,7 @@ def username(request):
                               context_instance=RequestContext(request, {
                                   'message': message,
                                   'changes_left': changes_left,
-                                  'form': FormLayout(form),
+                                  'form': form,
                                   'next_change': next_change,
                                   'changes_history': request.user.namechanges.order_by('-date')[:10],
                                   'tab': 'username'}));

+ 32 - 4
templates/cranefly/forms.html

@@ -1,24 +1,29 @@
 {# Forms macros for rendering forms and fields and stuff in templates. #}
 
-{% macro hiddens(form) -%}
+{% macro hidden_fields(form) -%}
   <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
   {% for field in form.hidden_fields() %}
   <input type="hidden" name="{{ field.html_name }}" value="{{ field.value() }}">
   {% endfor %}
 {%- endmacro %}
 
-{% macro row(_field, label=None, help_text=None, width=12, attrs=None) -%}
+{% macro row(_field, label=None, help_text=None, width=9, attrs=None) -%}
   <div id="{{ field.html_name }}-control-group" class="control-group{% if _field.errors %} error{% endif %}">
     <label class="control-label" for="id_{{ field.html_name }}">{% if label %}{{ label }}{% elif _field.label %}{{ _field.label }}{% else %}{{ _field.html_name }}{% endif %}</label>
     <div class="controls">
+      {% if attrs == None %}{% set attrs = {} %}{% endif %}
       {% if _field.field.widget.__class__.__name__ == 'CheckboxInput' %}
         <label class="checkbox">
           {{ field(_field, width=width, attrs=attrs)|trim }}
+          {% if 'inline' in attrs %}
+          {{ attrs.inline }}
+          {% else %}
           {% if help_text %}
           {{ help_text }}
           {% elif _field.help_text %}
           {{ _field.help_text }}
           {% endif %}
+          {% endif %}
         </label>
       {% else %}
         {{ field(_field, width=width, attrs=attrs)|trim }}
@@ -26,7 +31,7 @@
         {% for error in _field.errors %}
         <p class="help-block" style="font-weight: bold;">{{ error }}</p>
         {% endfor %}
-        {% if _field.field.widget.__class__.__name__ != 'CheckboxInput' %}
+        {% if 'inline' in attrs or _field.field.widget.__class__.__name__ != 'CheckboxInput' %}
         {% if help_text %}
         <p class="help-block">{{ help_text }}</p>
         {% elif _field.help_text %}
@@ -37,13 +42,20 @@
   </div>
 {%- endmacro %}
 
-{% macro field(_field, attrs=None, width=8) -%}
+{% macro field(_field, attrs=None, width=9) -%}
 {% set widget = _field.field.widget.__class__.__name__ %}
 {% set context = _field.field.widget.get_context(_field.html_name, _field.value(), attrs=attrs) %}
 {% if not 'class' in context['attrs'] and not widget == 'CheckboxInput' %}
 {% do context['attrs'].update({'class': ('span' ~ width)}) %}
 {% endif %}
+{% if 'inline' in context.attrs %}{% do context.attrs.pop('inline') %}{% endif %}
+{% if widget == 'Textarea' %}
+{{ _textarea(_field, context) }}
+{% elif widget == 'Select' %}
+{{ _select(_field, context) }}
+{% else %}
 {{ _input(_field, context) }}
+{% endif %}
 {%- endmacro %}
 
 {% macro attributes(attrs) -%}
@@ -55,7 +67,23 @@
 {%- endmacro %}
 
 {% macro _textarea(_field, context) -%}
+<textarea id="id_{{ context.name }}" name="{{ context.name }}" {{ attributes(context.attrs)|trim }}>{% if 'value' in context and context.value|length > 0 %}{{ context.value }}{% endif %}</textarea>
 {%- endmacro %}
 
 {% macro _select(_field, context) -%}
+<select id="id_{{ context.name }}" name="{{ context.name }}" {{ attributes(context.attrs)|trim }}>
+  {% if context['optgroups']|length > 1 %}
+  {% for optgroup in context['optgroups'] %}
+  <optgroup label="{{ optgroup[0] }}">
+    {% for option in optgroup[1] %}
+    <option value="{{ option[0] }}"{% if 'value' in context and option[0] in context.value %} selected="selected"{% endif %}>{{ option[1] }}</option>
+    {% endfor %}
+  </optgroup>
+  {% endfor %}
+  {% else %}
+  {% for option in context['optgroups'][0][1] %}
+  <option value="{{ option[0] }}"{% if 'value' in context and option[0] in context.value %} selected="selected"{% endif %}>{{ option[1] }}</option>
+  {% endfor %}
+  {% endif %}
+</select>
 {%- endmacro %}

+ 1 - 2
templates/cranefly/signin.html

@@ -36,8 +36,7 @@
 
       <form class="form-horizontal" action="{{ url('sign_in') }}" method="post">
         <div class="form-fields">
-          {{ form_theme.hiddens(form) }}
-          {# form_theme.form_widget(form, horizontal=true, width=6) #}
+          {{ form_theme.hidden_fields(form) }}
           {{ form_theme.row(form.user_email, attrs={'class': 'span4', 'placeholder': _("Enter your e-mail")}) }}
           {{ form_theme.row(form.user_password, attrs={'class': 'span4', 'placeholder': _("Enter your password")}) }}
           {% if 'user_remember_me' in form.fields %}

+ 3 - 2
templates/cranefly/usercp/avatar_upload.html

@@ -1,5 +1,5 @@
 {% extends "cranefly/usercp/layout.html" %}
-{% import "_forms.html" as form_theme with context %}
+{% import "cranefly/forms.html" as form_theme with context %}
 {% import "cranefly/macros.html" as macros with context %}
 
 {% block title %}{{ macros.page_title(title=_('Upload Avatar')) }}{% endblock %}
@@ -18,8 +18,9 @@
   {% endif %}
 
   <form action="{{ url('usercp_avatar_upload') }}" method="post" enctype="multipart/form-data">
+    {{ form_theme.hidden_fields(form) }}
     <input type="hidden" id="js_check" name="js_check" value="0">
-    {{ form_theme.form_widget(form, width=9) }}
+    {{ form_theme.row(form.avatar_upload) }}
     <div class="form-actions">
       <button name="save" type="submit" class="btn btn-primary">{% trans %}Upload Avatar{% endtrans %}</button>
       <a href="{{ url('usercp_avatar') }}" class="btn">{% trans %}Cancel{% endtrans %}</a>

+ 5 - 2
templates/cranefly/usercp/credentials.html

@@ -1,5 +1,5 @@
 {% extends "cranefly/usercp/layout.html" %}
-{% import "_forms.html" as form_theme with context %}
+{% import "cranefly/forms.html" as form_theme with context %}
 {% import "cranefly/macros.html" as macros with context %}
 
 {% block title %}{{ macros.page_title(title=_('Change your Sign-In Credentials')) }}{% endblock %}
@@ -18,8 +18,11 @@
   {% endif %}
 
   <form action="{{ url('usercp_credentials') }}" method="post">
+    {{ form_theme.hidden_fields(form) }}
     <div class="form-fields">
-      {{ form_theme.form_widget(form, width=9) }}
+      {{ form_theme.row(form.new_email) }}
+      {{ form_theme.row(form.new_password) }}
+      {{ form_theme.row(form.current_password) }}
     </div>
     <div class="form-actions">
   	  <button name="save" type="submit" class="btn btn-primary">{% trans %}Change Credentials{% endtrans %}</button>

+ 18 - 2
templates/cranefly/usercp/options.html

@@ -1,5 +1,5 @@
 {% extends "cranefly/usercp/layout.html" %}
-{% import "_forms.html" as form_theme with context %}
+{% import "cranefly/forms.html" as form_theme with context %}
 {% import "cranefly/macros.html" as macros with context %}
 
 {% block title %}{{ macros.page_title(title=_('Change Forum Options')) }}{% endblock %}
@@ -18,8 +18,24 @@
   {% endif %}
 
   <form action="{{ url('usercp_options') }}" method="post">
+    {{ form_theme.hidden_fields(form) }}
     <div class="form-fields">
-      {{ form_theme.form_widget(form, width=9) }}
+      {# form_theme.form_widget(form, width=9) #}
+      <fieldset>
+        <legend>{% trans %}Privacy{% endtrans %}</legend>
+        {{ form_theme.row(form.hide_activity) }}
+        {{ form_theme.row(form.allow_pds) }}
+      </fieldset>
+      <fieldset>
+        <legend>{% trans %}Forum Options{% endtrans %}</legend>
+        {{ form_theme.row(form.timezone) }}
+        {{ form_theme.row(form.newsletters, attrs={'inline': _("Yes, I want to subscribe forum newsletter.")}) }}
+      </fieldset>
+      <fieldset>
+        <legend>{% trans %}Watching Threads{% endtrans %}</legend>
+        {{ form_theme.row(form.subscribe_start) }}
+        {{ form_theme.row(form.subscribe_reply) }}
+      </fieldset>
     </div>
     <div class="form-actions">
       <button name="save" type="submit" class="btn btn-primary">{% trans %}Change Options{% endtrans %}</button>

+ 0 - 1
templates/cranefly/usercp/signature.html

@@ -1,5 +1,4 @@
 {% extends "cranefly/usercp/layout.html" %}
-{% import "_forms.html" as form_theme with context %}
 {% import "cranefly/editor.html" as editor with context %}
 {% import "cranefly/macros.html" as macros with context %}
 

+ 5 - 3
templates/cranefly/usercp/username.html

@@ -1,5 +1,5 @@
 {% extends "cranefly/usercp/layout.html" %}
-{% import "_forms.html" as form_theme with context %}
+{% import "cranefly/forms.html" as form_theme with context %}
 {% import "cranefly/macros.html" as macros with context %}
 
 {% block title %}{{ macros.page_title(title=_('Change your Username')) }}{% endblock %}
@@ -18,11 +18,13 @@
   {% endif %}
 
   <form action="{{ url('usercp_username') }}" method="post">
+    {{ form_theme.hidden_fields(form) }}
     <div class="form-fields">
       {% if changes_left == 0 %}
-      {% do form.fields['username']['attrs'].update({'disabled': 'disabled'}) %}
+      {{ form_theme.row(form.username, attrs={'disabled': 'disabled'}) }}
+      {% else %}
+      {{ form_theme.row(form.username) }}
       {% endif %}
-      {{ form_theme.form_widget(form, width=9) }}
     </div>
     <div class="form-actions">
       <button name="save" type="submit" class="btn btn-primary"{% if changes_left == 0 %} disabled="disabled"{% endif %}>{% trans %}Change Name{% endtrans %}</button>