def update(self, task):
     Task.update(title=task.title,
                 note=task.note,
                 start_time=task.start_time,
                 end_time=task.end_time,
                 assigned_user_id=task.assigned_user_id,
                 is_event=task.is_event,
                 category_id=task.category_id,
                 priority=task.priority,
                 status=task.status,
                 parent_task_id=task.parent_task_id,
                 updated_at=datetime.datetime.now()).where(
                     Task.id == task.id).execute()
    def can_write(self, user_id):
        """Returns tasks that user can read and change"""

        return list(
            map(
                self.to_task_instance,
                list(Task.select().join(UsersWriteTasks).where(
                    UsersWriteTasks.task_id == Task.id,
                    UsersWriteTasks.user_id == user_id))))
    def can_read(self, user_id):
        """Returns tasks that user can read"""

        return list(
            map(
                self.to_task_instance,
                list(Task.select().join(UsersReadTasks).where(
                    UsersReadTasks.task_id == Task.id,
                    UsersReadTasks.user_id == user_id))))
    def inner(self, task_id, recursive=False):
        """Returns inner tasks for task with ID == task_id"""
        if recursive:
            queue = deque()
            queue.append(self.get_by_id(task_id))
            inner_tasks = []
            return self.recursive_inner(queue, inner_tasks)

        return list(
            map(self.to_task_instance,
                list(Task.select().where(Task.parent_task_id == task_id))))
    def filter(self, *args):
        """
        Before usage you should import Task from tmlib.storage.storage_models module.
        Then you can pass filter query.
        If you want to filter multiple fields use bitwise operators (& and |) rather than logical operators (and and or).

        Example:
        filter(Task.title.contains('title') & Task.created_at > datetime.datetime.now())
        """

        return list(map(self.to_task_instance,
                        list(Task.select().where(args))))
    def process_notifications(self):
        """Changes notification status from CREATED to PENDING if it's time to show notification"""

        for notification in Notification.select().where(
                Notification.status == NotificationStatus.CREATED.value).join(
                    Task).where(Task.id == Notification.task_id):
            task = Task.get(Task.id == notification.task_id)
            if (task.start_time - datetime.timedelta(
                    seconds=notification.relative_start_time)
                ) < datetime.datetime.now():
                notification.status = NotificationStatus.PENDING.value
                notification.save()
 def create(self, task):
     return self.to_task_instance(
         Task.create(id=task.id,
                     user_id=task.user_id,
                     title=task.title,
                     note=task.note,
                     start_time=task.start_time,
                     end_time=task.end_time,
                     assigned_user_id=task.assigned_user_id,
                     parent_task_id=task.parent_task_id,
                     is_event=task.is_event,
                     category_id=task.category_id,
                     priority=task.priority,
                     status=task.status,
                     plan_id=task.plan_id))
Exemple #8
0
 def test_creates_task(self):
     before_tasks_count = Task.select().count()
     self.task_storage.create(self.task)
     after_tasks_count = Task.select().count()
     self.assertEqual(before_tasks_count + 1, after_tasks_count)
 def with_status(self, user_id, status):
     return list(
         map(
             self.to_task_instance,
             list(Task.select().where(Task.user_id == user_id,
                                      Task.status == status))))
 def assigned(self, user_id):
     return list(
         map(self.to_task_instance,
             list(Task.select().where(Task.assigned_user_id == user_id))))
 def user_tasks(self, user_id):
     return list(
         map(self.to_task_instance,
             list(Task.select().where(Task.user_id == user_id))))
Exemple #12
0
 def test_assignes_task_on_user(self):
     user_id = 5
     task_id = self.tasks_controller.create(self.task).id
     self.tasks_controller.assign_task_on_user(task_id, user_id)
     self.assertEqual(
         Task.select().where(Task.assigned_user_id == user_id).count(), 1)
 def delete_by_id(self, task_id):
     Task.delete().where(Task.id == task_id).execute()
     TaskPlan.delete().where(TaskPlan.task_id == task_id).execute()
 def created_by_task_plan(self, user_id, plan_id):
     return list(
         map(
             self.to_task_instance,
             list(Task.select().where(Task.user_id == user_id,
                                      Task.plan_id == plan_id))))
Exemple #15
0
 def test_deletes_task_by_id(self):
     task_id = self.task_storage.create(self.task).id
     self.task_storage.delete_by_id(task_id)
     self.assertEqual(Task.select().where(Task.id == task_id).count(), 0)
Exemple #16
0
 def test_updates_task(self):
     task_with_id = self.task_storage.create(self.task)
     task_with_id.title = "Do something great"
     self.task_storage.update(task_with_id)
     task_from_db = Task.get(Task.id == task_with_id.id)
     self.assertEqual(task_from_db.title, "Do something great")
 def get_by_id(self, task_id):
     try:
         return self.to_task_instance(Task.get(Task.id == task_id))
     except DoesNotExist:
         return None