Beispiel #1
0
def quick_add_assignment(request, slug):
    form = QuickAddForm(request.POST or None)

    if form.is_valid():
        sheet = Sheet.objects.get(slug=slug)
        number_of_items = form.cleaned_data['number_of_items']
        for _ in range(number_of_items):
            Assignment.objects.create(sheet=sheet,
                                      name="A{0:d}".format(Assignment.objects.filter(sheet=sheet).count() + 1)).save()
        return redirect('sheet_detail', slug=slug)

    return render(request, 'quick_add.html', {
        'form': form
    })
Beispiel #2
0
def quick_add_problem(request, sheet_slug, assignment_slug, task_slug):
    form = QuickAddForm(request.POST or None)

    if form.is_valid():
        sheet = Sheet.objects.get(slug=sheet_slug)
        assignment = sheet.assignment_set.get(slug=assignment_slug)
        task = assignment.task_set.get(slug=task_slug)
        number_of_items = form.cleaned_data['number_of_items']
        for _ in range(number_of_items):
            Problem.objects.create(task=task,
                                   name="P{0:d}".format(Problem.objects.filter(task=task).count() + 1)).save()
        MarkAPI.delete_mark_sets(task)
        return redirect('sheet_detail', slug=sheet_slug)

    return render(request, 'quick_add.html', {
        'form': form
    })