Esempio n. 1
0
 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
Esempio n. 2
0
 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