def get_or_create(cls,user=None): if not user: user = users.get_current_user() if not user: raise Exception('not logged in - cannot get or create TickUser') existing = cls.all().filter('all_users = ',user).get() if not existing: invitations = None if not users.is_current_user_admin(): invitations = Invitation.all().filter('email_address =',user.email().lower()).fetch(1000) if users.is_current_user_admin() or invitations: existing = cls( tick_name = user.nickname(), email_address = user.email(), all_users = [user], all_user_ids = [user.user_id()], ) existing.put() # add inviters as followers if invitations: from follow import Follow for invite in invitations: Follow.add_follower(existing,invite.inviter) # add default lists from ticklist import TickList from setlist import SetList TickList.create_list('Suggestions for Tick','public') getting_started = SetList.all(keys_only=True).filter('name =','getting started with tick').get() if getting_started: TickList.create_from_setlist('Getting Started',getting_started.id()) TickUserStat.generate_stats(existing) # TODO: create a new stats infrastructure else: raise NotInvitedError('not invited') return existing
def generate_stats(cls, user=None): ''' builds stats from scratch if there are any missing the method is VERY inefficient so it should be avoided at all costs normally we should increment just the stats we are changing it also only collects stats for the first 1000 lists belonging to a user ''' from ticklist import TickList, TickTask # lists if user: lists = TickList.all().filter('owner =', TickUser.get_current_user()).filter( 'deleted =', False).fetch(1000) else: lists = TickList.all().filter('deleted =', False).fetch(1000) lists_complete = len([lst for lst in lists if not lst.open]) tasks_created = 0 tasks_complete = 0 for lst in lists: tasks_created += lst.num_tasks tasks_complete += lst.num_completed_tasks # TODO: cache this in memcached return { 'lists created': len(lists), 'tasks created': tasks_created, 'tasks complete': tasks_complete, 'lists complete': lists_complete, }
def generate_stats(cls,user=None): ''' builds stats from scratch if there are any missing the method is VERY inefficient so it should be avoided at all costs normally we should increment just the stats we are changing it also only collects stats for the first 1000 lists belonging to a user ''' from ticklist import TickList, TickTask # lists if user: lists = TickList.all().filter('owner =',TickUser.get_current_user()).filter('deleted =',False).fetch(1000) else: lists = TickList.all().filter('deleted =',False).fetch(1000) lists_complete = len([ lst for lst in lists if not lst.open ]) tasks_created = 0 tasks_complete = 0 for lst in lists: tasks_created += lst.num_tasks tasks_complete += lst.num_completed_tasks # TODO: cache this in memcached return { 'lists created': len(lists), 'tasks created': tasks_created, 'tasks complete': tasks_complete, 'lists complete': lists_complete, }
def get_or_create(cls, user=None): if not user: user = users.get_current_user() if not user: raise Exception('not logged in - cannot get or create TickUser') existing = cls.all().filter('all_users = ', user).get() if not existing: invitations = None if not users.is_current_user_admin(): invitations = Invitation.all().filter( 'email_address =', user.email().lower()).fetch(1000) if users.is_current_user_admin() or invitations: existing = cls( tick_name=user.nickname(), email_address=user.email(), all_users=[user], all_user_ids=[user.user_id()], ) existing.put() # add inviters as followers if invitations: from follow import Follow for invite in invitations: Follow.add_follower(existing, invite.inviter) # add default lists from ticklist import TickList from setlist import SetList TickList.create_list('Suggestions for Tick', 'public') getting_started = SetList.all(keys_only=True).filter( 'name =', 'getting started with tick').get() if getting_started: TickList.create_from_setlist('Getting Started', getting_started.id()) TickUserStat.generate_stats( existing) # TODO: create a new stats infrastructure else: raise NotInvitedError('not invited') return existing