def edit_model(request, model_id): page_type, model = get_page_type_from_url(request.path) form = import_form("%sForm" % model.__name__) template = "new_%s.html" % page_type template_variables = edit_form(request, model, form, model_id) if "success_message" in template_variables: return HttpResponseRedirect("/%s/view/%s" % (page_type, model_id)) else: template_variables["url"] = "/%s/edit/%s" % (page_type, model_id) return render_to_response(template, template_variables, context_instance=RequestContext(request))
def test_edit_form(self): form_data = self.event_form_data form_data['name'] = 'Test Edit Form' event = EventForm(form_data) event.is_valid() event.save() event = Event.objects.get(name='Test Edit Form') form_data['name'] = 'Test Edit Form 2' request = self.factory.post('/event/edit/%s' % event.id, form_data) results = edit_form(request, Event, EventForm, event.id) self.assertTrue('success_message' in results)