Ejemplo n.º 1
0
 def add(task_dict):
     """
     task_dict: {
         'owner_token' : str(64) -> person.token,
         'due': datetime.datetime,
         'title': str(),
         'body': str(),
         'important': bool(),
         'done': bool()
     }
     """
     p = Person.get(task_dict['owner_token'])
     if not p:
         raise Exception('Owner does not exist!')
     try:
         t = Task(
             owner_id= p.id,
             due= task_dict['due'],
             title= task_dict['title'],
             body= task_dict['body'],
             important= task_dict['important'],
             done= task_dict['done'],
             token=token_urlsafe(32)
             )
     except:
         raise Exception('Problem in request dict')
     redis_client.delete(Person.get_id(t.owner_id).token + '-tasks')
     db.session.add(t)
     db.session.commit()
     redis_client.set(t.token, json.dumps(t.to_dict()), ex=1800)
     return t
Ejemplo n.º 2
0
 def toggle_done(_token):
     t = Task.query.filter_by(token=_token).first()
     if not t:
         raise Exception('Task does not exist!')
     else:
         t.done = not t.done
         db.session.commit()
         redis_client.delete(Person.get_id(t.owner_id).token + '-tasks')
         redis_client.delete(t.token)
         redis_client.set(t.token, json.dumps(t.to_dict), ex=1800)
         return t.to_dict()
Ejemplo n.º 3
0
 def delete(_token):
     t_redis = redis_client.get(_token)
     if t_redis:
         t = Task.from_dict(json.loads(t_redis))
     else:
         t = Task.query.filter_by(token=_token).first()
     if not t:
         raise Exception('Task does not exist!')
     else:
         redis_client.delete(_token)
         redis_client.delete(Person.get_id(t.owner_id).token + '-tasks')
         db.session.delete(Task.get(t.token))
         db.session.commit()
         return 'Task deleted'