def store_add(request,message=None): if request.POST: store_form = StoreForm(request.POST,prefix="store") map_form = MapInlineForm(request.POST,prefix="map") if store_form.is_valid() and map_form.is_valid(): store = store_form.save() #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() store.location = map.center #don't actually save map #set the user who added it store.added_by = request.user #set the slug store.slug = slugify(store.name+"-"+map.name) store.save() #create the revision revision.user = request.user revision.comment = "created" #save the citations #citation_from_json(request.POST['citations_json'],store) return HttpResponseRedirect(store.get_absolute_url()) else: message = "Please correct the errors below" else: store_form = StoreForm(prefix="store") map_form = MapInlineForm(prefix="map") message = "Add the store details below" return render_to_response("targets/store_add.html", {"message":message,"store_form": store_form,"map_form":map_form}, context_instance = RequestContext(request))
def store_edit(request,slug): store = Store.objects.get(slug=slug) if request.POST: form = StoreForm(request.POST,instance=store) if form.is_valid(): store = form.save() store.edited_by.add(request.user) #create the revision revision.user = request.user revision.comment = "Changed %s" % ", ".join(form.changed_data) store.save() return HttpResponseRedirect(store.get_absolute_url()) else: message = "Please correct the errors below" else: form = StoreForm(instance=store) message = "Edit the campaign details below" return render_to_response("targets/store_edit.html", {"message":message,"form": form}, context_instance = RequestContext(request))