<s> from django . shortcuts import render <EOL> from django . core import serializers <EOL> from django . http import HttpResponse <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . conf import settings <EOL> import json <EOL> import datetime <EOL> from registrar . models import Teacher <EOL> from registrar . models import Student <EOL> from registrar . models import Course <EOL> from registrar . models import Lecture <EOL> from teacher . forms import LectureForm <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def lectures_page ( request , course_id ) : <EOL> course = Course . objects . get ( id = course_id ) <EOL> teacher = Teacher . objects . get ( user = request . user ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : teacher , <EOL> '<STR_LIT>' : course , <EOL> '<STR_LIT>' : settings . NO_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . YOUTUBE_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . VIMEO_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . BLIPTV_VIDEO_PLAYER , <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : settings . APPLICATION_HAS_ADVERTISMENT , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_CSS_LIBRARY_URLS , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_JS_LIBRARY_URLS , <EOL> } ) <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def lectures_table ( request , course_id ) : <EOL> course = Course . objects . get ( id = course_id ) <EOL> teacher = Teacher . objects . get ( user = request . user ) <EOL> try : <EOL> lectures = Lecture . objects . filter ( course = course ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except Lecture . DoesNotExist : <EOL> lectures = None <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : teacher , <EOL> '<STR_LIT>' : course , <EOL> '<STR_LIT>' : lectures , <EOL> '<STR_LIT>' : settings . NO_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . YOUTUBE_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . VIMEO_VIDEO_PLAYER , <EOL> '<STR_LIT>' : settings . BLIPTV_VIDEO_PLAYER , <EOL> '<STR_LIT:user>' : request . user , <EOL> } ) <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def lecture_modal ( request , course_id ) : <EOL> if request . method == u'<STR_LIT:POST>' : <EOL> lecture_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> form = None <EOL> if lecture_id > <NUM_LIT:0> : <EOL> lecture = Lecture . objects . get ( lecture_id = lecture_id ) <EOL> form = LectureForm ( instance = lecture ) <EOL> else : <EOL> form = LectureForm ( ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : form , <EOL> } ) <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def save_lecture ( request , course_id ) : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> if request . is_ajax ( ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> course = Course . objects . get ( id = course_id ) <EOL> lecture_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> form = None <EOL> if lecture_id > <NUM_LIT:0> : <EOL> lecture = Lecture . objects . get ( lecture_id = lecture_id ) <EOL> form = LectureForm ( instance = lecture , data = request . POST ) <EOL> else : <EOL> form = LectureForm ( request . POST , request . FILES ) <EOL> if form . is_valid ( ) : <EOL> instance = form . save ( commit = False ) <EOL> instance . course = course <EOL> instance . save ( ) <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT:success>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> else : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : json . dumps ( form . errors ) } <EOL> return HttpResponse ( json . dumps ( response_data ) , content_type = "<STR_LIT:application/json>" ) <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def delete_lecture ( request , course_id ) : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> if request . is_ajax ( ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> lecture_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> teacher = Teacher . objects . get ( user = request . user ) <EOL> try : <EOL> lecture = Lecture . objects . get ( lecture_id = lecture_id ) <EOL> if lecture . course . teacher == teacher : <EOL> lecture . delete ( ) <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT:success>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> else : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> except Lecture . DoesNotExist : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> return HttpResponse ( json . dumps ( response_data ) , content_type = "<STR_LIT:application/json>" ) </s>
