def edit_class(request, course_b36): course_id = base36_to_int(course_b36) course = get_object_or_404(CourseInfo, pk=course_id) if course.is_editor(request.user): if request.method == 'POST': form = MakeCourseForm(request.POST) if form.is_valid(): course.title = form.cleaned_data['title'] course.description = form.cleaned_data['description'] course.prereqs = form.cleaned_data['prerequisites'] #course.from_date = form.cleaned_data['from_date'] #course.course_number = form.cleaned_data['course_number'] course.url = form.cleaned_data['url'] course.save() else: form = MakeCourseForm({'title':course.title, 'description':course.description, 'prerequisites':course.prereqs, 'from_date':course.from_date, 'course_number':course.course_number, 'url':course.url }) editors = course.editor.all() editors = [editor.editor for editor in editors] render_dict = { 'course': course, 'form': form, 'editors':editors } return render_to_response('classes/edit.html', render_dict , context_instance=RequestContext(request))
def create_class(request): if request.method == 'POST': form = MakeCourseForm(request.POST) if form.is_valid(): title = form.cleaned_data['title'] description = form.cleaned_data['description'] prereqs = form.cleaned_data['prerequisites'] #from_date = form.cleaned_data['from_date'] #institution = form.cleaned_data['institution'] url = form.cleaned_data['url'] #instructors = form.cleaned_data['instructors'] new_ci = CourseInfo(title=title, description=description, prereqs=prereqs, url=url) new_ci.save() ci_admin = CourseInfoEditor(editor=request.user, course_info=new_ci, creator=True) ci_admin.save() return HttpResponseRedirect('/c/edit/%s/' % (int_to_base36(new_ci.pk))) else: form = MakeCourseForm() #editors = course.editor.all() #editors = [editor.editor for editor in editors] return render_to_response('classes/edit.html', {'form': form, 'creating': True, } , context_instance=RequestContext(request))