def new_social_user_registered(sender, **kwargs): """ Captura la señal de un nuevo usuario de red social, escribe su timeline """ from models_acc import UserTimelineSystem from models_social import GoogleUser, FacebookUser, TwitterUser if isinstance(sender, GoogleUser): timeline = UserTimelineSystem(parent=sender.user, user=sender.user, msg_id=1) logging.info('Usuario con email %s ahora tiene cuenta de Google: %s' % (sender.user.email, sender.uid)) elif isinstance(sender, FacebookUser): timeline = UserTimelineSystem(parent=sender.user, user=sender.user, msg_id=2) logging.info( 'Usuario con email %s ahora tiene cuenta de Facebook: %s' % (sender.user.email, sender.uid)) elif isinstance(sender, TwitterUser): timeline = UserTimelineSystem(parent=sender.user, user=sender.user, msg_id=3) logging.info('Usuario con email %s ahora tiene cuenta de Twitter: %s' % (sender.user.email, sender.uid)) else: return timeline.put()
def new_user_registered(sender, **kwargs): """ Captura la señal de un nuevo usuario registrado, escribe el primer timeline """ if kwargs['status'] is None: logging.error('Problema registrando usuario %s') % sender.email sender.delete() from exceptions import RegistrationException raise RegistrationException() sender.send_confirm_code() from models_acc import UserTimelineSystem timeline = UserTimelineSystem(parent = sender, user=sender, msg_id=0) logging.info('Registrado nuevo usuario %s email: %s' % (sender.id, sender.email)) timeline.put()
def new_user_registered(sender, **kwargs): """ Captura la señal de un nuevo usuario registrado, escribe el primer timeline """ if kwargs['status'] is None: logging.error('Problema registrando usuario %s') % sender.email sender.delete() from exceptions import RegistrationException raise RegistrationException() sender.send_confirm_code() from models_acc import UserTimelineSystem timeline = UserTimelineSystem(parent=sender, user=sender, msg_id=0) logging.info('Registrado nuevo usuario %s email: %s' % (sender.id, sender.email)) timeline.put()
def new_social_user_registered(sender, **kwargs): """ Captura la señal de un nuevo usuario de red social, escribe su timeline """ from models_acc import UserTimelineSystem from models_social import GoogleUser, FacebookUser, TwitterUser if isinstance(sender, GoogleUser): timeline = UserTimelineSystem(parent = sender.user, user = sender.user, msg_id=1) logging.info('Usuario con email %s ahora tiene cuenta de Google: %s' % (sender.user.email, sender.uid)) elif isinstance(sender, FacebookUser): timeline = UserTimelineSystem(parent = sender.user, user = sender.user, msg_id=2) logging.info('Usuario con email %s ahora tiene cuenta de Facebook: %s' % (sender.user.email, sender.uid)) elif isinstance(sender, TwitterUser): timeline = UserTimelineSystem(parent = sender.user, user = sender.user, msg_id=3) logging.info('Usuario con email %s ahora tiene cuenta de Twitter: %s' % (sender.user.email, sender.uid)) else: return timeline.put()
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()
def get_activity_timeline(self, query_id=None): from models_acc import UserTimelineSystem, UserTimeline, UserTimelineFollowersIndex, UserTimelineSuggest from geovote.models import Comment, Vote from geoalert.models import Event from geolist.models import List # definir las consultas query_chrono = UserTimelineFollowersIndex.all().filter( 'followers =', self.key()).order('-created') query_activity = UserTimelineSystem.all().filter( 'user ='******'visible =', True).order('-modified') # recuperar cursores if query_id is not None and len(query_id) >= 2: cursor_chronology = query_id[0] cursor_activity = query_id[1] query_chrono = query_chrono.with_cursor( start_cursor=cursor_chronology) query_activity = query_activity.with_cursor( start_cursor=cursor_activity) else: cursor_activity = None cursor_chronology = None # let's go! timeline = [] timeline_chrono = [] activity_async = query_activity.run( config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE)) chrono_async = query_chrono.run(config=datastore_query.QueryOptions( limit=TIMELINE_PAGE_SIZE)) _go_chrono = True chrono = None for activity_timeline in activity_async: while _go_chrono: if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE: _go_chrono = False break if chrono is None: try: chrono = chrono_async.next() except: _go_chrono = False break if chrono is not None and chrono.created > activity_timeline.modified: timeline_chrono.append(chrono) chrono = None else: break timeline.append(activity_timeline) if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE: break # generar timeline timeline_chrono = fetch_parents(timeline_chrono) timeline = prefetch_refprops(timeline, UserTimeline.user) timeline_chrono = prefetch_refprops(timeline_chrono, UserTimeline.instance, UserTimeline.user) timeline.extend(timeline_chrono) #seguimos cargando por lotes todas las referencias from helpers_acc import _load_ref_instances instances = _load_ref_instances(timeline) timeline = [{ 'id': int(activity_timeline.id), 'created': activity_timeline.created, 'modified': activity_timeline.modified, 'msg': activity_timeline.msg, 'username': activity_timeline.user.username, 'msg_id': activity_timeline.msg_id, 'instance': instances.get( UserTimeline.instance.get_value_for_datastore( activity_timeline), activity_timeline.instance), 'has_voted': Vote.objects.user_has_voted(self, activity_timeline.instance.key()) if activity_timeline.instance is not None else None, 'vote_counter': Vote.objects.get_vote_counter(activity_timeline.instance.key()) if activity_timeline.instance is not None else None, 'comments': Comment.objects.get_by_instance(activity_timeline.instance, querier=self), 'list': instances.get( UserTimelineSuggest.list_id.get_value_for_datastore( activity_timeline), activity_timeline.list_id) if isinstance(activity_timeline, UserTimelineSuggest) else None, 'status': activity_timeline.status if hasattr(activity_timeline, 'status') else None, 'is_private': True, 'user_follower': instances.get( UserTimeline.instance.get_value_for_datastore( activity_timeline), activity_timeline.instance).has_follower(self) if hasattr( instances.get( UserTimeline.instance.get_value_for_datastore( activity_timeline), activity_timeline.instance), 'has_follower') else None, } for activity_timeline in timeline] from operator import itemgetter timeline_sorted = sorted(timeline, key=itemgetter('modified'), reverse=True) chronology = [[query_chrono.cursor(), query_activity.cursor()], timeline_sorted] return chronology
def get_activity_timeline(self, query_id=None): from models_acc import UserTimelineSystem, UserTimeline, UserTimelineFollowersIndex, UserTimelineSuggest from geovote.models import Comment, Vote from geoalert.models import Event from geolist.models import List # definir las consultas query_chrono = UserTimelineFollowersIndex.all().filter('followers =', self.key()).order('-created') query_activity = UserTimelineSystem.all().filter('user ='******'visible =', True).order('-modified') # recuperar cursores if query_id is not None and len(query_id)>=2: cursor_chronology = query_id[0] cursor_activity = query_id[1] query_chrono = query_chrono.with_cursor(start_cursor=cursor_chronology) query_activity = query_activity.with_cursor(start_cursor=cursor_activity) else: cursor_activity = None cursor_chronology = None # let's go! timeline = [] timeline_chrono = [] activity_async = query_activity.run(config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE)) chrono_async = query_chrono.run(config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE)) _go_chrono = True chrono = None for activity_timeline in activity_async: while _go_chrono: if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE: _go_chrono = False break if chrono is None: try: chrono = chrono_async.next() except: _go_chrono = False break if chrono is not None and chrono.created > activity_timeline.modified: timeline_chrono.append(chrono) chrono = None else: break timeline.append(activity_timeline) if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE: break # generar timeline timeline_chrono = fetch_parents(timeline_chrono) timeline = prefetch_refprops(timeline, UserTimeline.user) timeline_chrono = prefetch_refprops(timeline_chrono, UserTimeline.instance, UserTimeline.user) timeline.extend(timeline_chrono) #seguimos cargando por lotes todas las referencias from helpers_acc import _load_ref_instances instances = _load_ref_instances(timeline) timeline = [{ 'id': int(activity_timeline.id), 'created': activity_timeline.created, 'modified': activity_timeline.modified, 'msg': activity_timeline.msg, 'username': activity_timeline.user.username, 'msg_id': activity_timeline.msg_id, 'instance': instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance), 'has_voted': Vote.objects.user_has_voted(self, activity_timeline.instance.key()) if activity_timeline.instance is not None else None, 'vote_counter': Vote.objects.get_vote_counter(activity_timeline.instance.key()) if activity_timeline.instance is not None else None, 'comments': Comment.objects.get_by_instance(activity_timeline.instance, querier=self), 'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(activity_timeline), activity_timeline.list_id) if isinstance(activity_timeline, UserTimelineSuggest) else None, 'status': activity_timeline.status if hasattr(activity_timeline, 'status') else None, 'is_private': True, 'user_follower': instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance).has_follower(self) if hasattr(instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance), 'has_follower') else None, } for activity_timeline in timeline] from operator import itemgetter timeline_sorted = sorted(timeline, key=itemgetter('modified'), reverse=True) chronology = [[query_chrono.cursor(), query_activity.cursor()], timeline_sorted] return chronology