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 })
def test_edit_plan(self): with self.assertRaises(PermissionError): queries.edit_plan('user_readonly', self.plan_id, 'new_title') queries.edit_plan(EXECUTOR, self.plan_id, description='description') self.assertEqual( queries.get_plan(self.plan_id).description, 'description')
def edit_plan(request, id): plan = queries.get_plan(id) form = PlanForm(instance=plan) if request.POST: form = PlanForm(request.POST, instance=plan) if form.is_valid(): plan = form.save(commit=False) plan.save() return redirect('plans:details', id=plan.id) filters_form = PlanFiltersForm() return render(request, 'nxtodoapp/plan/plan_edit.html', { 'form': form, 'filters_form': filters_form })
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
def test_remove_plan(self): with self.assertRaises(PermissionError): queries.remove_plan('user_readonly', self.plan_id) queries.remove_plan(EXECUTOR, self.plan_id) with self.assertRaises(ObjectDoesNotFound): queries.get_plan(self.plan_id)
def test_add_tasks_to_plan(self): owner = Owner(EXECUTOR, AccessLevels.EDIT.value) queries.add_owners_to_plan(ADMINS_NAME, self.plan_id, [owner]) queries.add_tasks_to_plan(EXECUTOR, self.plan_id, [self.task_2_id, self.task_3_id]) self.assertEqual(len(queries.get_plan(self.plan_id).tasks.all()), 2)