Esempio n. 1
0
def edit_task(user_name,
              task_id,
              title=None,
              description=None,
              category=None,
              deadline=None,
              priority=None):
    """Edit task

    If the next argument is not None, then change the corresponding
    field to a new value.

    """

    task = get_task(task_id)
    if title:
        task.title = title
    if description:
        task.description = description
    if category:
        task.category = category
    if deadline:
        task.deadline = deadline
    if priority:
        task.priority = priority
    task.save()
Esempio n. 2
0
def add_subtasks_to_task(user_name, task_id, subtasks_ids):
    """Adds subtasks to task.

    :param user_name: users name, who makes query
    :param task_id: task id
    :param subtasks_ids: list of subtasks ids
    :return:

    """

    task = get_task(task_id)
    for id in subtasks_ids:
        subtask = get_task(id)
        if not subtask.check_cycles(task):
            task.subtasks.add(subtask)
        else:
            msg = ("You can't add subtask id={} to task id={}, because "
                   "the task id={} already exists in the subtasks of the "
                   "task id={}").format(id, task_id, task_id, id)
            raise Looping(msg)
Esempio n. 3
0
def add_reminders_to_task(user_name, task_id, reminders_ids):
    """Adds reminders to task.

    :param user_name: users name, who makes query
    :param task_id: task id
    :param reminders_ids: list of reminders ids
    :return:

    """

    task = get_task(task_id)
    for id in reminders_ids:
        reminder = get_reminder(id)
        relation = TaskReminders(task=task, reminder=reminder)
        relation.save()
Esempio n. 4
0
def add_tasks_to_plan(user_name, plan_id, tasks_ids):
    """Adds tasks to plan.

    :param user_name: users name, who makes query.
    :param plan_id: plan id
    :param tasks_ids: list of tasks ids
    :return:

    """

    plan = get_plan(plan_id)
    for id in tasks_ids:
        task = get_task(id)
        add_owners_to_task(ADMINS_NAME, id, get_objects_owners(plan))
        task.prepare_to_plan()
        plan.tasks.add(task)
Esempio n. 5
0
def remove_tasks_from_plan(username, plan_id, tasks_ids):

    """Removes tasks from plan.

    :param user_name: users name, who makes query.
    :param plan_id: plan id
    :param tasks_ids: list of tasks ids
    :return:

    """

    plan = get_plan(plan_id)
    for id in tasks_ids:
        task = get_task(id)
        task.status = Statuses.INPROCESS.value
        task.save()
        plan.tasks.remove(task)
Esempio n. 6
0
def remove_owners_from_task(username, task_id, owners):

    """Removes owners from task.

    :param user_name: users name, who makes query
    :param task_id: task id
    :param owners: list of owners

    """

    task = get_task(task_id)
    for owner in owners:
        user = get_user(owner)
        try:
            relation = UserTasks.objects.get(user=user, task=task)
            relation.delete()
        except:
            continue
Esempio n. 7
0
def duplicate_task(executor, task, created_at):
    """Duplicate existing task: get owners, reminders attached to task
    and simply add a new one.

    :param executor: who duplicates a task
    :param task: task to duplicate
    :param created_at: datetime in which task will be created

    """

    owners = get_objects_owners(task)
    reminders = [reminder.id for reminder in task.reminders.all()]
    executor = "{}(Plan)".format(executor)
    task_id = add_task(executor, task.title, task.description, task.category,
                       task.deadline, task.priority, owners, reminders)
    new_task = get_task(task_id)
    new_task.created_at = created_at
    new_task.save()
Esempio n. 8
0
    def wrapper(username, task_id, *args, **kwargs):
        if not username == ADMINS_NAME:
            user = get_user(username)
            task = get_task(task_id)

            try:
                relation = UserTasks.objects.get(user=user, task=task)
            except ObjectDoesNotExist:
                msg = ("Invalid operation, you are not the owner "
                       "of the '{}' task.").format(task.id)
                raise PermissionError(msg)

            if relation.access_level == AccessLevels.EDIT.value:
                func(username, task_id, *args, **kwargs)
            else:
                msg = ("Permission denied, you can't "
                       "edit '{}' task.").format(task.id)
                raise PermissionError(msg)
        else:
            func(username, task_id, *args, **kwargs)
Esempio n. 9
0
def add_owners_to_task(user_name, task_id, owners):
    """Adds owners to task.

    :param user_name: users name, who makes query
    :param task_id: task id
    :param owners: list of owners
    :return:

    """

    task = get_task(task_id)
    for owner in owners:
        user = get_user(owner.user_name)
        try:
            relation = UserTasks.objects.get(user=user, task=task)
        except:
            relation = UserTasks(user=user,
                                 task=task,
                                 assign_date=datetime.now(),
                                 access_level=owner.access_level)
            relation.save()