def company_add(request,message=None): if request.POST: company_form = CompanyForm(request.POST,request.FILES,prefix="company") action_form = CompanyActionInlineForm(request.POST,prefix="action") map_form = MapInlineForm(request.POST,prefix="map") if company_form.is_valid() and map_form.is_valid(): company = company_form.save() company.added_by = request.user #set the user who created it company.slug = slugify(company.name) #set the slug map_form.name = company.name #coords are like "lat,lon", need to be converted to real Point object coords = map_form.cleaned_data['center'].split(',') map_form.cleaned_data['center'] = Point(float(coords[0]),float(coords[1]),srid=4326) map = map_form.save() company.map = map #set the map #send the new company to the other forms if action_form.is_valid(): #send the new product to the action form action = action_form.save() action.company = company action.save() #resave the company to finish up company.save() #create the reversion revision.user = request.user revision.comment = "created" #save the citations citation_from_json(request.POST['company-citations_json'],company) return HttpResponseRedirect(company.get_absolute_url()) else: message = "Please correct the errors below" else: company_form = CompanyForm(prefix='company') action_form = CompanyActionInlineForm(prefix='action') map_form = MapInlineForm(prefix="map") message = "Add the company details below" return render_to_response("targets/company_add.html", {"message":message, "company_form":company_form, "action_form":action_form, "map_form":map_form}, context_instance = RequestContext(request))
def company_edit(request,slug): company = Company.objects.get(slug=slug) if request.POST: company_form = CompanyForm(request.POST,request.FILES,instance=company) if company_form.is_valid(): company = company_form.save() company.edited_by.add(request.user) company.save() revision.user = request.user revision.comment = "Changed %s" % ", ".join(company_form.changed_data) #save the citations citation_from_json(request.POST['citations_json'],company) return HttpResponseRedirect(company.get_absolute_url()) else: message = "Please correct the errors below" else: company_form = CompanyForm(instance=company) message = "Edit the company details below" return render_to_response("targets/company_edit.html", {"company_form": company_form, "message":message}, context_instance = RequestContext(request))