From fa8fd6ed0e1ccf4cfb45c6b33e3f5548b94ca9c8 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Fri, 9 Aug 2013 19:26:59 -0300 Subject: [PATCH] Reading username to use in url --- src/accounts/forms.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/accounts/templates/accounts/signup-form.html | 1 + src/accounts/views.py | 2 +- src/colab/deprecated/signup.py | 24 ++---------------------- src/colab/deprecated/views/userprofile.py | 2 +- src/super_archives/forms.py | 63 --------------------------------------------------------------- src/super_archives/models.py | 2 +- 7 files changed, 54 insertions(+), 88 deletions(-) create mode 100644 src/accounts/forms.py delete mode 100644 src/super_archives/forms.py diff --git a/src/accounts/forms.py b/src/accounts/forms.py new file mode 100644 index 0000000..cafc5ec --- /dev/null +++ b/src/accounts/forms.py @@ -0,0 +1,48 @@ +# -*- 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 _ + +from super_archives.models import MailingList +from super_archives.validators import UniqueValidator + + +LISTS_NAMES = [] +for list_ in MailingList.objects.iterator(): + choice = (list_.name, list_.name) + LISTS_NAMES.append(choice) + + +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) + lists = forms.MultipleChoiceField(label=u'Listas', + required=False, + widget=forms.CheckboxSelectMultiple, + choices=LISTS_NAMES) + + + def __init__(self, *args, **kwargs): + super(UserCreationForm, self).__init__(*args, **kwargs) + self.fields.pop('password1') + self.fields.pop('password2') + + +class UserUpdateForm(UserCreationForm): + def __init__(self, *args, **kwargs): + super(UserUpdateForm, self).__init__(*args, **kwargs) + self.fields.pop('username') + self.fields.pop('first_name') + self.fields.pop('last_name') + self.fields.pop('email') + self.fields.pop('lists') diff --git a/src/accounts/templates/accounts/signup-form.html b/src/accounts/templates/accounts/signup-form.html index e0d7c34..8635a5c 100644 --- a/src/accounts/templates/accounts/signup-form.html +++ b/src/accounts/templates/accounts/signup-form.html @@ -32,6 +32,7 @@ {% render_form_field form.first_name %} {% render_form_field form.last_name %} {% render_form_field form.email %} + {% render_form_field form.username %}
diff --git a/src/accounts/views.py b/src/accounts/views.py index 43ead34..ec35315 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -9,7 +9,7 @@ from django.contrib.auth.models import User from django.utils.translation import ugettext as _ from django.shortcuts import render, get_object_or_404 -from super_archives.forms import UserCreationForm +from .forms import UserCreationForm from super_archives.models import UserProfile, EmailAddress diff --git a/src/colab/deprecated/signup.py b/src/colab/deprecated/signup.py index a9fc08e..e670cdd 100644 --- a/src/colab/deprecated/signup.py +++ b/src/colab/deprecated/signup.py @@ -19,34 +19,14 @@ def send_verification_email(request, user): 'server_name': request.get_host(), } - html_content = render_to_string('email_signup-email-confirmation.html', - email_data) + html_content = render_to_string('accounts/email_signup-email-confirmation.html', + email_data) text_content = strip_tags(html_content) email_msg = EmailMultiAlternatives(subject, text_content, from_, [to]) email_msg.attach_alternative(html_content, 'text/html') email_msg.send() -def send_reset_password_email(request, user): - - subject = _(u'Password change of Colab Interlegis') - from_ = settings.SERVER_EMAIL - to = user.email - - email_data = { - 'hash': user.profile.verification_hash, - 'server_name': request.get_host(), - 'username': user.username, - } - - html_content = render_to_string('email_account-reset-password.html', - email_data) - text_content = strip_tags(html_content) - - email_msg = EmailMultiAlternatives(subject, text_content, from_, [to]) - email_msg.attach_alternative(html_content, 'text/html') - email_msg.send() - def send_email_lists(user, mailing_lists): subject = _(u'Registration on the mailing list') from_ = user.email diff --git a/src/colab/deprecated/views/userprofile.py b/src/colab/deprecated/views/userprofile.py index 59e65b2..78ef743 100644 --- a/src/colab/deprecated/views/userprofile.py +++ b/src/colab/deprecated/views/userprofile.py @@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import render, get_object_or_404, redirect from colab.deprecated import solrutils -from super_archives.forms import UserCreationForm, UserUpdateForm +from accounts.forms import UserCreationForm, UserUpdateForm from super_archives.models import Message, UserProfile, EmailAddress diff --git a/src/super_archives/forms.py b/src/super_archives/forms.py deleted file mode 100644 index 2540672..0000000 --- a/src/super_archives/forms.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- 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 _ - -from .models import MailingList -from .validators import UniqueValidator - -# XXX: I know that this code does not look nice AT ALL. -# probably it should be implemented using formsets instead of -# the hack below. Feel free to improve it! :) - -# User fields -first_name_field = forms.CharField(max_length=30, label=_(u'Name')) -last_name_field = forms.CharField(max_length=30, label=_(u'Last name')) -email_field = forms.EmailField(validators=[UniqueValidator(User, 'email')]) - -# UserProfile fields -institution_field = forms.CharField(max_length=120, label=_(u'Institution'), - required=False) -role_field = forms.CharField(max_length=60, label=_(u'Role'), required=False) -twitter_field = forms.URLField(label=_(u'Twitter'), required=False) -facebook_field = forms.URLField(label=_(u'Facebook'), required=False) -google_talk_field = forms.EmailField(label=_(u'Google Talk'), required=False) -webpage_field = forms.URLField(label=_(u'Personal Website/Blog'), required=False) - -all_lists = MailingList.objects.all() -lists_names = [] -for list_ in all_lists: - choice = (list_.name, list_.name) - lists_names.append(choice) - -lists_field = forms.MultipleChoiceField( - label=u'Listas', - required=False, - widget=forms.CheckboxSelectMultiple, - choices=lists_names -) - - -class UserCreationForm(UserCreationForm_): - first_name = first_name_field - last_name = last_name_field - email = email_field - institution = institution_field - role = role_field - twitter = twitter_field - facebook = facebook_field - google_talk = google_talk_field - webpage = webpage_field - lists = lists_field - - -class UserUpdateForm(forms.Form): - institution = institution_field - role = role_field - twitter = twitter_field - facebook = facebook_field - google_talk = google_talk_field - webpage = webpage_field diff --git a/src/super_archives/models.py b/src/super_archives/models.py index d58afc6..fb4a9f0 100644 --- a/src/super_archives/models.py +++ b/src/super_archives/models.py @@ -66,7 +66,7 @@ class UserProfile(models.Model): verbose_name_plural = _(u"Users Profiles") def __unicode__(self): - return '"%s" <%s>' % (self.get_full_name(), self.email) + return '"%s" <%s>' % (self.user.get_full_name(), self.user.email) # This does the same the same than related_name argument but it also creates # a profile in the case it doesn't exist yet. -- libgit2 0.21.2