Exemplo n.º 1
0
def plan_details(request, id):
    try:
        plan = queries.get_plan(id)
    except:
        return redirect('plans:details', id=id)
    access_level = UserPlans.objects.get(user=queries.get_user(
        request.user.username),
                                         plan=plan).access_level
    readonly = True if access_level == AccessLevels.READONLY.value else False

    owner_form = OwnersForm(request.user.username)
    reminder_form = ReminderForm(request.user.username, id, Entities.PLAN)
    task_form = PlansTaskForm(request.user.username, None)
    event_form = PlansEventForm(request.user.username, None)
    filters_form = PlanFiltersForm()

    return render(
        request, 'nxtodoapp/plan/plan_details.html', {
            "plan": plan,
            "owner_form": owner_form,
            "reminder_form": reminder_form,
            "plan_owners": queries.get_objects_owners(plan),
            "task_form": task_form,
            "event_form": event_form,
            "filters_form": filters_form,
            "readonly": readonly
        })
Exemplo n.º 2
0
def task_details(request, id):
    try:
        task = queries.get_task(id)
    except:
        return redirect('tasks:details', id=id)
    access_level = UserTasks.objects.get(user=queries.get_user(
        request.user.username),
                                         task=task).access_level
    readonly = True if access_level == AccessLevels.READONLY.value else False

    subtask_form = SubtaskForm(request.user.username, id)
    owner_form = OwnersForm(request.user.username)
    reminder_form = ReminderForm(request.user.username, id, Entities.TASK)
    filters_form = TaskFiltersForm()

    return render(
        request, 'nxtodoapp/task/task_details.html', {
            "task": task,
            "subtask_form": subtask_form,
            "owner_form": owner_form,
            "reminder_form": reminder_form,
            "task_owners": queries.get_objects_owners(task),
            "filters_form": filters_form,
            "readonly": readonly
        })
Exemplo n.º 3
0
 def get_choices(self, username, plan_id):
     choices = ()
     user = queries.get_user(username)
     for event in user.events.all():
         choices += ((event.id,
                      event.title + ' ({})'.format(str(event.id))), )
     return choices
Exemplo n.º 4
0
 def get_choices(self, username, obj_id, obj_type):
     choices = ()
     user = queries.get_user(username)
     if obj_type == Entities.TASK:
         entity = queries.get_task(obj_id)
     if obj_type == Entities.EVENT:
         entity = queries.get_event(obj_id)
     if obj_type == Entities.PLAN:
         entity = queries.get_plan(obj_id)
     ids_for_exclude = [reminder.id for reminder in entity.reminders.all()]
     for reminder in user.reminder_set.all().exclude(
             id__in=ids_for_exclude):
         choices += ((reminder.id, reminder.id), )
     return choices
Exemplo n.º 5
0
def event_details(request, id):
    try:
        event = queries.get_event(id)
    except:
        return redirect('events:details', id=id)
    access_level = UserEvents.objects.get(user=queries.get_user(
        request.user.username),
                                          event=event).access_level
    readonly = True if access_level == AccessLevels.READONLY.value else False

    owner_form = OwnersForm(request.user.username)
    reminder_form = ReminderForm(request.user.username, id, Entities.EVENT)
    filters_form = EventFiltersForm()

    return render(
        request, 'nxtodoapp/event/event_details.html', {
            "event": event,
            "owner_form": owner_form,
            "reminder_form": reminder_form,
            "event_participants": queries.get_objects_owners(event),
            "filters_form": filters_form,
            "readonly": readonly
        })
Exemplo n.º 6
0
def add_reminder(request):
    form = ReminderForm()
    if request.POST:
        form = ReminderForm(request.POST)
        if form.is_valid():
            reminder = form.save(commit=False)

            #some logic before saving
            if not reminder.start_remind_from:
                reminder.start_remind_from = datetime.now()
            if not reminder.stop_remind_in:
                reminder.stop_remind_in = datetime.max
            weekdays_str = request.POST.getlist('form_weekdays')
            reminder.weekdays = list(map(int, weekdays_str))
            reminder.user = queries.get_user(request.user.username)

            reminder.save()
            return redirect('reminders:all')
    filters_form = ReminderFiltersForm()
    return render(request, 'nxtodoapp/reminder/reminder_add.html', {
        'form': form,
        "filters_form": filters_form
    })
 def test_remove_user(self):
     queries.remove_user('user_1')
     with self.assertRaises(ObjectDoesNotFound):
         queries.get_user('user_1')
Exemplo n.º 8
0
 def get_choices(self, username, task_id):
     choices = ()
     user = queries.get_user(username)
     for task in user.tasks.all().exclude(id__in=[task_id]):
         choices += ((task.id, task.title + ' ({})'.format(str(task.id))), )
     return choices
Exemplo n.º 9
0
 def get_choices(self, username, plan_id):
     choices = ()
     user = queries.get_user(username)
     for task in user.tasks.all():
         choices += ((task.id, task.title + ' ({})'.format(str(task.id))), )
     return choices
Exemplo n.º 10
0
 def test_get_user(self):
     self.assertEqual(queries.get_user(EXECUTOR).name, EXECUTOR)