Пример #1
0
def product_add(request,message=None):
    if request.POST:
        product_form = ProductForm(request.POST,request.FILES,prefix='product')
        action_form = ProductActionInlineForm(request.POST,prefix='action')
        if product_form.is_valid():
            product = product_form.save()
            #set the user who added it
            product.added_by = request.user
            #set the slug
            product.slug = slugify(product.name)
            
            if action_form.is_valid():
                #send the new product to the action form
                action = action_form.save()
                action.product = product
                action.save()
            #resave the product to finish up
            product.save()
            #create the revision
            revision.user = request.user
            revision.comment = "created"
            #save the citations
            citation_from_json(request.POST['product-citations_json'],product)
            return HttpResponseRedirect(product.get_absolute_url())
        else:
           message = "Please correct the errors below"
    else:
        product_form = ProductForm(prefix='product')
        action_form = ProductActionInlineForm(prefix='action')
        message = "Add the product details below"
    return render_to_response("targets/product_add.html",
                    {"product_form": product_form,
                    "action_form":action_form,
                    "message":message},
    context_instance = RequestContext(request))
Пример #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))
Пример #3
0
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))
Пример #4
0
def campaign_edit(request,slug):
    campaign = Campaign.objects.get(slug=slug)
    if request.POST:
        form = CampaignForm(request.POST,instance=campaign)
        if form.is_valid():
            campaign = form.save()
            campaign.edited_by.add(request.user)
            campaign.save()
            #create the revision
            revision.user = request.user
            revision.comment = "Changed %s" % ", ".join(form.changed_data)
            #save the citations
            citation_from_json(request.POST['citations_json'],campaign)
            return HttpResponseRedirect(campaign.get_absolute_url())
        else:
            message = "Please correct the errors below"
    else:
        form = CampaignForm(instance=campaign)
        message = "Edit the campaign details below"
    return render_to_response("targets/campaign_edit.html",
                    {"campaign":campaign,"message":message,"form": form},
                    context_instance = RequestContext(request))
Пример #5
0
def product_edit(request,slug):
    product = get_object_or_404(Product,slug=slug)
    if request.POST:
        product_form = ProductForm(request.POST,request.FILES,instance=product)
        if product_form.is_valid():
            product = product_form.save()
            product.edited_by.add(request.user)
            product.save()
            #create the revision
            revision.user = request.user
            revision.comment = "Changed %s" % ", ".join(product_form.changed_data)
            #save the citations
            citation_from_json(request.POST['citations_json'],product)
            return HttpResponseRedirect(product.get_absolute_url())
        else:
            message = "Please correct the errors below"
    else:
        product_form = ProductForm(instance=product)
        message = "Edit the product details below"
    return render_to_response("targets/product_edit.html",
                    {"message":message,"product_form": product_form},
    context_instance = RequestContext(request))
Пример #6
0
def campaign_add(request,message=None):
    if request.POST:
        form = CampaignForm(request.POST)
        if form.is_valid():
            campaign = form.save()
            #set the user who added it
            campaign.added_by = request.user
            #set the slug
            campaign.slug = slugify(campaign.name)
            campaign.save()
            #create the revision
            revision.user = request.user
            revision.comment = "created"
            #save the citations
            citation_from_json(request.POST['citations_json'],campaign)
            return HttpResponseRedirect(campaign.get_absolute_url())
        else:
            message = "Please correct the errors below"
    else:
        form = CampaignForm()
        message = "Add the campaign details below"
    return render_to_response("targets/campaign_add.html",
                    {"message":message,"form": form},
                    context_instance = RequestContext(request))