1. Dominik Ruf
  2. collective.externalportrait

Commits

Dominik Ruf  committed 79188bd

try to add facebookid based on rpx_identifier

  • Participants
  • Parent commits 2040a02
  • Branches default

Comments (0)

Files changed (2)

File collective/externalportrait/controlpanel.py

View file
 
 class IExternalPortraitSettings(Interface):
     form.widget(urls=TextLinesFieldWidget)
-    urls = schema.Tuple(
+    urls = schema.List(
         title=u"URL patterns",
         description=u"""A list of URL patterns where to find a portrait.
             You can add user specific strings to the URL like %(emailmd5hash)s, %(fullname)s or %(username)s.
             The first URL that returns successful (http code 200) will be used.""",
         value_type = schema.TextLine(),
-        missing_value = (),
-        default=(u"http://www.gravatar.com/avatar/%(emailmd5hash)s?s=200&d=mm",),
+        missing_value = [],
+        default=[u"http://www.gravatar.com/avatar/%(emailmd5hash)s?s=200&d=mm",],
         )
 
 

File collective/externalportrait/membership.py

View file
         self.url = absurl
     def absolute_url(self):
         return self.url
-                
+
 def myGetPersonalPortrait(self, id=None, verifyPermission=0):
     portrait = self._orig_getPersonalPortrait(id, verifyPermission)
     if portrait.id == 'defaultUser.png':
 
             for url in settings.urls:
                 url = url % memberinfo
-                response = urlopen(url)
-                if response.getcode() == 200:
-                    portrait = DummyImage(url)
-                    break
+                try:
+                    response = urlopen(url)
+                    if response.getcode() == 200:
+                        portrait = DummyImage(url)
+                        break
+                except:
+                    pass
     return portrait
 
 def myGetMemberInfo(self, memberId=None):
     if member is None:
         return None
 
-    memberinfo = { 'fullname'    : member.getProperty('fullname'),
-                   'description' : member.getProperty('description'),
-                   'location'    : member.getProperty('location'),
-                   'language'    : member.getProperty('language'),
-                   'home_page'   : member.getProperty('home_page'),
-                   'emailmd5hash': md5(str(member.getProperty('email', None))).hexdigest(),
-                   'username'    : member.getUserName(),
-                   'has_email'   : bool(member.getProperty('email')),
+    memberinfo = { 'fullname'       : member.getProperty('fullname', ''),
+                   'description'    : member.getProperty('description', ''),
+                   'location'       : member.getProperty('location', ''),
+                   'language'       : member.getProperty('language', ''),
+                   'home_page'      : member.getProperty('home_page', ''),
+                   'username'       : member.getUserName(),
+                   'has_email'      : bool(member.getProperty('email', None)),
+                   'emailmd5hash'   : md5(str(member.getProperty('email', ''))).hexdigest(),
+                   'facebookid'     : member.getProperty('facebookid', ''),
                  }
+    
+    rpx_identifier = member.getProperty('rpx_identifier', '')
+    for rpx_id in rpx_identifier:
+        if 'facebook.com' in rpx_id:
+            memberinfo['facebookid'] = rpx_id.rsplit('=', 1)[-1]
 
     return memberinfo