def studentHome(teacher): print teacher # Pull episodes from database for teacher # Add authentication for student and that student belongs to teacher page teacherEpisodeData = getTeacherEpisodes(teacher) teacherEpisodeData = json.dumps(getTeacherEpisodes(teacher), ensure_ascii=False) print teacherEpisodeData return render_template('mainMenu.html', teacher=teacher, episodeData=teacherEpisodeData)
def postAddEpisode(username): if (username == current_user.username): # Gets the string name of file from ajax in MainMeunContainer.js episodeName = request.get_data() #TODO: For now, if the episode has not been added to databaes for whatever reason, add it in during this time # In most cases, the episode should already be in the database if Episode.query.filter_by(episodeJSONFileName=episodeName).first(): print "Episode already in database" newEpisode = Episode.query.filter_by( episodeJSONFileName=episodeName).first() else: newEpisode = Episode(episodeName) db.session.add(newEpisode) db.session.commit() teacher = User.query.filter_by(username=current_user.username).first() newEpisode.users.append(teacher) db.session.commit() newEpisodeArray = getTeacherEpisodes(current_user.username) return json.dumps({ 'success': True, 'episodeArray': newEpisodeArray }, 200, {'ContentType': 'application/json'})
def teacherPage(username): # Make sure only the teacher with this username can see the page if current_user.username != username: return redirect(url_for('index')) else: user = User.query.filter_by(username=username).first() episodeArray = getTeacherEpisodes(username) print episodeArray return render_template('teacherHome.html', public="public", username=username, episodeArray=episodeArray)
def getEpisodes(username): # TODO - Only the teacher and students should be able to access this page in future # Currently publicly accessible to anyone visiting this page try: teacherEpisodeData = getTeacherEpisodes(username) return json.dumps( { 'success': True, 'teacherEpisodeData': teacherEpisodeData }, 200, {'ContentType': 'application.json'}) except: return json.dumps({ 'success': True, 'teacherEpisodeData': [] }, 200, {'ContentType': 'application.json'})
def deleteEpisode(username): if (username == current_user.username): episodeName = request.get_data() teacher = User.query.filter_by(username=current_user.username).first() print teacher episodeToDelete = Episode.query.filter_by( episodeJSONFileName=episodeName).first() print episodeToDelete teacher.episodes.remove(episodeToDelete) db.session.commit() newEpisodeArray = getTeacherEpisodes(current_user.username) return json.dumps({ 'success': True, 'episodeArray': newEpisodeArray }, 200, {'ContentType': 'application.json'})