def newcourse(request): if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception if (request.method == 'POST'): form = CourseForm(request.POST) if (form.is_valid()): form.save() return HttpResponseRedirect('/') else: form = CourseForm() return render(request, 'course/newcourse.html', {'form': form, }) else: return HTTP_401_UNAUTHORIZED_RESPONSE
def editcourse(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 = CourseForm(request.POST, instance=course) if (form.is_valid()): form_edit = form.save(commit=False) form_edit.save() return HttpResponseRedirect(PATHOKNEWCOURSE) else: form = CourseForm(instance=course) return render(request, 'course/editcourse.html', {'form': form, 'course': course}, context_instance=RequestContext(request)) else: return HTTP_401_UNAUTHORIZED_RESPONSE
def newcourse(request): if ( len(request.user.teacher_set.all()) > 0 ): # if an authenticated user "accidentally" access this section, he doesn't get an exception if (request.method == 'POST'): form = CourseForm(request.POST) if (form.is_valid()): form.save() return HttpResponseRedirect('/') else: form = CourseForm() return render(request, 'course/newcourse.html', { 'form': form, }) else: return HTTP_401_UNAUTHORIZED_RESPONSE
def editcourse(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 = CourseForm(request.POST, instance=course) if (form.is_valid()): form_edit = form.save(commit=False) form_edit.save() return HttpResponseRedirect(PATHOKNEWCOURSE) else: form = CourseForm(instance=course) return render(request, 'course/editcourse.html', { 'form': form, 'course': course }, context_instance=RequestContext(request)) else: return HTTP_401_UNAUTHORIZED_RESPONSE