コード例 #1
0
 def get_by_slug_querier(self, slug, querier):
     '''
     Obtiene un evento por su id, COMPRUEBA VISIBILIDAD, solo obtiene los publicos
     '''
     suggestion = memcache.deserialize_instances(memcache.get(
         '%sEVENT%s' % (memcache.version, slug)),
                                                 _search_class=self._klass)
     if suggestion is None:
         suggestion = self._klass.all().filter('slug =', slug).get()
         if suggestion is None:
             try:
                 suggestion = self.get_by_id(slug)
             except:
                 return None
         if suggestion is not None:
             if suggestion._is_private():
                 if not querier.is_authenticated():
                     return None
                 if suggestion.__class__.user.get_value_for_datastore(
                         suggestion) == querier.key():
                     return None
             elif suggestion._is_shared():
                 if not querier.is_authenticated():
                     return None
                 if not suggestion.user_invited(querier):
                     return None
             memcache.set('%sEVENT%s' % (memcache.version, slug),
                          memcache.serialize_instances(suggestion), 300)
             return suggestion
     return suggestion
コード例 #2
0
 def get_by_id(self, id):
     import memcache
     try:
         id = long(id)
     except:
         return None
     place = memcache.deserialize_instances(memcache.get('%splace_%s' % (memcache.version, id)), _search_class=Place)
     if place is None:
         place = self._klass.get_by_id(id)
         if place is None:
             return None
         memcache.set('%splace_%s' % (memcache.version, id), memcache.serialize_instances(place), 300)
     return place
コード例 #3
0
 def get_by_id(self, id):
     import memcache
     try:
         id = long(id)
     except:
         return None
     place = memcache.deserialize_instances(memcache.get(
         '%splace_%s' % (memcache.version, id)),
                                            _search_class=Place)
     if place is None:
         place = self._klass.get_by_id(id)
         if place is None:
             return None
         memcache.set('%splace_%s' % (memcache.version, id),
                      memcache.serialize_instances(place), 300)
     return place
コード例 #4
0
 def __init__(self, access_token=None, user=None):
     if user is None and access_token is None:
         raise AttributeError
     import memcache
     memclient = memcache.mem.Client()
     if user is not None:
         self.user = user
         token = memcache.deserialize_instances(memclient.get('%sfbclientuser_%s' % (memcache.version, 
                                                               user.id
                                                               )
                                            ))
         if token is None:
             token = OAUTH_Access.get_token_user(provider='facebook', user=user)
             if token is None:
                 raise OAUTHException()
             memclient.set('%sfbclientuser_%s' % (memcache.version, 
                                                               user.id
                                                               ),
                            memcache.serialize_instances(token)
                                            )
     else:
         token = memclient.get('%sfbclienttoken_%s' % (memcache.version, 
                                                               access_token
                                                               )
                                            )
         if token is None:
             token = OAUTH_Access.get_token(access_token)  # TODO: buscar por proveedor
             if token is not None:
                 self.user = token.user
                 token_cache = {'token': token,
                                'user': token.user
                                }
                 memclient.set('%sfbclienttoken_%s' % (memcache.version, 
                                                       access_token
                                               ), token_cache)
             else:
                 self.consumer = GraphAPI(access_token=access_token)
                 return
         else:
             self.user = token['user']
             token = token['token']
     self.consumer = GraphAPI(access_token=token.token_key)
コード例 #5
0
 def get_by_id(self, id):
     '''
     Obtiene un evento por su id, COMPRUEBA VISIBILIDAD, solo obtiene los publicos
     '''
     try:
         id = int(id)
     except:
         raise TypeError
     event = memcache.deserialize_instances(memcache.get(
         '%sEVENT%s' % (memcache.version, id)),
                                            _search_class=self._klass)
     if event is None:
         event = self._klass.get_by_id(int(id))
         if not hasattr(event, '_vis'):
             return None
         if not event._is_public():
             return None
         memcache.set('%sEVENT%s' % (memcache.version, id),
                      memcache.serialize_instances(event), 300)
     return event
コード例 #6
0
 def __init__(self, access_token=None, user=None):
     if user is None and access_token is None:
         raise AttributeError
     import memcache
     memclient = memcache.mem.Client()
     if user is not None:
         self.user = user
         token = memcache.deserialize_instances(
             memclient.get('%sfbclientuser_%s' %
                           (memcache.version, user.id)))
         if token is None:
             token = OAUTH_Access.get_token_user(provider='facebook',
                                                 user=user)
             if token is None:
                 raise OAUTHException()
             memclient.set(
                 '%sfbclientuser_%s' % (memcache.version, user.id),
                 memcache.serialize_instances(token))
     else:
         token = memclient.get('%sfbclienttoken_%s' %
                               (memcache.version, access_token))
         if token is None:
             token = OAUTH_Access.get_token(
                 access_token)  # TODO: buscar por proveedor
             if token is not None:
                 self.user = token.user
                 token_cache = {'token': token, 'user': token.user}
                 memclient.set(
                     '%sfbclienttoken_%s' %
                     (memcache.version, access_token), token_cache)
             else:
                 self.consumer = GraphAPI(access_token=access_token)
                 return
         else:
             self.user = token['user']
             token = token['token']
     self.consumer = GraphAPI(access_token=token.token_key)