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 create_from_setlist(cls,name,type_id): setlist,tasks = SetList.get_setlist_and_tasks(type_id) inserts = [] tree = TaskTree() for task in tasks: tree.add_node(task.parent_task, task.id, task.text, task.notes) inserts = tree.get_flat() new_list = cls.create_list(name) #new_list.num_tasks = len(tasks) new_list.list_type = setlist new_list.put() cls.save_list_items(new_list.key().id(),new_list.version,inserts,[],[]) new_list.enqueue_indexing(url='/tick/tasks/searchindexing',condition=('version',new_list.version)) return (setlist,new_list)
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