Exemple #1
0
def get_reminders(user, description=None, status=None, id=None, orderby=None):
    """
    Returns users reminders filtered by args.
    """
    user = get_user(user)
    filters = create_filters(id, description=description)
    selection = user.reminder_set.filter(**filters)

    if status == ReminderStatuses.ACTIVE.value:
        now = datetime.now()
        selection = selection.filter(start_remind_from__lte=now).\
            filter(stop_remind_in__gte=now)

    if status == ReminderStatuses.ARCHIVED.value:
        now = datetime.now()
        part_one = selection.filter(start_remind_from__gt=now)
        part_two = selection.filter(stop_remind_in__lt=now)
        selection = list(chain(part_one, part_two))

    if orderby:
        selection = selection.order_by(orderby)

    if not len(selection):
        raise ObjectDoesNotFound('There is no reminders '
                                 'with selected filters.')
    return selection
Exemple #2
0
def get_user(name):
    """
    Returns user by name.
    """
    try:
        return User.objects.get(name=name)
    except ObjectDoesNotExist:
        raise ObjectDoesNotFound("There is no user '{}'.".format(name))
Exemple #3
0
def get_reminder(reminder_id):
    """
    Returns reminder by id.
    """
    try:
        return Reminder.objects.get(id=reminder_id)
    except ObjectDoesNotExist:
        raise ObjectDoesNotFound(
            'There is no reminder with id={}.'.format(reminder_id))
Exemple #4
0
def get_plan(plan_id):
    """
    Returns plan by id.
    """
    try:
        return Plan.objects.get(id=plan_id)
    except ObjectDoesNotExist:
        raise ObjectDoesNotFound(
            'There is no plan with id={}.'.format(plan_id))
Exemple #5
0
def get_event(event_id):
    """
    Returns event by id.
    """
    try:
        return Event.objects.get(id=event_id)
    except ObjectDoesNotExist:
        raise ObjectDoesNotFound(
            'There is no event with id={}.'.format(event_id))
Exemple #6
0
def get_task(task_id):
    """
    Returns task by id.
    """
    try:
        return Task.objects.get(id=task_id)
    except ObjectDoesNotExist:
        raise ObjectDoesNotFound(
            'There is no task with id={}.'.format(task_id))
Exemple #7
0
def get_users(name=None):
    """
    Returns users by name, all users when 'name' argument is None.
    """
    filters = create_filters(name=name)
    selection = User.objects.filter(**filters)
    if not len(selection):
        raise ObjectDoesNotFound('There is no users with selected filters.')
    return selection
Exemple #8
0
def get_plans(user,
              title=None,
              category=None,
              priority=None,
              status=None,
              id=None,
              orderby=None):
    """
    Returns users plans filtered by args.
    """
    user = get_user(user)
    filters = create_filters(id, title, category, priority, status)
    selection = user.plans.filter(**filters)

    if orderby:
        selection = selection.order_by(orderby)

    if not len(selection):
        raise ObjectDoesNotFound('There is no plans with selected filters.')
    return selection
Exemple #9
0
def get_events(user,
               title=None,
               category=None,
               fromdt=None,
               priority=None,
               status=None,
               place=None,
               id=None,
               orderby=None):
    """
    Returns users events filtered by args.
    """
    user = get_user(user)
    filters = create_filters(id, title, category, priority, status, place)
    selection = user.events.filter(**filters)
    if fromdt:
        selection = selection.filter(from_datetime__lte=fromdt)

    if orderby:
        selection = selection.order_by(orderby)

    if not len(selection):
        raise ObjectDoesNotFound('There is no events with selected filters.')
    return selection