def create_medicine(request): data = {'name': request.POST['name'], 'type': 'medicine'} form = InfoServiceValidationForm(data) response = {} if form.is_valid(): form.save() infoservice = form.instance response['id'] = infoservice.id response['name'] = infoservice.name else: response['errors'] = form.errors return HttpResponse(content = simplejson.dumps(response), content_type = "application/json")
def create_infoservice(request, infoservice_type): ''' Display the form and save the new infoservice. Display a successmessage. ''' infoservice_textblocks = InfoService.TYPE_TEXTS[infoservice_type] if request.method == "POST": data = {'name': request.POST['name'], 'type': infoservice_type} form = InfoServiceValidationForm(data) if form.is_valid(): form.save() infoservice = form.instance logger.info("Created InfoService: %s", str(infoservice)) nexturl = reverse('infoservices_index', kwargs={'infoservice_type': infoservice_type}) backurl = reverse('infoservices_create', kwargs={'infoservice_type': infoservice_type}) title = _("Creation successful") message = _("The \"%(infoservice_name)s\" " "%(infoservice_type)s has been created.") \ % {'infoservice_name': infoservice.name, 'infoservice_type': infoservice_textblocks["name"]} new_button_label = _("Create another %(infoservice_type)s") \ % {'infoservice_type': infoservice_textblocks['name']} success = True return render_to_response('web/status_message.html', locals(), context_instance = RequestContext(request)) return render_to_response("infoservices/create.html", locals(), context_instance = RequestContext(request))