Commit fa8fd6ed0e1ccf4cfb45c6b33e3f5548b94ca9c8

Authored by Sergio Oliveira
1 parent 1b800ac2

Reading username to use in url

src/accounts/forms.py 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  1 +# -*- coding: utf-8 -*-
  2 +
  3 +from django import forms
  4 +from django.core.exceptions import ValidationError
  5 +from django.contrib.auth.models import User
  6 +from django.contrib.auth.forms import UserCreationForm as UserCreationForm_
  7 +from django.utils.translation import ugettext_lazy as _
  8 +
  9 +from super_archives.models import MailingList
  10 +from super_archives.validators import UniqueValidator
  11 +
  12 +
  13 +LISTS_NAMES = []
  14 +for list_ in MailingList.objects.iterator():
  15 + choice = (list_.name, list_.name)
  16 + LISTS_NAMES.append(choice)
  17 +
  18 +
  19 +class UserCreationForm(UserCreationForm_):
  20 + first_name = forms.CharField(max_length=30, label=_(u'Name'))
  21 + last_name = forms.CharField(max_length=30, label=_(u'Last name'))
  22 + email = forms.EmailField(validators=[UniqueValidator(User, 'email')])
  23 + institution= forms.CharField(max_length=120, label=_(u'Institution'), required=False)
  24 + role = forms.CharField(max_length=60, label=_(u'Role'), required=False)
  25 + twitter = forms.URLField(label=_(u'Twitter'), required=False)
  26 + facebook = forms.URLField(label=_(u'Facebook'), required=False)
  27 + google_talk = forms.EmailField(label=_(u'Google Talk'), required=False)
  28 + webpage = forms.URLField(label=_(u'Personal Website/Blog'), required=False)
  29 + lists = forms.MultipleChoiceField(label=u'Listas',
  30 + required=False,
  31 + widget=forms.CheckboxSelectMultiple,
  32 + choices=LISTS_NAMES)
  33 +
  34 +
  35 + def __init__(self, *args, **kwargs):
  36 + super(UserCreationForm, self).__init__(*args, **kwargs)
  37 + self.fields.pop('password1')
  38 + self.fields.pop('password2')
  39 +
  40 +
  41 +class UserUpdateForm(UserCreationForm):
  42 + def __init__(self, *args, **kwargs):
  43 + super(UserUpdateForm, self).__init__(*args, **kwargs)
  44 + self.fields.pop('username')
  45 + self.fields.pop('first_name')
  46 + self.fields.pop('last_name')
  47 + self.fields.pop('email')
  48 + self.fields.pop('lists')
src/accounts/templates/accounts/signup-form.html
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 {% render_form_field form.first_name %} 32 {% render_form_field form.first_name %}
33 {% render_form_field form.last_name %} 33 {% render_form_field form.last_name %}
34 {% render_form_field form.email %} 34 {% render_form_field form.email %}
  35 + {% render_form_field form.username %}
35 </fieldset> 36 </fieldset>
36 37
37 <fieldset class="box last"> 38 <fieldset class="box last">
src/accounts/views.py
@@ -9,7 +9,7 @@ from django.contrib.auth.models import User @@ -9,7 +9,7 @@ from django.contrib.auth.models import User
9 from django.utils.translation import ugettext as _ 9 from django.utils.translation import ugettext as _
10 from django.shortcuts import render, get_object_or_404 10 from django.shortcuts import render, get_object_or_404
11 11
12 -from super_archives.forms import UserCreationForm 12 +from .forms import UserCreationForm
13 from super_archives.models import UserProfile, EmailAddress 13 from super_archives.models import UserProfile, EmailAddress
14 14
15 15
src/colab/deprecated/signup.py
@@ -19,34 +19,14 @@ def send_verification_email(request, user): @@ -19,34 +19,14 @@ def send_verification_email(request, user):
19 'server_name': request.get_host(), 19 'server_name': request.get_host(),
20 } 20 }
21 21
22 - html_content = render_to_string('email_signup-email-confirmation.html',  
23 - email_data) 22 + html_content = render_to_string('accounts/email_signup-email-confirmation.html',
  23 + email_data)
24 text_content = strip_tags(html_content) 24 text_content = strip_tags(html_content)
25 email_msg = EmailMultiAlternatives(subject, text_content, from_, [to]) 25 email_msg = EmailMultiAlternatives(subject, text_content, from_, [to])
26 email_msg.attach_alternative(html_content, 'text/html') 26 email_msg.attach_alternative(html_content, 'text/html')
27 email_msg.send() 27 email_msg.send()
28 28
29 29
30 -def send_reset_password_email(request, user):  
31 -  
32 - subject = _(u'Password change of Colab Interlegis')  
33 - from_ = settings.SERVER_EMAIL  
34 - to = user.email  
35 -  
36 - email_data = {  
37 - 'hash': user.profile.verification_hash,  
38 - 'server_name': request.get_host(),  
39 - 'username': user.username,  
40 - }  
41 -  
42 - html_content = render_to_string('email_account-reset-password.html',  
43 - email_data)  
44 - text_content = strip_tags(html_content)  
45 -  
46 - email_msg = EmailMultiAlternatives(subject, text_content, from_, [to])  
47 - email_msg.attach_alternative(html_content, 'text/html')  
48 - email_msg.send()  
49 -  
50 def send_email_lists(user, mailing_lists): 30 def send_email_lists(user, mailing_lists):
51 subject = _(u'Registration on the mailing list') 31 subject = _(u'Registration on the mailing list')
52 from_ = user.email 32 from_ = user.email
src/colab/deprecated/views/userprofile.py
@@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required @@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required
13 from django.shortcuts import render, get_object_or_404, redirect 13 from django.shortcuts import render, get_object_or_404, redirect
14 14
15 from colab.deprecated import solrutils 15 from colab.deprecated import solrutils
16 -from super_archives.forms import UserCreationForm, UserUpdateForm 16 +from accounts.forms import UserCreationForm, UserUpdateForm
17 from super_archives.models import Message, UserProfile, EmailAddress 17 from super_archives.models import Message, UserProfile, EmailAddress
18 18
19 19
src/super_archives/forms.py
@@ -1,63 +0,0 @@ @@ -1,63 +0,0 @@
1 -# -*- coding: utf-8 -*-  
2 -  
3 -from django import forms  
4 -from django.core.exceptions import ValidationError  
5 -from django.contrib.auth.models import User  
6 -from django.contrib.auth.forms import UserCreationForm as UserCreationForm_  
7 -from django.utils.translation import ugettext_lazy as _  
8 -  
9 -from .models import MailingList  
10 -from .validators import UniqueValidator  
11 -  
12 -# XXX: I know that this code does not look nice AT ALL.  
13 -# probably it should be implemented using formsets instead of  
14 -# the hack below. Feel free to improve it! :)  
15 -  
16 -# User fields  
17 -first_name_field = forms.CharField(max_length=30, label=_(u'Name'))  
18 -last_name_field = forms.CharField(max_length=30, label=_(u'Last name'))  
19 -email_field = forms.EmailField(validators=[UniqueValidator(User, 'email')])  
20 -  
21 -# UserProfile fields  
22 -institution_field = forms.CharField(max_length=120, label=_(u'Institution'),  
23 - required=False)  
24 -role_field = forms.CharField(max_length=60, label=_(u'Role'), required=False)  
25 -twitter_field = forms.URLField(label=_(u'Twitter'), required=False)  
26 -facebook_field = forms.URLField(label=_(u'Facebook'), required=False)  
27 -google_talk_field = forms.EmailField(label=_(u'Google Talk'), required=False)  
28 -webpage_field = forms.URLField(label=_(u'Personal Website/Blog'), required=False)  
29 -  
30 -all_lists = MailingList.objects.all()  
31 -lists_names = []  
32 -for list_ in all_lists:  
33 - choice = (list_.name, list_.name)  
34 - lists_names.append(choice)  
35 -  
36 -lists_field = forms.MultipleChoiceField(  
37 - label=u'Listas',  
38 - required=False,  
39 - widget=forms.CheckboxSelectMultiple,  
40 - choices=lists_names  
41 -)  
42 -  
43 -  
44 -class UserCreationForm(UserCreationForm_):  
45 - first_name = first_name_field  
46 - last_name = last_name_field  
47 - email = email_field  
48 - institution = institution_field  
49 - role = role_field  
50 - twitter = twitter_field  
51 - facebook = facebook_field  
52 - google_talk = google_talk_field  
53 - webpage = webpage_field  
54 - lists = lists_field  
55 -  
56 -  
57 -class UserUpdateForm(forms.Form):  
58 - institution = institution_field  
59 - role = role_field  
60 - twitter = twitter_field  
61 - facebook = facebook_field  
62 - google_talk = google_talk_field  
63 - webpage = webpage_field  
src/super_archives/models.py
@@ -66,7 +66,7 @@ class UserProfile(models.Model): @@ -66,7 +66,7 @@ class UserProfile(models.Model):
66 verbose_name_plural = _(u"Users Profiles") 66 verbose_name_plural = _(u"Users Profiles")
67 67
68 def __unicode__(self): 68 def __unicode__(self):
69 - return '"%s" <%s>' % (self.get_full_name(), self.email) 69 + return '"%s" <%s>' % (self.user.get_full_name(), self.user.email)
70 70
71 # This does the same the same than related_name argument but it also creates 71 # This does the same the same than related_name argument but it also creates
72 # a profile in the case it doesn't exist yet. 72 # a profile in the case it doesn't exist yet.