def course_detail(request, pk): # deny access for certain users if request.user.is_student or \ request.user.is_superuser: return HttpResponseForbidden() courses = Course.objects.filter(instructor=request.user) courses = courses.filter(pk=pk) for course in courses: assignments = Assignment.objects.filter(course=course) c_form = False for course in courses: c_form = CourseForm(instance=course) # pass current data if request.method == 'POST': request.POST = request.POST.copy() # copy post and make it mutable c_form = CourseForm(request.POST, instance=course) # pass user data c_form.data["instructor"] = request.user # save current user c_form.data["code"] = course.code # save current course if c_form.is_valid(): c_form.save() return redirect('instructor:course_detail', pk=pk) return render(request, 'instructor/class.html', { 'pk': pk, 'c_form': c_form, 'courses': courses, 'assignments': assignments })
def course(request, course_slug=None): if not ALLOW_USER_COURSE_CREATION: request.user.message_set.create(message="Course creation has been \ disabled") return HttpResponseRedirect(reverse("course_list")) if course_slug: course = get_object_or_404(Course, slug=course_slug) template = 'courses/courses/edit.html' else: course = None template = 'courses/courses/create.html' if request.method == 'POST': form = CourseForm(request.POST, instance=course) if form.is_valid(): if course: form.save() request.user.message_set.create(message="Course changes have \ been saved") else: if form.cleaned_data['privacy'] == u'E': form.cleaned_data['moderated'] = True course = form.save() t = Teachership(course=course, teacher=request.user, is_owner=True) t.save() request.user.message_set.create(message="Your course has been \ created. It will not be visible to other users until you \ activate it.") return HttpResponseRedirect(course.get_absolute_url()) form = CourseForm(instance=course) return render_to_response(template, { 'form': form, 'course': course }, context_instance=RequestContext(request))
def addcourse(request): if request.method=="POST": form=CourseForm(request.POST) if form.is_valid(): form.save() course_name=form.cleaned_data.get('course_name') # return HttpResponse('%s course is successfully added..!'%(course_name)) messages.success(request, '%s course is successfully added..!'%(course_name)) return redirect('showcourses') form=CourseForm() return render(request,'courses/addcourse.html',{"form":form})
def course_detail(request): # deny access for certain users if request.user.is_student or \ request.user.is_superuser: return HttpResponseForbidden() courses = Course.objects.filter(instructor=request.user) if request.method == 'POST': c_form = CourseForm(request.POST) if c_form.is_valid(): c_form.save() return HttpResponseRedirect(reverse_lazy('instructor:instructor')) return render(request, 'instructor/class.html', {'courses': courses})
def courseedit(request,id): data=Course.objects.get(id=id) if request.method=="POST": form=CourseForm(request.POST,instance=data) if form.is_valid(): form.save() course_name=form.cleaned_data.get('course_name') # return HttpResponse('%s course is successfully updated'%(course_name)) messages.warning(request,'%s course is successfully updated'%(course_name)) return redirect('showcourses') form=CourseForm(instance=data) context={ 'data':data, 'form':form } return render(request,'courses/courseedit.html',context)
def show_courses(request): # if not request.user.is_authenticated: # messages.warning(request, 'Login First') # return redirect('login') courses = Course.objects.all() types = Type.objects.all() # courses = Course.objects.filter(fee__lte=13000) # courses = Course.objects.get(id=1) if request.method == 'POST': form = CourseForm(request.POST) form.save() messages.success(request, 'Course added') return redirect('courses') form = CourseForm() return render(request, 'courses.html', {'courses': courses, 'form': form, 'types': types, 'MEDIA_URL': MEDIA_URL})
def post(self, request): course_form = CourseForm(request.data) if course_form.is_valid(): course = course_form.save(commit=False) course.author = Teacher.objects.first() course.save() page = Page(name="Première page", order=1, course_id=course.id) page.save() page.sections.create(name="Première section", order=1) return Http201(self.serialize(course))
def course_add(request): if request.POST: form = CourseForm(request.POST) if form.is_valid(): new_course = form.save() return HttpResponseRedirect(new_course.get_absolute_url()) else: form = CourseForm() return render(request, 'courses/course_form.html', { 'form': form, })
def create_course(request): form = CourseForm() if request.method == 'POST': form = CourseForm(data=request.POST) if form.is_valid(): course = form.save(commit=False) course.owner = request.user course.save() messages.success(request, 'Course created successfully!') return redirect('/courses/') return render(request, 'create_course.html', {'form': form})
def create_course(request): form = CourseForm() if request.method == 'POST': form = CourseForm(data=request.POST) if form.is_valid(): course = form.save(commit=False) course.owner = request.user course.save() messages.success(request, 'Course created successfully!') return redirect('/courses/') return render(request, 'create_course.html', {'form': form})
def post(self, request): course_form = CourseForm(request.data) if course_form.is_valid(): course = course_form.save(commit=False) course.author = request.user course.save() # Crée une page vierge page = Page(name="Première page", order=1, course_id=course.id) page.save() # Crée une section dans la page page.sections.create(name="Première section", order=1) return Http201(self.serialize(course))
def create_course(request): # deny access for certain users if request.user.is_student or \ request.user.is_superuser: return HttpResponseForbidden() c_form = CourseForm() courses = Course.objects.filter(instructor=request.user) if request.method == 'POST': request.POST = request.POST.copy() # copy post and make it mutable c_form = CourseForm(request.POST) c_form.data["instructor"] = request.user # save current user if c_form.is_valid(): c_form.save() return HttpResponseRedirect(reverse_lazy('instructor:instructor')) return render(request, 'instructor/home.html', { 'c_form': c_form, 'courses': courses })
def course(request, course_slug=None): if not ALLOW_USER_COURSE_CREATION: request.user.message_set.create(message="Course creation has been \ disabled") return HttpResponseRedirect(reverse("course_list")) if course_slug: course = get_object_or_404(Course, slug=course_slug) template = 'courses/courses/edit.html' else: course = None template = 'courses/courses/create.html' if request.method == 'POST': form = CourseForm(request.POST, instance=course) if form.is_valid(): if course: form.save() request.user.message_set.create(message="Course changes have \ been saved") else: if form.cleaned_data['privacy'] == u'E': form.cleaned_data['moderated'] = True course = form.save() t = Teachership(course=course, teacher=request.user, is_owner=True) t.save() request.user.message_set.create(message="Your course has been \ created. It will not be visible to other users until you \ activate it.") return HttpResponseRedirect(course.get_absolute_url()) form = CourseForm(instance=course) return render_to_response(template, { 'form': form, 'course': course }, context_instance=RequestContext(request))
def RegisterCourse(request): if request.method =='POST': form = CourseForm(request.POST,request.FILES) if form.is_valid(): newCourse = form.save(commit=False) newCourse.save(user = request.user) #CreateCourseMembership.send(sender = Course,instance=newCourse,user=request.user,created = True) return redirect(reverse('course_home_url', args(newCourse.id,))) # Redirect after POST else: form = CourseForm() # An unbound form return render_to_response('courses/register.html', { 'form': form, },context_instance=RequestContext(request))
def add_course(request): if request.POST: form = CourseForm(request.POST) if form.is_valid(): new_course = form.save(commit=False) new_course.instructor_id = Instructor.objects.get( instructor_id=request.user.id).id new_course.save() return HttpResponseRedirect(new_course.get_absolute_url()) else: raise Http404 else: form = CourseForm() return render(request, 'courses/course_form.html', { 'form': form, })
def RegisterCourse(request): if request.method =='POST': form = CourseForm(request.POST,request.FILES) if form.is_valid(): newCourse = form.save(commit=False) newCourse.save(user = request.user) #No event on course creation - only one follower - actor himself. #Just add a follower after the CourseMembership table has been popoulated, return redirect(reverse('course_home', args=(newCourse.id,))) # Redirect after POST else: form = CourseForm() # An unbound form return render_to_response('courses/register.html', { 'form': form, },context_instance=RequestContext(request))
def RegisterCourse(request): if request.method == 'POST': form = CourseForm(request.POST, request.FILES) if form.is_valid(): newCourse = form.save(commit=False) newCourse.save(user=request.user) #No event on course creation - only one follower - actor himself. #Just add a follower after the CourseMembership table has been popoulated, return redirect(reverse( 'course_home', args=(newCourse.id, ))) # Redirect after POST else: form = CourseForm() # An unbound form return render_to_response('courses/register.html', { 'form': form, }, context_instance=RequestContext(request))
def course_add(request): if request.POST: form = CourseForm(request.POST) if form.is_valid(): new_course = form.save() return HttpResponseRedirect(new_course.get_absolute_url())