def change_live_datetime(request): list_type = request.POST.get('list_type') action = request.POST.get('action') form = LiveDateForm(request.POST) if form.is_valid(): if action == "Make Ready and Go Live": new_live_datetime = datetime.now() elif action == "Set Live Date": new_live_datetime = form.cleaned_data['live_datetime'] else: new_live_datetime = None ids = request.POST.get("change_live_datetime_ids").split(",") for id in ids: parts = id.split('_') if parts[0] == 'video': content = Video.objects.get(id=parts[1]) elif parts[0] == 'problemset': content = ProblemSet.objects.get(id=parts[1]) elif parts[0] == 'additionalpage': content = AdditionalPage.objects.get(id=parts[1]) elif parts[0] == 'file': content = File.objects.get(id=parts[1]) elif parts[0] == 'exam': content = Exam.objects.get(id=parts[1]) if action == "Make Ready and Go Live" and parts[0] != 'file': content.commit() content.live_datetime = new_live_datetime content.image.live_datetime = new_live_datetime content.save() content.image.save() if list_type == 'course_materials': return redirect('courses.views.course_materials', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) elif list_type == 'problemsets': return redirect('problemsets.views.listAll', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) else: return redirect('courses.videos.views.list', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) #This won't work anymore because referer could be /change_live_datetime if it's an invalid form post #return redirect(request.META['HTTP_REFERER']) if list_type == 'course_materials': section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True, get_exam_content=True) template = 'courses/draft/course_materials.html' elif list_type == 'problemsets': section_structures = get_course_materials(common_page_data=request.common_page_data, get_pset_content=True) template = 'problemsets/draft/list.html' else: section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True) template = 'videos/draft/list.html' return render(request, template, {'common_page_data': request.common_page_data, 'section_structures': section_structures, 'form': form})
def change_live_datetime(request): list_type = request.POST.get('list_type') action = request.POST.get('action') form = LiveDateForm(request.POST) if form.is_valid(): if action == "Make Ready and Go Live": new_live_datetime = datetime.now() elif action == "Set Live Date": new_live_datetime = form.cleaned_data['live_datetime'] else: new_live_datetime = None ids = request.POST.get("change_live_datetime_ids").split(",") for id in ids: parts = id.split('_') if parts[0] == 'video': content = Video.objects.get(id=parts[1]) elif parts[0] == 'problemset': content = ProblemSet.objects.get(id=parts[1]) elif parts[0] == 'additionalpage': content = AdditionalPage.objects.get(id=parts[1]) elif parts[0] == 'file': content = File.objects.get(id=parts[1]) if action == "Make Ready and Go Live" and parts[0] != 'file': content.commit() content.live_datetime = new_live_datetime content.image.live_datetime = new_live_datetime content.save() content.image.save() if list_type == 'course_materials': return redirect('courses.views.course_materials', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) elif list_type == 'problemsets': return redirect('problemsets.views.listAll', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) else: return redirect('courses.videos.views.list', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) #This won't work anymore because referer could be /change_live_datetime if it's an invalid form post #return redirect(request.META['HTTP_REFERER']) if list_type == 'course_materials': section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True) template = 'courses/draft/course_materials.html' elif list_type == 'problemsets': section_structures = get_course_materials(common_page_data=request.common_page_data, get_pset_content=True) template = 'problemsets/draft/list.html' else: section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True) template = 'videos/draft/list.html' return render(request, template, {'common_page_data': request.common_page_data, 'section_structures': section_structures, 'form': form})
def save_content_order(request): try: common_page_data = get_common_page_data( request, request.POST.get("course_prefix"), request.POST.get("course_suffix") ) except: raise Http404 if not common_page_data["is_course_admin"]: return redirect("courses.views.main", request.POST.get("course_prefix"), request.POST.get("course_suffix")) section_structures = get_course_materials( common_page_data=common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True, get_exam_content=True, ) for section_structure in section_structures: if section_structure["section"].id == long(request.POST.get("section_id")): for item in section_structure["items"]: if item["type"] == "video": item["video"].index = request.POST.get("order_video_" + str(item["video"].id)) item["video"].save() video_image = item["video"].image video_image.index = request.POST.get("order_video_" + str(item["video"].id)) video_image.save() elif item["type"] == "problem_set": item["problem_set"].index = request.POST.get("order_problem_set_" + str(item["problem_set"].id)) item["problem_set"].save() problem_set_image = item["problem_set"].image problem_set_image.index = request.POST.get("order_problem_set_" + str(item["problem_set"].id)) problem_set_image.save() elif item["type"] == "additional_page": item["additional_page"].index = request.POST.get( "order_additional_page_" + str(item["additional_page"].id) ) item["additional_page"].save() additional_page_image = item["additional_page"].image additional_page_image.index = request.POST.get( "order_additional_page_" + str(item["additional_page"].id) ) additional_page_image.save() elif item["type"] == "file": item["file"].index = request.POST.get("order_file_" + str(item["file"].id)) item["file"].save() file_image = item["file"].image file_image.index = request.POST.get("order_file_" + str(item["file"].id)) file_image.save() elif item["type"] == "exam": item["exam"].index = request.POST.get("order_exam_" + str(item["exam"].id)) item["exam"].save() exam_image = item["exam"].image exam_image.index = request.POST.get("order_exam_" + str(item["exam"].id)) exam_image.save() break return redirect(request.META["HTTP_REFERER"])
def list(request, course_prefix, course_suffix): try: common_page_data = get_common_page_data(request, course_prefix, course_suffix) except: raise Http404 if 'id' in request.GET: #process Video model instance with this youtube id #and other stuff try: video = Video.objects.get(pk=request.GET['vid']) except Video.DoesNotExist: raise Http404 video.url = request.GET['id'] video.save() video.create_ready_instance() section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('videos/'+common_page_data['course_mode']+'/list.html', {'common_page_data': common_page_data, 'section_structures':section_structures, 'context':'video_list', 'form': form}, context_instance=RequestContext(request))
def listAll(request, course_prefix, course_suffix, show_types=["exam",]): course = request.common_page_data['course'] if course.mode == "draft": #draft mode, lists grades exams = list(Exam.objects.filter(course=course, is_deleted=0, exam_type__in=show_types)) #if course.mode=="live": #exams = filter(lambda item: item.is_live(), exams) scores = [] for e in exams: if ExamScore.objects.filter(course=course, exam=e, student=request.user).exists(): scores.append(ExamScore.objects.filter(course=course, exam=e, student=request.user)[0].score) else: scores.append(None) return render_to_response('exams/list.html', {'common_page_data':request.common_page_data, 'course':course, 'exams_and_scores':zip(exams,scores)}, RequestContext(request)) else: #ready mode, uses section structures section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=False, get_exam_content=True, exam_types=show_types) form = None if show_types: ex_type = show_types[0] else: ex_type = "exam" return render_to_response('exams/ready/list.html', {'common_page_data': request.common_page_data, 'section_structures':section_structures, 'reverse_show':ex_type+'_show', 'form':form, }, context_instance=RequestContext(request))
def list(request, course_prefix, course_suffix): try: common_page_data = get_common_page_data(request, course_prefix, course_suffix) except: raise Http404 if "id" in request.GET: # process Video model instance with this youtube id # and other stuff try: video = Video.objects.get(pk=request.GET["vid"]) except Video.DoesNotExist: raise Http404 video.url = request.GET["id"] video.save() video.create_ready_instance() section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=True) form = None if request.common_page_data["course_mode"] == "draft": form = LiveDateForm() return render_to_response( "videos/" + common_page_data["course_mode"] + "/list.html", { "common_page_data": common_page_data, "section_structures": section_structures, "context": "video_list", "form": form, }, context_instance=RequestContext(request), )
def save_content_order(request): try: common_page_data = get_common_page_data(request, request.POST.get("course_prefix"), request.POST.get("course_suffix")) except: raise Http404 if not common_page_data['is_course_admin']: return redirect('courses.views.main', request.POST.get("course_prefix"), request.POST.get("course_suffix")) SECTION = ContentSection.objects.get(pk=request.POST.get('section_id')) section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=True, get_additional_page_content = True, get_file_content=True, get_exam_content=True, SECTION=SECTION) def set_index_from_POST(item): tag = item['type'] image = item[tag].image new_index = request.POST.get("order_"+tag+"_"+str(item[tag].id)) item[tag].index = new_index item[tag].save() image.index = new_index image.save() for section_structure in section_structures: for item in section_structure['items']: set_index_from_POST(item) return redirect(request.META['HTTP_REFERER'])
def course_materials(request, course_prefix, course_suffix): section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('courses/'+request.common_page_data['course_mode']+'/course_materials.html', {'common_page_data': request.common_page_data, 'section_structures':section_structures, 'context':'course_materials', 'form':form}, context_instance=RequestContext(request))
def list(request, course_prefix, course_suffix): try: common_page_data = get_common_page_data(request, course_prefix, course_suffix) except: raise Http404 print "ASDNAJDSNAJDSAJDSNAJKNDSAJKDSNAD" print request section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=False, get_pset_content=True) return render_to_response('problemsets/'+common_page_data['course_mode']+'/list.html', {'common_page_data': common_page_data, 'section_structures':section_structures, 'context':'problemset_list'}, context_instance=RequestContext(request))
def listAll(request, course_prefix, course_suffix): common_page_data = request.common_page_data section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=False, get_pset_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('problemsets/'+common_page_data['course_mode']+'/list.html', {'common_page_data': common_page_data, 'section_structures':section_structures, 'context':'exam_list', 'form': form}, context_instance=RequestContext(request))
def list(request, course_prefix, course_suffix): common_page_data = request.common_page_data section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=False, get_pset_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('problemsets/'+common_page_data['course_mode']+'/list.html', {'common_page_data': common_page_data, 'section_structures':section_structures, 'context':'problemset_list', 'form': form}, context_instance=RequestContext(request))
def listAll(request, course_prefix, course_suffix, show_types=[ "exam", ]): course = request.common_page_data['course'] if course.mode == "draft": #draft mode, lists grades exams = list( Exam.objects.filter(course=course, is_deleted=0, exam_type__in=show_types)) #if course.mode=="live": #exams = filter(lambda item: item.is_live(), exams) scores = [] for e in exams: if ExamScore.objects.filter(course=course, exam=e, student=request.user).exists(): scores.append( ExamScore.objects.filter(course=course, exam=e, student=request.user)[0].score) else: scores.append(None) return render_to_response( 'exams/list.html', { 'common_page_data': request.common_page_data, 'course': course, 'exams_and_scores': zip(exams, scores) }, RequestContext(request)) else: #ready mode, uses section structures section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=False, get_exam_content=True, exam_types=show_types) form = None if show_types: ex_type = show_types[0] else: ex_type = "exam" return render_to_response('exams/ready/list.html', { 'common_page_data': request.common_page_data, 'section_structures': section_structures, 'reverse_show': ex_type + '_show', 'form': form, }, context_instance=RequestContext(request))
def course_materials(request, course_prefix, course_suffix, section_id=None): if section_id: #If an instructor switches to edit view from a single section's materials page, #just redirect to display all sections, since section_id is for viewing sections in ready mode if request.common_page_data['course_mode'] == 'draft': return redirect('courses.views.course_materials', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) #Makes sure section_id is for a ready mode section try: section = ContentSection.objects.getByCourse(course=request.common_page_data['course']).get(pk=section_id) except ContentSection.DoesNotExist: raise Http404 section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True, SECTION=section) else: section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('courses/'+request.common_page_data['course_mode']+'/course_materials.html', {'common_page_data': request.common_page_data, 'section_structures':section_structures, 'context':'course_materials', 'form':form}, context_instance=RequestContext(request))
def course_materials(request, course_prefix, course_suffix, section_id=None): #Vars used for single section nav prev_section = None next_section = None if section_id: #If an instructor switches to edit view from a single section's materials page, #just redirect to display all sections, since section_id is for viewing sections in ready mode if request.common_page_data['course_mode'] == 'draft': return redirect('courses.views.course_materials', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) #Makes sure section_id is for a ready mode section try: section = ContentSection.objects.getByCourse(course=request.common_page_data['course']).get(pk=section_id) except ContentSection.DoesNotExist: raise Http404 section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True, SECTION=section) #Get prev/next nav links cur_index = None sections = request.common_page_data['content_sections'] for index, item in enumerate(sections): if item == section: cur_index = index break if cur_index: if cur_index > 0: prev_section = sections[cur_index-1] if cur_index < len(sections) - 1: next_section = sections[cur_index+1] else: section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('courses/'+request.common_page_data['course_mode']+'/course_materials.html', {'common_page_data': request.common_page_data, 'section_structures':section_structures, 'context':'course_materials', 'form':form, 'prev_section':prev_section, 'next_section':next_section}, context_instance=RequestContext(request))
def save_content_order(request): try: common_page_data = get_common_page_data(request, request.POST.get("course_prefix"), request.POST.get("course_suffix")) except: raise Http404 if not common_page_data['is_course_admin']: return redirect('courses.views.main', request.POST.get("course_prefix"), request.POST.get("course_suffix")) section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content = True, get_file_content=True, get_exam_content=True) for section_structure in section_structures: if section_structure['section'].id == long(request.POST.get("section_id")): for item in section_structure['items']: if item['type'] == 'video': item['video'].index = request.POST.get("order_video_"+str(item['video'].id)) item['video'].save() video_image = item['video'].image video_image.index = request.POST.get("order_video_"+str(item['video'].id)) video_image.save() elif item['type'] == 'problem_set': item['problem_set'].index = request.POST.get("order_problem_set_"+str(item['problem_set'].id)) item['problem_set'].save() problem_set_image = item['problem_set'].image problem_set_image.index = request.POST.get("order_problem_set_"+str(item['problem_set'].id)) problem_set_image.save() elif item['type'] == 'additional_page': item['additional_page'].index = request.POST.get("order_additional_page_"+str(item['additional_page'].id)) item['additional_page'].save() additional_page_image = item['additional_page'].image additional_page_image.index = request.POST.get("order_additional_page_"+str(item['additional_page'].id)) additional_page_image.save() elif item['type'] == 'file': item['file'].index = request.POST.get("order_file_"+str(item['file'].id)) item['file'].save() file_image = item['file'].image file_image.index = request.POST.get("order_file_"+str(item['file'].id)) file_image.save() elif item['type'] == 'exam': item['exam'].index = request.POST.get("order_exam_"+str(item['exam'].id)) item['exam'].save() exam_image = item['exam'].image exam_image.index = request.POST.get("order_exam_"+str(item['exam'].id)) exam_image.save() break return redirect(request.META['HTTP_REFERER'])
def list(request, course_prefix, course_suffix): try: common_page_data = get_common_page_data(request, course_prefix, course_suffix) except: raise Http404 section_structures = get_course_materials(common_page_data=common_page_data, get_video_content=False, get_pset_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render(request, 'problemsets/'+common_page_data['course_mode']+'/list.html', { 'common_page_data': common_page_data, 'section_structures': section_structures, 'context': 'problemset_list', 'form': form })
def course_materials(request, course_prefix, course_suffix): section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True, ) return render_to_response( "courses/" + request.common_page_data["course_mode"] + "/course_materials.html", { "common_page_data": request.common_page_data, "section_structures": section_structures, "context": "course_materials", }, context_instance=RequestContext(request), )
def listAll(request, course_prefix, course_suffix): common_page_data = request.common_page_data section_structures = get_course_materials( common_page_data=common_page_data, get_video_content=False, get_pset_content=True ) form = None if request.common_page_data["course_mode"] == "draft": form = LiveDateForm() return render_to_response( "problemsets/" + common_page_data["course_mode"] + "/list.html", { "common_page_data": common_page_data, "section_structures": section_structures, "context": "problemset_list", "form": form, }, context_instance=RequestContext(request), )
def save_content_order(request): try: common_page_data = get_common_page_data( request, request.POST.get("course_prefix"), request.POST.get("course_suffix")) except: raise Http404 if not common_page_data['is_course_admin']: return redirect('courses.views.main', request.POST.get("course_prefix"), request.POST.get("course_suffix")) SECTION = ContentSection.objects.get(pk=request.POST.get('section_id')) section_structures = get_course_materials( common_page_data=common_page_data, get_video_content=True, get_additional_page_content=True, get_file_content=True, get_exam_content=True, SECTION=SECTION) def set_index_from_POST(item): tag = item['type'] image = item[tag].image new_index = request.POST.get("order_" + tag + "_" + str(item[tag].id)) item[tag].index = new_index item[tag].save() image.index = new_index image.save() for section_structure in section_structures: for item in section_structure['items']: set_index_from_POST(item) return redirect(request.META['HTTP_REFERER'])
def course_materials(request, course_prefix, course_suffix, section_id=None): #Vars used for single section nav prev_section = None next_section = None if section_id: #If an instructor switches to edit view from a single section's materials page, #just redirect to display all sections, since section_id is for viewing sections in ready mode if request.common_page_data['course_mode'] == 'draft': return redirect('courses.views.course_materials', request.common_page_data['course_prefix'], request.common_page_data['course_suffix']) #Makes sure section_id is for a ready mode section try: section = ContentSection.objects.getByCourse( course=request.common_page_data['course']).get(pk=section_id) except ContentSection.DoesNotExist: raise Http404 section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True, SECTION=section) #Get prev/next nav links cur_index = None sections = request.common_page_data['content_sections'] for index, item in enumerate(sections): if item == section: cur_index = index break if cur_index: if cur_index > 0: prev_section = sections[cur_index - 1] if cur_index < len(sections) - 1: next_section = sections[cur_index + 1] else: section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True) form = None if request.common_page_data['course_mode'] == "draft": form = LiveDateForm() return render_to_response('courses/' + request.common_page_data['course_mode'] + '/course_materials.html', { 'common_page_data': request.common_page_data, 'section_structures': section_structures, 'context': 'course_materials', 'form': form, 'prev_section': prev_section, 'next_section': next_section }, context_instance=RequestContext(request))
def save_content_order(request): try: common_page_data = get_common_page_data( request, request.POST.get("course_prefix"), request.POST.get("course_suffix")) except: raise Http404 if not common_page_data['is_course_admin']: return redirect('courses.views.main', request.POST.get("course_prefix"), request.POST.get("course_suffix")) section_structures = get_course_materials( common_page_data=common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True, get_exam_content=True) for section_structure in section_structures: if section_structure['section'].id == long( request.POST.get("section_id")): for item in section_structure['items']: if item['type'] == 'video': item['video'].index = request.POST.get( "order_video_" + str(item['video'].id)) item['video'].save() video_image = item['video'].image video_image.index = request.POST.get("order_video_" + str(item['video'].id)) video_image.save() elif item['type'] == 'problem_set': item['problem_set'].index = request.POST.get( "order_problem_set_" + str(item['problem_set'].id)) item['problem_set'].save() problem_set_image = item['problem_set'].image problem_set_image.index = request.POST.get( "order_problem_set_" + str(item['problem_set'].id)) problem_set_image.save() elif item['type'] == 'additional_page': item['additional_page'].index = request.POST.get( "order_additional_page_" + str(item['additional_page'].id)) item['additional_page'].save() additional_page_image = item['additional_page'].image additional_page_image.index = request.POST.get( "order_additional_page_" + str(item['additional_page'].id)) additional_page_image.save() elif item['type'] == 'file': item['file'].index = request.POST.get("order_file_" + str(item['file'].id)) item['file'].save() file_image = item['file'].image file_image.index = request.POST.get("order_file_" + str(item['file'].id)) file_image.save() elif item['type'] == 'exam': item['exam'].index = request.POST.get("order_exam_" + str(item['exam'].id)) item['exam'].save() exam_image = item['exam'].image exam_image.index = request.POST.get("order_exam_" + str(item['exam'].id)) exam_image.save() break return redirect(request.META['HTTP_REFERER'])
def change_live_datetime(request): list_type = request.POST.get("list_type") action = request.POST.get("action") form = LiveDateForm(request.POST) if form.is_valid(): if action == "Make Ready and Go Live": new_live_datetime = datetime.now() elif action == "Set Live Date": new_live_datetime = form.cleaned_data["live_datetime"] else: new_live_datetime = None ids = request.POST.get("change_live_datetime_ids").split(",") for id in ids: parts = id.split("_") if parts[0] == "video": content = Video.objects.get(id=parts[1]) elif parts[0] == "problemset": content = ProblemSet.objects.get(id=parts[1]) elif parts[0] == "additionalpage": content = AdditionalPage.objects.get(id=parts[1]) elif parts[0] == "file": content = File.objects.get(id=parts[1]) elif parts[0] == "exam": content = Exam.objects.get(id=parts[1]) if action == "Make Ready and Go Live" and parts[0] != "file": content.commit() content.live_datetime = new_live_datetime content.image.live_datetime = new_live_datetime content.save() content.image.save() if list_type == "course_materials": return redirect( "courses.views.course_materials", request.common_page_data["course_prefix"], request.common_page_data["course_suffix"], ) elif list_type == "problemsets": return redirect( "problemsets.views.listAll", request.common_page_data["course_prefix"], request.common_page_data["course_suffix"], ) else: return redirect( "courses.videos.views.list", request.common_page_data["course_prefix"], request.common_page_data["course_suffix"], ) # This won't work anymore because referer could be /change_live_datetime if it's an invalid form post # return redirect(request.META['HTTP_REFERER']) if list_type == "course_materials": section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=True, get_additional_page_content=True, get_file_content=True, get_exam_content=True, ) template = "courses/draft/course_materials.html" elif list_type == "problemsets": section_structures = get_course_materials(common_page_data=request.common_page_data, get_pset_content=True) template = "problemsets/draft/list.html" else: section_structures = get_course_materials(common_page_data=request.common_page_data, get_video_content=True) template = "videos/draft/list.html" return render( request, template, {"common_page_data": request.common_page_data, "section_structures": section_structures, "form": form}, )
def course_materials(request, course_prefix, course_suffix, section_id=None): # Vars used for single section nav prev_section = None next_section = None if section_id: # If an instructor switches to edit view from a single section's materials page, # just redirect to display all sections, since section_id is for viewing sections in ready mode if request.common_page_data["course_mode"] == "draft": return redirect( "courses.views.course_materials", request.common_page_data["course_prefix"], request.common_page_data["course_suffix"], ) # Makes sure section_id is for a ready mode section try: section = ContentSection.objects.getByCourse(course=request.common_page_data["course"]).get(pk=section_id) except ContentSection.DoesNotExist: raise Http404 section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True, SECTION=section, ) # Get prev/next nav links sections = request.common_page_data["content_sections"] for index, item in enumerate(sections): if item == section: cur_index = index break if cur_index > 0: prev_section = sections[cur_index - 1] if cur_index < len(sections) - 1: next_section = sections[cur_index + 1] else: section_structures = get_course_materials( common_page_data=request.common_page_data, get_video_content=True, get_pset_content=False, get_additional_page_content=True, get_file_content=True, get_exam_content=True, ) form = None if request.common_page_data["course_mode"] == "draft": form = LiveDateForm() return render_to_response( "courses/" + request.common_page_data["course_mode"] + "/course_materials.html", { "common_page_data": request.common_page_data, "section_structures": section_structures, "context": "course_materials", "form": form, "prev_section": prev_section, "next_section": next_section, }, context_instance=RequestContext(request), )