예제 #1
0
def twitterBaseView(request):
    context = {
        'user': request.user,
        "navigator": [
            ("Twitter", "/twitter"),
        ]
    }
    log(context)
    resetUserSelection(request)
    return render(request, 'Twitter/TwitterBase.html', context)
 def createAndSetInstance(self, strType):
     if self.getInstance(): return  # Object instance already set
     d = {
         "user": ("fbUser", "U", FBUser),
         "page": ("fbPage", "P", FBPage),
         "group": ("fbGroup", "G", FBGroup),
         "event": ("fbEvent", "E", FBEvent),
         "application": ("fbApplication", "A", FBApplication),
         "video": ("fbVideo", "V", FBVideo),
         "photo": ("fbPhoto", "H", FBPhoto),
     }
     if strType not in d.keys():
         log('profile type "%s" is not recognised' % strType)
         return
     attr, type, model = d[strType]
     setattr(self, attr, model.objects.create(_ident=self._ident))
     self.type = type
 def copyBasicFields(self, jObject):
     for attr in self.basicFields:
         if self.basicFields[attr][0] in jObject:
             val = jObject[self.basicFields[attr][0]]
             for key in self.basicFields[attr][1:]:
                 if key in val:
                     val = val[key]
                 else:
                     val = None
             if val:
                 field = self._meta.get_field(attr)
                 if field.max_length and field.max_length < len(
                         val) and field.max_length >= 30:
                     log("DATA TOO LONG TO FIT <%s> FIELD \"%s\" (value: %s)"
                         % (self, attr, val))
                     val = "DATA TOO LONG. CONTENT SKIPPED"
                 setattr(self, attr, val)
예제 #4
0
 def update(self, jObject):
     if 'description' in jObject:
         self.description = jObject['description']
     if 'media' in jObject and 'image' in jObject['media']:
         if 'url' in jObject['media']['image']:
             self.imageUrl = jObject['media']['image']['url']
         elif 'src' in jObject['media']['image']:
             self.imageUrl = jObject['media']['image']['src']
         else:
             log(jObject['media'])
     if 'target' in jObject:
         self.targetUrl = jObject['target']['url']
     if 'title' in jObject:
         self.title = jObject['title']
     if 'type' in jObject:
         self.type = jObject['type']
     self.save()
예제 #5
0
def fbCommentView(request, fbCommentId):
    log(fbCommentId)
    fbComment = FBComment.objects.filter(pk=fbCommentId).first()
    if not fbComment:
        fbComment = FBComment.objects.filter(_ident=fbCommentId).first()
    log(fbComment)
    if not fbComment:
        raise Http404()
    context = {
        'fbComment':
        fbComment,
        'user':
        request.user,
        "navigator":
        [("Facebook", "/facebook"),
         (fbComment.from_profile, fbComment.from_profile.getLink()),
         ("Commentaire facebook", "/facebook/post/%s" % fbComment.pk)],
    }
    resetUserSelection(request)
    return render_to_response('Facebook/FacebookComment.html', context)
 def extend(self):
     try:
         graph = facebook.GraphAPI(self._token)
         response = graph.extend_access_token(
             FACEBOOK_APP_PARAMS['app_id'],
             FACEBOOK_APP_PARAMS['app_secret'])
         pretty(response)
         if not 'access_token' in response:
             raise Exception("failed to extend access token: %s" % self)
         self._token = response['access_token']
         if 'expires_in' in response:
             self.expires = time.time() + int(response['expires_in'])
         else:
             self.expires = time.time() + 60 * 5
         self.save()
         log("%s expires in %s seconds" %
             (self, self.expires - time.time()))
     except Exception as e:
         logError("An error occured while extending the token!")
         self.userProfile.facebookApp_parameters_error = True
         self.userProfile.save()
         raise
 def migrateId(self, newId):
     newProfile = FBProfile.objects.filter(_ident=newId).first()
     currentInstance = self.getInstance()
     if newProfile:
         newInstance = newProfile.getInstance()
         if newInstance:
             log('migrating fbProfile:')
             log('   current: %s' % currentInstance)
             log('   to:      %s' % newInstance)
             if currentInstance:
                 if hasattr(currentInstance, "fowardConnections"):
                     currentInstance.fowardConnections(newInstance)
                 currentInstance.delete()
             self.findAndSetInstance()
     elif currentInstance:
         currentInstance._ident = newId
         currentInstance.save()
     self._ident = newId
     self.save()
 def setParentPage(self, jObject):
     if 'parent_page' in jObject:
         log('PARENT PAGE: %s' % jObject['parent_page'])