Esempio n. 1
0
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))
Esempio n. 2
0
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))