Beispiel #1
0
def diary_create(request, childcare_id, classroom_id):
    childcare = get_object_or_404(Childcare, pk=childcare_id)
    classroom = get_object_or_404(Classroom, pk=classroom_id)
    if request.method == 'POST':
        form = DiaryCreateForm(data=request.POST)
        if form.is_valid():
            try:
                obj = form.save(commit=False)
                obj.classroom = classroom
                obj.author = request.user
                obj.save()
                form.save(commit=True)
                return HttpResponseRedirect(
                    '/childcare/%s/classroom/%s/diary/' %
                    (childcare_id, classroom_id))
            except IntegrityError:
                return render(request,
                              'classroom/error_diary_already_written.html', {
                                  'childcare': childcare,
                                  'classroom': classroom
                              })
    else:
        form = DiaryCreateForm()
    return render(request, 'classroom/diary_create.html', {
        'form': form,
        'childcare': childcare,
        'classroom': classroom
    })
Beispiel #2
0
def diary_create(request, childcare_slug):
    childcare = get_object_or_404(Childcare, slug=childcare_slug)
    if request.method == 'POST':
        form = DiaryCreateForm(data=request.POST, childcare=childcare)
        if form.is_valid():
            try:
                obj = form.save(commit=False)
                obj.author = request.user
                obj.save()
                diary = form.save(commit=True)
                log.info(log_prefix+'Diary created (childcare: %s, user: %s)' % (childcare.name, request.user))
                return HttpResponseRedirect(reverse('childcare:diary_list', kwargs={'childcare_slug': childcare.slug}))
            except IntegrityError:
                return render(request, 'classroom/error_diary_already_written.html', {'childcare': childcare})
    else:
        form = DiaryCreateForm(childcare=childcare)
    return render(request, 'classroom/diary_create.html', {'form': form,
                                                           'childcare': childcare})
Beispiel #3
0
def diary_create(request, childcare_id, classroom_id):
    childcare = get_object_or_404(Childcare, pk=childcare_id)
    classroom = get_object_or_404(Classroom, pk=classroom_id)
    if request.method == 'POST':
        form = DiaryCreateForm(data=request.POST)
        if form.is_valid():
            try:
                obj = form.save(commit=False)
                obj.classroom = classroom
                obj.author = request.user
                obj.save()
                form.save(commit=True)
                return HttpResponseRedirect('/childcare/%s/classroom/%s/diary/' % (childcare_id, classroom_id))
            except IntegrityError:
                return render(request, 'classroom/error_diary_already_written.html', {
                                                           'childcare': childcare,
                                                           'classroom': classroom})
    else:
        form = DiaryCreateForm()
    return render(request, 'classroom/diary_create.html', {'form': form,
                                                           'childcare': childcare,
                                                           'classroom': classroom})