Example #1
0
 def create(cls,sentence,other=None,target=None,actor=None,extra_recipients=[]):
     expecting = 'text'
     pointers = frozenset(['<actor>','<target>','<other>'])
     grammar = sentence.split('|')
     if grammar[0] in pointers:
         grammar = [''] + grammar
     for token in grammar:
         if expecting == 'text':
             if token in pointers:
                 raise Exception('invalid activity grammar: %s found when text was expected' % token)
             expecting = 'entity'
         else: #entity
             if token not in pointers:
                 raise Exception('invalid activity grammar: "%s" found when <entity> was expected' % token)
             expecting = 'text'
     if not actor:
         actor = TickUser.get_current_user()
         
     one_hour_ago = datetime.today() - timedelta(hours=1)
     query = cls.all(keys_only=True)
     if target:
         query = query.ancestor(target)
     existing = query.filter('sentence =',sentence).filter('actor =',actor).filter('target =',target).filter('other =',other).filter('creation_date >',one_hour_ago).get()
     if existing:
         return None
         
     extra = [item for sublist in [extra.all_user_ids for extra in extra_recipients] for item in sublist] # this is a fast and convenient way of flattening the list of lists
     new_entity = cls(parent=target,sentence=sentence,actor=actor,target=target,other=other,extra_recipients=extra)
     new_entity.put()
     return new_entity
Example #2
0
 def can_tag(cls,target,user=None):
     if not user:
         user = TickUser.get_current_user(keys_only=True)
     if not user:
         return False
     tag_key = Tag.make_key_name(user,target)
     return cls.get_by_key_name(tag_key,parent=target) is None   
Example #3
0
 def can_tag(cls, target, user=None):
     if not user:
         user = TickUser.get_current_user(keys_only=True)
     if not user:
         return False
     tag_key = Tag.make_key_name(user, target)
     return cls.get_by_key_name(tag_key, parent=target) is None
Example #4
0
 def add_like(cls, kind, id):
     user = TickUser.get_current_user()
     existing = kind.get_by_id(id)
     if not existing:
         raise Exception('%s does not exist' % kind.kind())
     result = cls.add(user, existing)
     if not result:
         raise Exception('%s already favourited' % kind.kind())
     return existing
Example #5
0
 def add_like(cls,kind,id):
     user = TickUser.get_current_user()
     existing = kind.get_by_id(id)    
     if not existing:
         raise Exception('%s does not exist' % kind.kind())
     result = cls.add(user,existing)
     if not result:
         raise Exception('%s already favourited' % kind.kind())  
     return existing
Example #6
0
    def create(cls,
               sentence,
               other=None,
               target=None,
               actor=None,
               extra_recipients=[]):
        expecting = 'text'
        pointers = frozenset(['<actor>', '<target>', '<other>'])
        grammar = sentence.split('|')
        if grammar[0] in pointers:
            grammar = [''] + grammar
        for token in grammar:
            if expecting == 'text':
                if token in pointers:
                    raise Exception(
                        'invalid activity grammar: %s found when text was expected'
                        % token)
                expecting = 'entity'
            else:  #entity
                if token not in pointers:
                    raise Exception(
                        'invalid activity grammar: "%s" found when <entity> was expected'
                        % token)
                expecting = 'text'
        if not actor:
            actor = TickUser.get_current_user()

        one_hour_ago = datetime.today() - timedelta(hours=1)
        query = cls.all(keys_only=True)
        if target:
            query = query.ancestor(target)
        existing = query.filter('sentence =', sentence).filter(
            'actor =',
            actor).filter('target =',
                          target).filter('other =',
                                         other).filter('creation_date >',
                                                       one_hour_ago).get()
        if existing:
            return None

        extra = [
            item
            for sublist in [extra.all_user_ids for extra in extra_recipients]
            for item in sublist
        ]  # this is a fast and convenient way of flattening the list of lists
        new_entity = cls(parent=target,
                         sentence=sentence,
                         actor=actor,
                         target=target,
                         other=other,
                         extra_recipients=extra)
        new_entity.put()
        return new_entity
Example #7
0
 def get_lists(cls,limit=50):
     user = users.get_current_user()
     ticklist_keys = set([])
     index_keys = set([])
     if user:
         # get all your latest lists just in case they arent indexed yet
         owner = TickUser.get_current_user(keys_only=True)
         ticklist_keys.update(cls.all(keys_only=True).filter('deleted =',False).filter('owner =',owner).order('-updated').fetch(limit))
         # get all the other lists you have permission to see, up till the limit
         index_keys.update(cls.PERMISSION_INDEX_TYPE.all(keys_only=True).filter('parent_kind =',cls.__name__).order('ordinal').filter('view_permissions =',user.user_id()).fetch(limit-len(ticklist_keys)))
     else:
         index_keys.update(cls.PERMISSION_INDEX_TYPE.all(keys_only=True).filter('parent_kind =',cls.__name__).order('ordinal').filter('view_permissions =','public').fetch(limit))
     ticklist_keys.update([key.parent() for key in index_keys])
     lists = db.get(ticklist_keys)
     non_deleted = [item for item in lists if item.deleted == False]
     return sorted(non_deleted,key=lambda x: x.updated,reverse=True)
Example #8
0
 def set_favourite(cls, kind, id, status):
     user = TickUser.get_current_user()
     if not user:
         raise Exception('not logged in')
     existing = kind.get_by_id(id)
     if not existing:
         raise Exception('%s does not exist' % kind.kind())
     if status:
         result = cls.add(user, existing)
         if not result:
             raise Exception('%s already favourited' % kind.kind())
     else:
         result = cls.remove(user, existing)
         if not result:
             raise Exception('%s is not a favourite' % kind.kind())
     return existing
Example #9
0
 def set_favourite(cls,kind,id,status):
     user = TickUser.get_current_user()
     if not user:
         raise Exception('not logged in')
     existing = kind.get_by_id(id)    
     if not existing:
         raise Exception('%s does not exist' % kind.kind())
     if status:
         result = cls.add(user,existing)
         if not result:
             raise Exception('%s already favourited' % kind.kind())         
     else:
         result = cls.remove(user,existing)        
         if not result:
             raise Exception('%s is not a favourite' % kind.kind()) 
     return existing
Example #10
0
 def create_list(cls,name,sharing='private'):
     owner = TickUser.get_current_user(keys_only=True)
     slug = slugify(name)
     exists = cls.all(keys_only=True).filter('slug =',slug).filter('owner =',owner).filter('deleted =',False).count(1)
     if exists > 0:
         raise Exception('active list of this name already exists')
     new_list = cls(
         name = name,
         slug = slug,
         next_task_id = 0,
         owner = owner,
         open = True,
         num_tasks = 0,
         num_completed_tasks = 0,
         sharing=sharing,
         )
     new_list.put()
     new_list.enqueue_indexing(url='/tick/tasks/searchindexing',condition=('version',new_list.version))
     return new_list
Example #11
0
 def before_put_trigger(this):
     if not this.is_saved():
         if not this.owner:
             this.owner = TickUser.get_current_user(keys_only=True) #TickUser.get_by_user_id(users.get_current_user().user_id(),keys_only=True)
Example #12
0
 def get_my_lists(cls,limit=50):
     owner = TickUser.get_current_user(keys_only=True)
     lists = cls.all().filter('deleted =',False).filter('owner =',owner).order('-updated').fetch(limit)
     return lists
Example #13
0
 def get_favourites(cls, target_kind, limit=50):
     current = TickUser.get_current_user(keys_only=True)
     faves = cls.all().filter('owner =',
                              current).filter('target_kind =',
                                              target_kind).fetch(limit)
     return faves
Example #14
0
 def get_favourites(cls,target_kind,limit=50):
     current = TickUser.get_current_user(keys_only=True)
     faves = cls.all().filter('owner =',current).filter('target_kind =',target_kind).fetch(limit)
     return faves