def lectures(request, grade): kakomons_dict = {} year_list = [2008, 2009, 2010, 2011, 2012, 2013, 2014] lectures = Lecture.all().filter('grade =', grade) for lecture in lectures: kakomons_dict[lecture.id] = [] for year in year_list: if Kakomon.all().filter('lecture =', lecture).filter('year =', year).get(): kakomons_dict[lecture.id].append(Kakomon.all().filter('lecture =', lecture).filter('year =', year)) #kakomons_dict[lecture.id] = Kakomon.all().filter('lecture =', lecture) return render_to_response('kakomon/lectures.html', {'grade' : grade, 'lectures': lectures, 'kakomons_dict': kakomons_dict, 'year_list': year_list})
def manage_lectures(request, id): lecture = Lecture.all().filter('id =', id).get() edit_flag = '' upload_form = UploadForm() comment_form = CommentForm({'comment': lecture.comment}) delete_form = DeleteForm() if request.method == "POST" and upload_form.validate(request.form, request.files): edit_flag = 'upload' kakomon = Kakomon.all().filter('lecture =', lecture).filter('year =', upload_form['year']).get() if kakomon: kakomon.delete() mimetype = request.files['file'].content_type ext = request.files['file'].filename.split('.')[1] Kakomon(lecture=lecture, year=upload_form['year'], teacher=upload_form['teacher'], file=upload_form['file'], mimetype=mimetype, ext=ext).put() elif request.method == "POST" and delete_form.validate(request.form) and delete_form['years']: edit_flag = 'delete' for year in delete_form['years']: kakomons = Kakomon.all().filter('lecture =', lecture) kakomons.filter('year =', year).get().delete() elif request.method == "POST" and comment_form.validate(request.form): edit_flag = 'comment' lecture.comment = comment_form['comment'].replace('\r\n', '\n').replace('\n', '<br/>') lecture.put() elif request.method == "POST": lecture.delete() return redirect(url_for('kakomon/manage')) years = [] for kakomon in Kakomon.all().filter('lecture =', lecture).order('year'): years.append(kakomon.year) delete_form.years.choices = years return render_to_response('kakomon/manage_lecture.html', {'file_form': upload_form.as_widget(), 'comment_form': comment_form.as_widget(), 'delete_form': delete_form.as_widget(), 'lecture': lecture, 'years': years, 'flag': edit_flag})
def manage(request): lectures = [] for i in range(1, 5): lectures.append(Lecture.all().filter('grade =', i)) return render_to_response('kakomon/manage.html', {'lectures': lectures})
def download(request, id, name, year, ext): lecture = Lecture.all().filter('id =', id).get() kakomon = Kakomon.all().filter('lecture =', lecture).filter('year =', year).get() return Response(mimetype=kakomon.mimetype, response=kakomon.file)