Esempio n. 1
0
def new_follower(sender, **kwargs):
    """
        Captura la señal de un nuevo seguidor
        Escribe en el timeline de los dos usuarios.
        Envia una notificacion al correo.
        Escribe en el timeline de notificaciones
    """
    from google.appengine.ext import db
    from models_acc import UserTimelineSystem, UserTimeline, UserSettings
    if not isinstance(kwargs['following'], db.Key):
        raise AttributeError
    if kwargs['following'].id() == 962005 or sender.username == 'georemindme':
        return 
    from google.appengine.ext.deferred import defer
    defer(UserTimeline.add_timelines_to_follower, kwargs['following'], sender.key())
    settings = UserSettings.objects.get_by_id(kwargs['following'].id())
    timeline = UserTimelineSystem(parent = sender, user = sender, instance = kwargs['following'], msg_id=100, visible=False)
    put = db.put_async([timeline])
    if settings.show_followings:
        timelinePublic = UserTimeline(parent=sender, user = sender, instance = kwargs['following'], msg_id=100)
        timelinePublic.put()
    from google.appengine.ext.deferred import defer
    defer(settings.notify_follower, sender.key())  # mandar email de notificacion
    put.get_result()
    if sender.key() != kwargs['following']:
        from geouser.models_utils import _Notification
        notification = _Notification(parent=kwargs['following'], owner=kwargs['following'], timeline=timeline)
        notification.put()
Esempio n. 2
0
def new_follower(sender, **kwargs):
    """
        Captura la señal de un nuevo seguidor
        Escribe en el timeline de los dos usuarios.
        Envia una notificacion al correo.
        Escribe en el timeline de notificaciones
    """
    from google.appengine.ext import db
    from models_acc import UserTimelineSystem, UserTimeline, UserSettings
    if not isinstance(kwargs['following'], db.Key):
        raise AttributeError
    if kwargs['following'].id() == 962005 or sender.username == 'georemindme':
        return
    from google.appengine.ext.deferred import defer
    defer(UserTimeline.add_timelines_to_follower, kwargs['following'],
          sender.key())
    settings = UserSettings.objects.get_by_id(kwargs['following'].id())
    timeline = UserTimelineSystem(parent=sender,
                                  user=sender,
                                  instance=kwargs['following'],
                                  msg_id=100,
                                  visible=False)
    put = db.put_async([timeline])
    if settings.show_followings:
        timelinePublic = UserTimeline(parent=sender,
                                      user=sender,
                                      instance=kwargs['following'],
                                      msg_id=100)
        timelinePublic.put()
    from google.appengine.ext.deferred import defer
    defer(settings.notify_follower,
          sender.key())  # mandar email de notificacion
    put.get_result()
    if sender.key() != kwargs['following']:
        from geouser.models_utils import _Notification
        notification = _Notification(parent=kwargs['following'],
                                     owner=kwargs['following'],
                                     timeline=timeline)
        notification.put()
Esempio n. 3
0
def add_timeline_to_follower(user_key, follower_key, limit=10):
    from models_acc import UserTimeline, UserTimelineFollowersIndex
    from google.appengine.ext import db
    timeline = UserTimeline.all(keys_only=True).filter('user ='******'_vis =', 'public').order('-modified').fetch(limit)
    indexes_to_save = []
    for t in timeline:
        if UserTimelineFollowersIndex.all(keys_only=True).ancestor(t).filter('followers =', follower_key).get() is not None:
            continue # ya esta el usuario como seguidor del timeline
        index = UserTimelineFollowersIndex.all().ancestor(t).order('-created').get()
        if index is None:  # no existen indices o hemos alcanzado el maximo
            index = UserTimelineFollowersIndex(parent=t)
        index.followers.append(follower_key)
        indexes_to_save.append(index)
    db.put(indexes_to_save)
    return True
Esempio n. 4
0
def add_timeline_to_follower(user_key, follower_key, limit=10):
    from models_acc import UserTimeline, UserTimelineFollowersIndex
    from google.appengine.ext import db
    timeline = UserTimeline.all(keys_only=True).filter(
        'user ='******'_vis =',
                                   'public').order('-modified').fetch(limit)
    indexes_to_save = []
    for t in timeline:
        if UserTimelineFollowersIndex.all(keys_only=True).ancestor(t).filter(
                'followers =', follower_key).get() is not None:
            continue  # ya esta el usuario como seguidor del timeline
        index = UserTimelineFollowersIndex.all().ancestor(t).order(
            '-created').get()
        if index is None:  # no existen indices o hemos alcanzado el maximo
            index = UserTimelineFollowersIndex(parent=t)
        index.followers.append(follower_key)
        indexes_to_save.append(index)
    db.put(indexes_to_save)
    return True
Esempio n. 5
0
 def write_timeline(self, msg, instance=None):
     from models_acc import UserTimeline
     return UserTimeline.insert(msg=msg, user=self, instance=instance)
Esempio n. 6
0
    def get_by_id(self, userid, query_id=None, querier=None):
        '''
        Obtiene la lista de ultimos timeline del usuario

            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
        '''
        try:
            userid = long(userid)
        except:
            return None
        from geovote.models import Vote, Comment
        from geoalert.models import Suggestion
        from geolist.models import List
        from models_acc import UserTimeline, UserTimelineSuggest
        query = UserTimeline.all().filter(
            'user ='******'-created')
        if query_id is not None:  # recuperamos los cursores anteriores
            query = query.with_cursor(start_cursor=query_id)
        timelines = query.fetch(10)
        query_id = query.cursor()
        from georemindme.funcs import prefetch_refprops
        timelines = prefetch_refprops(timelines, UserTimeline.user,
                                      UserTimeline.instance)
        instances = _load_ref_instances(timelines)
        if querier is None:
            return [
                query_id,
                [{
                    'id':
                    timeline.id,
                    'created':
                    timeline.created,
                    'modified':
                    timeline.modified,
                    'msg':
                    timeline.msg,
                    'username':
                    timeline.user.username,
                    'msg_id':
                    timeline.msg_id,
                    'instance':
                    instances.get(
                        UserTimeline.instance.get_value_for_datastore(
                            timeline), timeline.instance),
                    'list':
                    instances.get(
                        UserTimelineSuggest.list_id.get_value_for_datastore(
                            timeline), timeline.list_id) if isinstance(
                                timeline, UserTimelineSuggest) else None,
                    'has_voted':
                    Vote.objects.user_has_voted(
                        db.Key.from_path(User.kind(), userid),
                        timeline.instance.key())
                    if timeline.instance is not None else None,
                    'vote_counter':
                    Vote.objects.get_vote_counter(timeline.instance.key())
                    if timeline.instance is not None else None,
                    'comments':
                    Comment.objects.get_by_instance(timeline.instance),
                    'is_private':
                    False
                } for timeline in timelines]
            ]
        elif querier.is_authenticated() and querier.are_friends(
                db.Key.from_path(User.kind(), userid)):
            return [
                query_id,
                [{
                    'id':
                    timeline.id,
                    'created':
                    timeline.created,
                    'modified':
                    timeline.modified,
                    'msg':
                    timeline.msg,
                    'username':
                    timeline.user.username,
                    'msg_id':
                    timeline.msg_id,
                    'instance':
                    instances.get(
                        UserTimeline.instance.get_value_for_datastore(
                            timeline), timeline.instance),
                    'list':
                    instances.get(
                        UserTimelineSuggest.list_id.get_value_for_datastore(
                            timeline), timeline.list_id) if isinstance(
                                timeline, UserTimelineSuggest) else None,
                    'has_voted':
                    Vote.objects.user_has_voted(querier,
                                                timeline.instance.key())
                    if timeline.instance is not None else None,
                    'vote_counter':
                    Vote.objects.get_vote_counter(timeline.instance.key())
                    if timeline.instance is not None else None,
                    'comments':
                    Comment.objects.get_by_instance(timeline.instance,
                                                    querier=querier),
                    'user_follower':
                    timeline.instance.has_follower(querier)
                    if isinstance(timeline.instance, Suggestion)
                    and querier.is_authenticated() else None,
                    'is_private':
                    False,
                } for timeline in timelines
                 if timeline._is_shared() or timeline._is_public()]
            ]
        return [
            query_id,
            [{
                'id':
                timeline.id,
                'created':
                timeline.created,
                'modified':
                timeline.modified,
                'msg':
                timeline.msg,
                'username':
                timeline.user.username,
                'msg_id':
                timeline.msg_id,
                'instance':
                instances.get(
                    UserTimeline.instance.get_value_for_datastore(timeline),
                    timeline.instance),
                'list':
                instances.get(
                    UserTimelineSuggest.list_id.get_value_for_datastore(
                        timeline), timeline.list_id) if isinstance(
                            timeline, UserTimelineSuggest) else None,
                'has_voted':
                Vote.objects.user_has_voted(querier, timeline.instance.key())
                if timeline.instance is not None
                and querier.is_authenticated() else None,
                'vote_counter':
                Vote.objects.get_vote_counter(timeline.instance.key())
                if timeline.instance is not None else None,
                'comments':
                Comment.objects.get_by_instance(timeline.instance,
                                                querier=querier),
                'user_follower':
                timeline.instance.has_follower(querier)
                if isinstance(timeline.instance, Suggestion)
                and querier.is_authenticated() else None,
                'is_private':
                False,
            } for timeline in timelines if timeline._is_public()]
        ]
Esempio n. 7
0
    def get_by_id(self, userid, query_id = None, querier=None):
        '''
        Obtiene la lista de ultimos timeline del usuario

            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
        '''
        try:
            userid = long(userid)
        except:
            return None
        from geovote.models import Vote, Comment
        from geoalert.models import Suggestion
        from geolist.models import List
        from models_acc import UserTimeline, UserTimelineSuggest
        query = UserTimeline.all().filter('user ='******'-created')
        if query_id is not None:  # recuperamos los cursores anteriores
            query = query.with_cursor(start_cursor=query_id)
        timelines = query.fetch(10)
        query_id = query.cursor()
        from georemindme.funcs import prefetch_refprops
        timelines = prefetch_refprops(timelines, UserTimeline.user, UserTimeline.instance)
        instances = _load_ref_instances(timelines)
        if querier is None:
                return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(db.Key.from_path(User.kind(), userid), timeline.instance.key()) if timeline.instance is not None else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance),
                        'is_private': False
                        } 
                       for timeline in timelines]]
        elif querier.is_authenticated() and querier.are_friends(db.Key.from_path(User.kind(), userid)):
            return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(querier, timeline.instance.key()) if timeline.instance is not None else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance, querier=querier),
                        'user_follower': timeline.instance.has_follower(querier) if isinstance(timeline.instance, Suggestion) and querier.is_authenticated() else None,
                        'is_private': False,
                        }
                        for timeline in timelines if timeline._is_shared() or timeline._is_public()]]
        return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(querier, timeline.instance.key()) if timeline.instance is not None and querier.is_authenticated()else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance, querier=querier),
                        'user_follower': timeline.instance.has_follower(querier) if isinstance(timeline.instance, Suggestion) and querier.is_authenticated() else None,
                        'is_private': False,
                        }
                       for timeline in timelines if timeline._is_public()]]
Esempio n. 8
0
 def write_timeline(self, msg, instance=None):
     from models_acc import UserTimeline
     return UserTimeline.insert(msg=msg, user=self, instance=instance)