コード例 #1
0
def newshift(request, idcourse):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        course = Course.objects.get(pk=idcourse)
        if (request.method=='POST'):
            form = ShiftForm(request.POST)
            if (form.is_valid()):
                form.save()
                return HttpResponseRedirect(PATHOKNEWCOURSE % course.id)
        else:
            form = ShiftForm(initial={'course':course})
        return render(request, 'shift/newshift.html', {'form': form, 'idcourse':idcourse})
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
コード例 #2
0
def editshift(request, idshift):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        shift = Shift.objects.get(pk=idshift)     
        if (request.method == 'POST'):
            form = ShiftForm(request.POST, instance = shift)
            if (form.is_valid()):
                form_edit = form.save(commit=False)
                form_edit.save()
                return HttpResponseRedirect(PATHOKNEWCOURSE % shift.course.id)
        else:
            form = ShiftForm(instance = shift)
        return render(request, 'shift/editshift.html', {'form': form, 'idcourse':shift.course.id})
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE