Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 4
0
 def authorize(self, user):
     """guarda el token de autorizacion"""
     if user is not None:#el usuario ya esta conectado, pero pide permisos
         token = OAUTH_Access.get_token(self.consumer.access_token)
         if token is None:
             OAUTH_Access.remove_token(user, 'facebook')
             token = OAUTH_Access.add_token(
                                             token_key=self.consumer.access_token,
                                             token_secret='',
                                             provider='facebook',
                                             user=user,
                                             )
         else:
             token.user = user
             token.put()
         self.consumer = GraphAPI(access_token=token.token_key)
         facebookInfo = self.get_user_info()
         if user.facebook_user is None:
             fbuser = FacebookUser.register(user=user, uid=facebookInfo['id'], 
                                            email=facebookInfo.get('email', None),
                                            realname=facebookInfo["name"],
                                            profile_url=facebookInfo["link"],
                                            access_token=self.consumer.access_token)
         else:
             user.facebook_user.update(
                          uid=facebookInfo['id'],
                          realname = facebookInfo['name'],
                          profile_url=facebookInfo["link"],
                         )
         self.user = user
         self.token  = token
         import memcache
         memclient = memcache.mem.Client()
         token_cache = {'token': token,
                        'user': self.user
                        }
         memclient.set('%sfbclienttoken_%s' % (memcache.version, 
                                               self.consumer.access_token
                                               ), 
                           token_cache)
         memclient.set('%sfbclientuser_%s' % (memcache.version, 
                                               user.id
                                               ),
                            memcache.serialize_instances(token)
                                            )
         return True
     return False
Esempio n. 5
0
 def authorize(self, user):
     """guarda el token de autorizacion"""
     if user is not None:  #el usuario ya esta conectado, pero pide permisos
         token = OAUTH_Access.get_token(self.consumer.access_token)
         if token is None:
             OAUTH_Access.remove_token(user, 'facebook')
             token = OAUTH_Access.add_token(
                 token_key=self.consumer.access_token,
                 token_secret='',
                 provider='facebook',
                 user=user,
             )
         else:
             token.user = user
             token.put()
         self.consumer = GraphAPI(access_token=token.token_key)
         facebookInfo = self.get_user_info()
         if user.facebook_user is None:
             fbuser = FacebookUser.register(
                 user=user,
                 uid=facebookInfo['id'],
                 email=facebookInfo.get('email', None),
                 realname=facebookInfo["name"],
                 profile_url=facebookInfo["link"],
                 access_token=self.consumer.access_token)
         else:
             user.facebook_user.update(
                 uid=facebookInfo['id'],
                 realname=facebookInfo['name'],
                 profile_url=facebookInfo["link"],
             )
         self.user = user
         self.token = token
         import memcache
         memclient = memcache.mem.Client()
         token_cache = {'token': token, 'user': self.user}
         memclient.set(
             '%sfbclienttoken_%s' %
             (memcache.version, self.consumer.access_token), token_cache)
         memclient.set('%sfbclientuser_%s' % (memcache.version, user.id),
                       memcache.serialize_instances(token))
         return True
     return False
Esempio n. 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)
Esempio n. 7
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
Esempio n. 8
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)
Esempio n. 9
0
 def _post_put(self, **kwargs):
     import memcache
     memcache.set('%s%s' % (memcache.version, self.key().name()),
                  memcache.serialize_instances(self), 300)
Esempio n. 10
0
 def _post_put(self, **kwargs):
     import memcache
     memcache.delete('%s%s_avatarcachebase64' % (memcache.version, self.username))
     memcache.set('%s%s' % (memcache.version, self.key().name()), memcache.serialize_instances(self), 300)    
Esempio n. 11
0
 def _post_put(self, **kwargs):
     import memcache
     memcache.delete('%s%s_avatarcachebase64' %
                     (memcache.version, self.username))
     memcache.set('%s%s' % (memcache.version, self.key().name()),
                  memcache.serialize_instances(self), 300)
Esempio n. 12
0
 def _post_put(self, **kwargs):
     import memcache
     memcache.set('%s%s' % (memcache.version, self.key().name()), memcache.serialize_instances(self), 300)