Ejemplo n.º 1
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))
Ejemplo n.º 2
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))