Esempio n. 1
0
 def get_by_user(self, user, query_id = None, page=1, querier=None):
     """
     Obtiene una lista con todos los comentarios hechos por un usuario
     
         :param user: usuario a buscar
         :type user: :class:`geouser.models.User`
         :param query_id: identificador de la busqueda paginada
         :type query_id: :class:`long`
         :param page: pagina a buscar
         :type page: :class:`integer`
         
         :returns: [query_id, [:class:`geovote.models.Comment`]]
     """
     if querier is not None and not isinstance(querier, User):
         raise TypeError
     from georemindme.paging import PagedQuery
     from google.appengine.api import datastore
     q = datastore.Query('Comment', {'user ='******'deleted =': False})
     q.Order(('created', datastore.Query.DESCENDING))
     p = PagedQuery(q, id = query_id, page_size=7)
     comments = p.fetch_page(page)
     from georemindme.funcs import prefetch_refpropsEntity
     prefetch = prefetch_refpropsEntity(comments, 'user', 'instance')
     return [p.id, [
       {'id': comment.key().id(),
        'username': prefetch[comment['user']].username,
        'has_voted':  Vote.objects.user_has_voted(querier, comment.key()) if querier is not None else None,
        'vote_counter': comment['votes'],
        'instance': prefetch[comment['instance']],
        'msg': comment['msg'],
        'created': comment['created'],
        } for comment in comments]
             ]
Esempio n. 2
0
 def get_top_voted(self, instance, querier):
     if querier is None:
         raise TypeError
     if instance is not None:
         import memcache
         top = None #memcache.get(memcache.get('%stopcomments_%s' % (memcache.version, instance.key())))
         if top is None:
             from google.appengine.api import datastore
             top = datastore.Query('Comment', {'instance =': instance.key(), 'votes >': 0})
             top.Order(('votes', datastore.Query.DESCENDING))
             top = top.Get(3)
             if len(top) > 0:
                 from georemindme.funcs import prefetch_refpropsEntity
                 prefetch = prefetch_refpropsEntity(top, 'user')
                 return [
                                {'id': comment.key().id(),
                                 'username': prefetch[comment['user']].username,
                                 'has_voted':  Vote.objects.user_has_voted(querier, comment.key()) if querier is not None else None,
                                 'vote_counter': comment['votes'],
                                 'msg': comment['msg'],
                                 'created': comment['created'],
                                 } for comment in top
                         ]
                 memcache.set('%stopcomments_%s' % (memcache.version, instance.key()), top, 300)
     return top
Esempio n. 3
0
 def get_invitations_pending(self, user, page = 1, query_id = None):
     raise NotImplementedError()
     if not isinstance(user, User):
         raise TypeError
     from google.appengine.api import datastore
     q = datastore.Query('Invitation', {'to =': user.key(), 'status': 0})
     from paging import PagedQuery
     p = PagedQuery(q, id = query_id)
     invitations = p.fetch_page(page)
     from georemindme.funcs import prefetch_refpropsEntity
     prefetch = prefetch_refpropsEntity(invitations, 'sender', 'to', 'instance')
     return [p.id, [i.to_dict() for i in p.fetch_page(page)], p.page_count()]
Esempio n. 4
0
 def get_by_user(self, user, query_id=None, page=1, querier=None):
     """
     Obtiene una lista con todos los comentarios hechos por un usuario
     
         :param user: usuario a buscar
         :type user: :class:`geouser.models.User`
         :param query_id: identificador de la busqueda paginada
         :type query_id: :class:`long`
         :param page: pagina a buscar
         :type page: :class:`integer`
         
         :returns: [query_id, [:class:`geovote.models.Comment`]]
     """
     if querier is not None and not isinstance(querier, User):
         raise TypeError
     from georemindme.paging import PagedQuery
     from google.appengine.api import datastore
     q = datastore.Query('Comment', {
         'user ='******'deleted =': False
     })
     q.Order(('created', datastore.Query.DESCENDING))
     p = PagedQuery(q, id=query_id, page_size=7)
     comments = p.fetch_page(page)
     from georemindme.funcs import prefetch_refpropsEntity
     prefetch = prefetch_refpropsEntity(comments, 'user', 'instance')
     return [
         p.id,
         [{
             'id':
             comment.key().id(),
             'username':
             prefetch[comment['user']].username,
             'has_voted':
             Vote.objects.user_has_voted(querier, comment.key())
             if querier is not None else None,
             'vote_counter':
             comment['votes'],
             'instance':
             prefetch[comment['instance']],
             'msg':
             comment['msg'],
             'created':
             comment['created'],
         } for comment in comments]
     ]
Esempio n. 5
0
 def get_top_voted(self, instance, querier):
     if querier is None:
         raise TypeError
     if instance is not None:
         import memcache
         top = None  #memcache.get(memcache.get('%stopcomments_%s' % (memcache.version, instance.key())))
         if top is None:
             from google.appengine.api import datastore
             top = datastore.Query('Comment', {
                 'instance =': instance.key(),
                 'votes >': 0
             })
             top.Order(('votes', datastore.Query.DESCENDING))
             top = top.Get(3)
             if len(top) > 0:
                 from georemindme.funcs import prefetch_refpropsEntity
                 prefetch = prefetch_refpropsEntity(top, 'user')
                 return [{
                     'id':
                     comment.key().id(),
                     'username':
                     prefetch[comment['user']].username,
                     'has_voted':
                     Vote.objects.user_has_voted(querier, comment.key())
                     if querier is not None else None,
                     'vote_counter':
                     comment['votes'],
                     'msg':
                     comment['msg'],
                     'created':
                     comment['created'],
                 } for comment in top]
                 memcache.set(
                     '%stopcomments_%s' %
                     (memcache.version, instance.key()), top, 300)
     return top
Esempio n. 6
0
class CommentHelper(object):
    """ Helper de la clase comentario """
    def get_by_id(self, id):
        try:
            id = long(id)
        except:
            return None
        comment = Comment.get_by_id(id)
        if comment is not None:
            if comment.deleted:
                return None
            if comment._is_public():
                return comment
        return None

    def get_by_key(self, key):
        """
        Obtiene el evento con ese key
        """
        return Comment.get(key)

    def get_by_user(self, user, query_id=None, page=1, querier=None):
        """
        Obtiene una lista con todos los comentarios hechos por un usuario
        
            :param user: usuario a buscar
            :type user: :class:`geouser.models.User`
            :param query_id: identificador de la busqueda paginada
            :type query_id: :class:`long`
            :param page: pagina a buscar
            :type page: :class:`integer`
            
            :returns: [query_id, [:class:`geovote.models.Comment`]]
        """
        if querier is not None and not isinstance(querier, User):
            raise TypeError
        from georemindme.paging import PagedQuery
        from google.appengine.api import datastore
        q = datastore.Query('Comment', {
            'user ='******'deleted =': False
        })
        q.Order(('created', datastore.Query.DESCENDING))
        p = PagedQuery(q, id=query_id, page_size=7)
        comments = p.fetch_page(page)
        from georemindme.funcs import prefetch_refpropsEntity
        prefetch = prefetch_refpropsEntity(comments, 'user', 'instance')
        return [
            p.id,
            [{
                'id':
                comment.key().id(),
                'username':
                prefetch[comment['user']].username,
                'has_voted':
                Vote.objects.user_has_voted(querier, comment.key())
                if querier is not None else None,
                'vote_counter':
                comment['votes'],
                'instance':
                prefetch[comment['instance']],
                'msg':
                comment['msg'],
                'created':
                comment['created'],
            } for comment in comments]
        ]

    def get_by_instance(self,
                        instance,
                        query_id=None,
                        page=1,
                        querier=None,
                        async=False):
        """
        Obtiene una lista con todos los comentarios hechos en una instancia
        
            :param instance: objeto al que buscar los comentarios
            :type instance: :class:`db.Model`
            :param query_id: identificador de la busqueda paginada
            :type query_id: :class:`long`
            :param page: pagina a buscar
            :type page: :class:`integer`
            
            :returns: [query_id, [:class:`geovote.models.Comment`]]
        """
        if querier is not None and not querier.is_authenticated():
            querier = None
        if querier is not None and not isinstance(querier, User):
            raise TypeError
        if instance is None:
            return None
        from georemindme.paging import PagedQuery
        from google.appengine.api import datastore
        q = datastore.Query(kind='Comment',
                            filters={
                                'instance =': instance.key(),
                                'deleted =': False
                            })
        q.Order(('created', datastore.Query.DESCENDING))
        p = PagedQuery(q, id=query_id, page_size=7)
        if async:
            from google.appengine.datastore import datastore_query
            q = Comment.all().filter('instance =',
                                     instance).filter('deleted =',
                                                      False).order('-created')
            return p.id, q.run(config=datastore_query.QueryOptions(limit=7))
        comments = p.fetch_page(page)
        from georemindme.funcs import prefetch_refpropsEntity
        prefetch = prefetch_refpropsEntity(comments, 'user', 'instance')
        return [
            p.id,
            [{
                'id':
                comment.key().id(),
                'username':
                prefetch[comment['user']].username,
                'has_voted':
                Vote.objects.user_has_voted(querier, comment.key())
                if querier is not None else None,
                'vote_counter':
                comment['votes'],
                'instance':
                prefetch[comment['instance']],
                'msg':
                comment['msg'],
                'created':
                comment['created'],
            } for comment in comments]
        ]