Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:Stunning/Django-facebook

  • Loading branch information...
commit cd27ad8a376241587fde30d9918414fe12e7dc5a 2 parents 0b63896 + 928dbd2
Per Rosengren per42 authored
2  django_facebook/__init__.py
@@ -4,7 +4,7 @@
4 4
5 5
6 6 __license__ = 'BSD'
7   -__version__ = '3.5.2'
  7 +__version__ = '3.5.4'
8 8 __maintainer__ = 'Thierry Schellenbach'
9 9 __email__ = 'thierryschellenbach@gmail.com'
10 10 __status__ = 'Production'
15 django_facebook/connect.py
@@ -98,11 +98,14 @@ def connect_user(request, access_token=None, facebook_graph=None):
98 98 #store the access token for later usage if the profile model supports it
99 99 if hasattr(profile, 'access_token'):
100 100 # only update the access token if it is long lived and
101   - # not equal to the current token
102   - if not graph.expires and graph.access_token != profile.access_token:
103   - # TODO, maybe we should just always do this.
104   - profile.access_token = graph.access_token
105   - profile.save()
  101 + if graph.expires:
  102 + logger.warn('we shouldnt be finding a graph expiration, its set to %s', graph.expires)
  103 + #TODO: maybe we should still save these
  104 + else:
  105 + # and not equal to the current token
  106 + if graph.access_token != profile.access_token:
  107 + profile.access_token = graph.access_token
  108 + profile.save()
106 109
107 110 return action, user
108 111
@@ -222,7 +225,7 @@ def _update_user(user, facebook):
222 225 # profile thats fine
223 226 # partial support (everything except raw_data and facebook_id is included)
224 227 facebook_data = facebook.facebook_registration_data(username=False)
225   - facebook_fields = ['facebook_name', 'facebook_profile_url',
  228 + facebook_fields = ['facebook_name', 'facebook_profile_url', 'gender',
226 229 'date_of_birth', 'about_me', 'website_url', 'first_name', 'last_name']
227 230 user_dirty = profile_dirty = False
228 231 profile = user.get_profile()
1  django_facebook/models.py
@@ -19,6 +19,7 @@ class FacebookProfileModel(models.Model):
19 19 image = models.ImageField(blank=True, null=True,
20 20 upload_to='profile_images', max_length=255)
21 21 date_of_birth = models.DateField(blank=True, null=True)
  22 + gender = models.CharField(max_length=1, choices=(('m', 'Male'), ('f', 'Female')), blank=True, null=True)
22 23 raw_data = models.TextField(blank=True)
23 24
24 25 def __unicode__(self):
14 django_facebook/tests.py
@@ -41,6 +41,20 @@ def test_persistent_graph(self):
41 41 request.session = {}
42 42 request.user = AnonymousUser()
43 43 get_persistent_graph(request, access_token='short_username')
  44 +
  45 + def test_gender_matching(self):
  46 + from django.test import RequestFactory
  47 + request = RequestFactory()
  48 + request.session = {}
  49 + request.user = AnonymousUser()
  50 + graph = get_persistent_graph(request, access_token='paul')
  51 + converter = FacebookUserConverter(graph)
  52 + base_data = converter.facebook_profile_data()
  53 + self.assertEqual(base_data['gender'], 'male')
  54 + data = converter.facebook_registration_data()
  55 + self.assertEqual(data['gender'], 'm')
  56 + action, user = connect_user(self.request, facebook_graph=graph)
  57 + self.assertEqual(user.get_profile().gender, 'm')
44 58
45 59 def test_full_connect(self):
46 60 #going for a register, connect and login
1  django_facebook/tests_utils/sample_data/user_data.py
@@ -16,6 +16,7 @@
16 16 user_data['same_username'] = user_data['short_username'].copy()
17 17 user_data['same_username'].update(dict(id='1111111', email='t@fake.com'))
18 18
  19 +user_data['paul'] = {"website": "http://usabilla.com", "last_name": "Veugen", "locale": "en_US", "image": "https://graph.facebook.com/me/picture?access_token=aa&type=large", "quotes": "\"Make no small plans for they have no power to stir the soul.\" - Machiavelli", "timezone": 1, "education": [{"school": {"id": "114174235260224", "name": "Tilburg University"}, "type": "College", "year": {"id": "136328419721520", "name": "2009"}}, {"school": {"id": "111600322189438", "name": "Tilburg University"}, "type": "Graduate School", "concentration": [{"id": "187998924566551", "name": "Business Communication and Digital Media"}, {"id": "105587479474873", "name": "Entrepreneurship"}], "degree": {"id": "110198449002528", "name": "BA"}}], "id": "555227728", "first_name": "Paul", "verified": True, "sports": [{"id": "114031331940797", "name": "Cycling"}, {"id": "107496599279538", "name": "Snowboarding"}, {"id": "109368782422374", "name": "Running"}], "languages": [{"id": "106059522759137", "name": "English"}, {"id": "107672419256005", "name": "Dutch"}], "location": {"id": "111777152182368", "name": "Amsterdam, Netherlands"}, "image_thumb": "https://graph.facebook.com/me/picture?access_token=aa", "email": "paulv@email.com", "username": "pveugen", "bio": "Founder Usabilla. User Experience designer, entrepeneur and digital media addict. On a mission to make user experience research simple and fun with Usabilla.com.", "birthday": "07/11/1984", "link": "http://www.facebook.com/pveugen", "name": "Paul Veugen", "gender": "male", "work": [{"description": "http://usabilla.com", "employer": {"id": "235754672838", "name": "Usabilla"}, "location": {"id": "111777152182368", "name": "Amsterdam, Netherlands"}, "position": {"id": "130899310279007", "name": "Founder, CEO"}, "with": [{"id": "1349358449", "name": "Marc van Agteren"}], "start_date": "2009-01"}, {"position": {"id": "143357809027330", "name": "Communication Designer"}, "start_date": "2000-02", "location": {"id": "112258135452858", "name": "Venray"}, "end_date": "2010-01", "employer": {"id": "133305113393672", "name": "Flyers Internet Communicatie"}}], "updated_time": "2011-11-27T14:34:34+0000"}
19 20
20 21 user_data['unicode_string'] = {u'bio': u'ATELIER : TODOS LOS DIAS DE 14 A 22 HS C CITA PREVIA. MIX DE ESTETICAS - ECLECTICA - PRENDAS UNICAS-HAND MADE- SEASSON LESS RETROMODERNIDAD -CUSTOMIZADO !!!\r\n\r\nMe encanta todo el proceso que lleva lograr un objeto que sea unico....personalizarlo de acuerdo a cada uno...a cada persona....a su forma de ser.......elegir los materiales, los avios, las telas...siendo la premisa DIFERENCIARSE!!!!\r\n Atemporal..Retro modernidad...Eclecticismo!!!',
21 22 u'birthday': u'04/09/1973',

0 comments on commit cd27ad8

Please sign in to comment.
Something went wrong with that request. Please try again.