def meta_add(request): if request.method == 'POST': form = ProblemMetaForm(request.POST) if form.is_valid(): meta = form.save() return HttpResponseRedirect(reverse('meta_detail', kwargs={'meta_id': meta.id})) else: form = ProblemMetaForm() data = {'form': form} return render_to_response("problem/problem_meta_add.html", data, context_instance=RequestContext(request))
def meta_edit(request, meta_id): session = Session() meta = session.query(ProblemMeta).get(meta_id) if meta is None: session.close() raise Http404 if request.method == "POST": form = ProblemMetaForm(request.POST) if form.is_valid(): meta = form.save(update=True, meta_id=meta_id) return HttpResponseRedirect(reverse('meta_detail', kwargs={'meta_id': meta.id})) else: form = ProblemMetaForm(initial={"title":meta.title, "judge_flow":meta.judge_flow}) data = {'form': form} return render_to_response("problem/problem_meta_edit.html", data, context_instance=RequestContext(request))