From 13b92bc1a4406208a6fce29f1d4ad817a80c1912 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Tue, 17 Sep 2013 16:03:15 -0300 Subject: [PATCH] Updating signup form --- src/accounts/forms.py | 29 +++++++++++++++++++---------- src/accounts/templates/accounts/signup-form.html | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- src/accounts/views.py | 23 +++++++++++++++++++++-- src/colab/static/css/screen.css | 34 +++++++++------------------------- 4 files changed, 97 insertions(+), 82 deletions(-) diff --git a/src/accounts/forms.py b/src/accounts/forms.py index cafc5ec..6c7ec1a 100644 --- a/src/accounts/forms.py +++ b/src/accounts/forms.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from django import forms -from django.core.exceptions import ValidationError from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm as UserCreationForm_ from django.utils.translation import ugettext_lazy as _ @@ -17,15 +16,12 @@ for list_ in MailingList.objects.iterator(): class UserCreationForm(UserCreationForm_): - first_name = forms.CharField(max_length=30, label=_(u'Name')) - last_name = forms.CharField(max_length=30, label=_(u'Last name')) - email = forms.EmailField(validators=[UniqueValidator(User, 'email')]) - institution= forms.CharField(max_length=120, label=_(u'Institution'), required=False) - role = forms.CharField(max_length=60, label=_(u'Role'), required=False) - twitter = forms.URLField(label=_(u'Twitter'), required=False) - facebook = forms.URLField(label=_(u'Facebook'), required=False) - google_talk = forms.EmailField(label=_(u'Google Talk'), required=False) - webpage = forms.URLField(label=_(u'Personal Website/Blog'), required=False) + first_name = forms.CharField(max_length=30, label=_(u'Name'), + widget=forms.TextInput(attrs={'class':'form-control'})) + last_name = forms.CharField(max_length=30, label=_(u'Last name'), + widget=forms.TextInput(attrs={'class':'form-control'})) + email = forms.EmailField(validators=[UniqueValidator(User, 'email')], + widget=forms.TextInput(attrs={'class':'form-control'})) lists = forms.MultipleChoiceField(label=u'Listas', required=False, widget=forms.CheckboxSelectMultiple, @@ -39,6 +35,19 @@ class UserCreationForm(UserCreationForm_): class UserUpdateForm(UserCreationForm): + institution= forms.CharField(max_length=120, label=_(u'Institution'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + role = forms.CharField(max_length=60, label=_(u'Role'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + twitter = forms.URLField(label=_(u'Twitter'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + facebook = forms.URLField(label=_(u'Facebook'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + google_talk = forms.EmailField(label=_(u'Google Talk'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + webpage = forms.URLField(label=_(u'Personal Website/Blog'), required=False, + widget=forms.TextInput(attrs={'class':'form-control'})) + def __init__(self, *args, **kwargs): super(UserUpdateForm, self).__init__(*args, **kwargs) self.fields.pop('username') diff --git a/src/accounts/templates/accounts/signup-form.html b/src/accounts/templates/accounts/signup-form.html index 7fe5b97..72ffae1 100644 --- a/src/accounts/templates/accounts/signup-form.html +++ b/src/accounts/templates/accounts/signup-form.html @@ -5,22 +5,20 @@

{% trans "Sign up" %}

-{% if form.errors %} -
- {% trans "Please correct the errors below and try again." %} -
-{% endif %} -
-
- -
- user -
-

- {% trans "Add an avatar to your account using" %} Gravatar -

+ {% if form.errors %} +
+ {% trans "Please correct the errors below and try again" %}
+ {% endif %} + +
+ {% for field in form %} + {% if field.errors %} + {{ field.label }} + {% endif %} + {% endfor %} +
@@ -28,46 +26,51 @@

-
+ {% csrf_token %}
-
-
- {% trans "Personal Information" %} - {% render_form_field form.first_name %} - {% render_form_field form.last_name %} - {% render_form_field form.email %} - {% render_form_field form.username %} -
- -
- {% trans "Others" %} - {% render_form_field form.twitter %} - {% render_form_field form.facebook %} - {% render_form_field form.google_talk %} - {% render_form_field form.webpage %} -
-
-
-
- {% trans "Professionals Information" %} - {% render_form_field form.institution %} - {% render_form_field form.role %} -
+
+ {% for legend, fields in fieldsets %} +
+
+
+ {{ legend }} + {% for field in fields %} +
+ + {% if field.name == 'username' %} + + {% elif field.name == 'lists' %} + {% for choice in field %} +
+ {{ choice }} +
+ {% endfor %} + {% else %} + {{ field }} + {% endif %} + {{ field.errors }} +
-
- {% trans "Subscribe to mail lists" %} -
- {% render_form_field form.lists %} + {% endfor %} +
- +
+ {% endfor %} +
+
-
- +
+
+
+ + {% endblock %} diff --git a/src/accounts/views.py b/src/accounts/views.py index ec35315..8631a77 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -12,20 +12,39 @@ from django.shortcuts import render, get_object_or_404 from .forms import UserCreationForm from super_archives.models import UserProfile, EmailAddress +# helper +def get_field_set(form): + fieldsets = ( + (_('Personal Information'), ( + form['first_name'], + form['last_name'], + form['email'], + form['username'], + ) + ), + (_('Subscribe to mail lists'), ( + form['lists'], + ) + ), + ) + return fieldsets + def signup(request): # If the request method is GET just return the form if request.method == 'GET': form = UserCreationForm() - return render(request, 'accounts/signup-form.html', {'form': form}) + return render(request, 'accounts/signup-form.html', + {'form': form, 'fieldsets': get_field_set(form)}) # If the request method is POST try to store data form = UserCreationForm(request.POST) # If there is validation errors give the form back to the user if not form.is_valid(): - return render(request, 'accounts/signup-form.html', {'form': form}) + return render(request, 'accounts/signup-form.html', + {'form': form, 'fieldsets': get_field_set(form)}) user = User( username=form.cleaned_data.get('username'), diff --git a/src/colab/static/css/screen.css b/src/colab/static/css/screen.css index ce86bb2..b75f11c 100644 --- a/src/colab/static/css/screen.css +++ b/src/colab/static/css/screen.css @@ -86,41 +86,25 @@ max-width: 95% !important; } -/* Forms */ +/* Forms */ .required label:before { color: #f00; content: "* "; } -input[type="text"], -input[type="password"] { - width: 300px; - padding: 3px; -} -/* End Forms */ - -/* Changing Bootstrap*/ -fieldset>legend { - display:block; - font-weight:bold; - font-size:1.2em; - margin-top:-0.2em; - margin-bottom:0em; - border: none; +form.signup .form-group { + width: 90%; + margin-left: 0.5em; } -.well { - background:#e5eCf9 !important; +form.signup div.submit { + margin: auto; + margin-bottom: 5em; + width: 200px; } -.col-lg-6 .well{ - max-width:570px; -} +/* End Forms */ -.col-lg-3 .well { - max-width:285px; -} -/* End changes */ .rss-icon { background-image: url(../img/rss.png); -- libgit2 0.21.2