Merge lp:~mboehn/lancms/lc2-profile into lp:lancms

Proposed by Mathias Bøhn Grytemark
Status: Merged
Approved by: Mathias Bøhn Grytemark
Approved revision: no longer in the source branch.
Merged at revision: 26
Proposed branch: lp:~mboehn/lancms/lc2-profile
Merge into: lp:lancms
Diff against target: 124 lines (+70/-3)
5 files modified
core/common.py (+3/-1)
core/models.py (+36/-1)
lancms2/settings.py (+2/-1)
requirements.txt (+1/-0)
templates/account/profile.html (+28/-0)
To merge this branch: bzr merge lp:~mboehn/lancms/lc2-profile
Reviewer Review Type Date Requested Status
Mathias Bøhn Grytemark Approve
Review via email: mp+201097@code.launchpad.net

Description of the change

* Adds a UserProfile (OneToOne with User).
* Populates date of birth and/or gender from Facebook if it is available.

To post a comment you must log in.
Revision history for this message
Mathias Bøhn Grytemark (mboehn) wrote :

self-approved :-)

review: Approve
lp:~mboehn/lancms/lc2-profile updated
26. By Mathias Bøhn Grytemark <email address hidden>

merged lc2-profile

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core/common.py'
2--- core/common.py 2014-01-07 21:23:42 +0000
3+++ core/common.py 2014-01-09 20:36:49 +0000
4@@ -2,4 +2,6 @@
5 from django.template import RequestContext
6
7 def prtr (template, dict, request):
8- return render_to_response (template, dict, context_instance=RequestContext(request))
9+ return render_to_response (template, dict, context_instance=RequestContext(request))
10+
11+
12
13=== modified file 'core/models.py'
14--- core/models.py 2014-01-07 21:23:42 +0000
15+++ core/models.py 2014-01-09 20:36:49 +0000
16@@ -1,3 +1,38 @@
17+### Models
18 from django.db import models
19
20-# Create your models here.
21+
22+from django.contrib.auth.models import User
23+from django_countries import CountryField
24+
25+
26+CHOICES_GENDER = (
27+ ('female', 'Female'),
28+ ('male', 'Male'),
29+ )
30+
31+
32+class UserProfile(models.Model):
33+ user = models.OneToOneField (User)
34+ date_of_birth = models.DateField (null=True)
35+ streetaddress = models.CharField (max_length=255, null=True)
36+ country = CountryField (null=True)
37+ postalcode = models.IntegerField (null=True)
38+ gender = models.CharField (max_length=6, choices=CHOICES_GENDER, null=True)
39+
40+
41+
42+
43+### Signals
44+
45+from django.dispatch import receiver
46+from allauth.account.signals import user_signed_up
47+import datetime
48+@receiver(user_signed_up)
49+def populate_user_profile (request, user, sociallogin=None, **kwargs):
50+ if sociallogin:
51+ if sociallogin.account.provider == 'facebook':
52+ up = UserProfile(user=user)
53+ up.gender = sociallogin.account.extra_data['gender']
54+ up.date_of_birth = datetime.datetime.strptime (sociallogin.account.extra_data['birthday'], "%m/%d/%Y")
55+ up.save()
56
57=== modified file 'lancms2/settings.py'
58--- lancms2/settings.py 2014-01-08 12:03:17 +0000
59+++ lancms2/settings.py 2014-01-09 20:36:49 +0000
60@@ -43,6 +43,7 @@
61 'allauth.socialaccount.providers.facebook',
62 'core',
63 'debug_toolbar', # for DEBUG
64+ 'django_countries',
65 )
66
67 MIDDLEWARE_CLASSES = (
68@@ -116,7 +117,7 @@
69 'allauth.account.auth_backends.AuthenticationBackend',
70 )
71
72-SOCIALACCOUNT_PROVIDERS = { 'facebook': { 'SCOPE': ['email'], 'AUTH_PARAMS': { 'auth_type': 'reauthenticate' }, 'METHOD': 'oauth2', 'LOCALE_FUNC': lambda request: 'en_GB' } }
73+SOCIALACCOUNT_PROVIDERS = { 'facebook': { 'SCOPE': ['email', 'user_birthday'], 'AUTH_PARAMS': { 'auth_type': 'reauthenticate' }, 'METHOD': 'oauth2', 'LOCALE_FUNC': lambda request: 'en_GB' } }
74
75 ##### end allauth
76
77
78=== modified file 'requirements.txt'
79--- requirements.txt 2014-01-08 12:03:17 +0000
80+++ requirements.txt 2014-01-09 20:36:49 +0000
81@@ -1,3 +1,4 @@
82 Django==1.6.1
83 django_allauth
84 django-debug-toolbar
85+django-countries
86
87=== modified file 'templates/account/profile.html'
88--- templates/account/profile.html 2014-01-08 17:02:40 +0000
89+++ templates/account/profile.html 2014-01-09 20:36:49 +0000
90@@ -38,6 +38,34 @@
91 {{user.email}}
92 </td>
93 </tr>
94+ {% if user.userprofile.date_of_birth %}
95+ <tr>
96+ <th>
97+ Gender
98+ </th>
99+ <td>
100+ {{user.userprofile.date_of_birth}}
101+ </td>
102+ </tr>
103+ {% endif %}
104+ {% if user.userprofile.gender %}
105+ <tr>
106+ <th>
107+ Gender
108+ </th>
109+ <td>
110+ <i class="fa fa-{{user.userprofile.gender}}"></i> {{user.userprofile.get_gender_display}}
111+ </td>
112+ </tr>
113+ {% endif %}
114+ <tr>
115+ <th>
116+ Registered
117+ </th>
118+ <td>
119+ {{user.date_joined}}
120+ </td>
121+ </tr>
122 {% if user.is_staff or user.is_superuser %}
123 <tr>
124 <th>

Subscribers

People subscribed via source and target branches