예제 #1
0
def add_reminders_to_plan(user_name, plan_id, reminders_ids):
    """Adds reminders to plan.

    :param user_name: users name, who makes query.
    :param plan_id: plan id
    :param reminders_ids: list of reminders ids

    """

    plan = get_plan(plan_id)
    for id in reminders_ids:
        reminder = get_reminder(id)
        relation = PlanReminders(plan=plan, reminder=reminder)
        relation.save()
예제 #2
0
def add_events_to_plan(user_name, plan_id, events_ids):
    """Adds events to plan.

    :param user_name: users name, who makes query
    :param plan_id: plan id
    :param events_ids: list of events ids

    """

    plan = get_plan(plan_id)
    for id in events_ids:
        event = get_event(id)
        add_participants_to_event(ADMINS_NAME, id, get_objects_owners(plan))
        event.prepare_to_plan()
        plan.events.add(event)
예제 #3
0
def remove_events_from_plan(username, plan_id, events_ids):

    """Remove events from plan.

    :param user_name: users name, who makes query
    :param plan_id: plan id
    :param events_ids: list of events ids

    """

    plan = get_plan(plan_id)
    for id in events_ids:
        event = get_event(id)
        event.status = Statuses.INPROCESS.value
        event.save()
        plan.events.remove(event)
예제 #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)
예제 #5
0
def remove_owners_from_plan(username, plan_id, owners):
    """Remove owners from plan.

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

    """

    plan = get_plan(plan_id)
    for owner in owners:
        user = get_user(owner)
        try:
            relation = UserPlans.objects.get(user=user, plan=plan)
            relation.delete()
        except:
            continue
예제 #6
0
def remove_reminders_from_plan(username, plan_id, reminders_ids):
    """Remove reminders from plan.

    :param user_name: users name, who makes query.
    :param plan_id: plan id
    :param reminders_ids: list of reminders ids

    """

    plan = get_plan(plan_id)
    for id in reminders_ids:
        reminder = get_reminder(id)
        try:
            relation = PlanReminders.objects.get(plan=plan, reminder=reminder)
            relation.delete()
        except:
            continue
예제 #7
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)
예제 #8
0
def add_owners_to_plan(user_name, plan_id, owners):
    """Adds owners to plan.

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

    """

    plan = get_plan(plan_id)
    for owner in owners:
        user = get_user(owner.user_name)
        relation = UserPlans(user=user,
                             plan=plan,
                             assign_date=datetime.now(),
                             access_level=owner.access_level)
        relation.save()
예제 #9
0
    def wrapper(username, plan_id, *args, **kwargs):
        if not username == ADMINS_NAME:
            user = get_user(username)
            plan = get_plan(plan_id)

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

            if relation.access_level == AccessLevels.EDIT.value:
                func(username, plan_id, *args, **kwargs)
            else:
                msg = ("Permission denied, you can't "
                       "edit '{}' plan.").format(plan.id)
                raise PermissionError(msg)
        else:
            func(username, plan_id, *args, **kwargs)
예제 #10
0
def edit_plan(user_name,
              plan_id,
              title=None,
              description=None,
              category=None,
              priority=None):
    """Edit plan

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

    """

    plan = get_plan(plan_id)
    if title:
        plan.title = title
    if description:
        plan.description = description
    if category:
        plan.category = category
    if priority:
        plan.priority = priority
    plan.save()
예제 #11
0
def remove_plan(user_name, plan_id):
    """
    Remove plan if it can be removed.
    """
    get_plan(plan_id).delete()