Example #1
0
def add_owner(request, id):
    if request.POST:
        username = request.POST.get('owner')
        access_level = request.POST.get('access_level')
        try:
            queries.add_owners_to_task(request.user.username, id,
                                       [Owner(username, access_level)])
        except Exception as e:
            messages.error(request, str(e))
        return redirect('tasks:details', id=id)
 def test_add_subtasks_to_task(self):
     with self.assertRaises(PermissionError):
         queries.add_subtasks_to_task('user_readonly', self.task_1_id, [1])
     queries.add_subtasks_to_task(EXECUTOR, self.task_1_id,
                                  [self.task_2_id])
     self.assertTrue(queries.get_task(self.task_1_id).subtasks.filter(
         title='task_2').exists())
     owner = Owner(EXECUTOR, AccessLevels.EDIT.value)
     queries.add_owners_to_task(ADMINS_NAME, self.task_2_id, [owner])
     queries.add_owners_to_task(ADMINS_NAME, self.task_3_id, [owner])
     queries.add_subtasks_to_task(EXECUTOR, self.task_2_id,
                                  [self.task_3_id])
     with self.assertRaises(Looping):
         queries.add_subtasks_to_task(EXECUTOR, self.task_3_id,
                                      [self.task_1_id])
 def test_add_owners_to_task(self):
     owners = [
         Owner(EXECUTOR, AccessLevels.EDIT.value),
         Owner('user_readonly', AccessLevels.READONLY.value),
         Owner('user_2', AccessLevels.EDIT),
         Owner('user_3', AccessLevels.READONLY)
     ]
     queries.add_owners_to_task(ADMINS_NAME, self.task_1_id, owners)
     task = queries.get_task(self.task_1_id)
     self.assertEqual(
         len(task.user_set.all()),
         4
     )
     task_owners = [owner.name for owner in task.user_set.all()]
     some_people = [EXECUTOR, 'user_readonly', 'user_2', 'user_3']
     self.assertEqual(task_owners.sort(), some_people.sort())
Example #4
0
def add_task(request):
    form = TaskForm()
    if request.POST:
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.status = Statuses.INPROCESS.value
            task.created_by = request.user.username
            task.save()
            queries.add_owners_to_task(
                ADMINS_NAME, task.id,
                [Owner(request.user.username, AccessLevels.EDIT.value)])
            return redirect('tasks:all')
    filters_form = TaskFiltersForm()
    return render(request, 'nxtodoapp/task/task_add.html', {
        'form': form,
        'filters_form': filters_form
    })
Example #5
0
def share_task(user_name, args):
    queries.add_owners_to_task(user_name, args.id, args.owners)