def edit_tracker(request, tracker): try: t = Tracker.objects.get(pk=tracker) except Tracker.DoesNotExist: return HttpResponse("Tracker is invalid.") try: form = FormCss.objects.get(tracker=t) except FormCss.DoesNotExist: return HttpResponse("Form is not valid.") if request.POST: design = DesignForm(data=request.POST, instance=form) tracker_form = TrackerForm(data=request.POST, instance=t, prefix='t') campaign_form = CampaignForm(data=request.POST, instance=t.campaign) if design.is_valid() and tracker_form.is_valid() and campaign_form.is_valid(): design.save() tracker_form.save() campaign_form.save() return HttpResponseRedirect("/campaign/list/") else: design = DesignForm(instance=form) tracker_form = TrackerForm(instance=t, prefix='t') campaign_form = CampaignForm(instance=t.campaign) return render_to_response('campaign/edit_tracker.html', {'design_form':design, 'campaign_form':campaign_form, 'tracker_form':tracker_form}, context_instance=RequestContext(request))
def new_campaign(request, campaignpk=""): if campaignpk: campaign = Campaign.objects.get(pk=campaignpk) action = '/campaign/tracker/add/'+campaignpk+'/' button = 'Add Tracker' header = 'Add Tracker To Campaign' else: campaign = Campaign(user=request.user, impressions=0, clicks=0, leads_total=0, leads_sold=0) action = '/campaign/new/' button = 'Add Campaign' header = 'Add A New Campaign' design = FormCss() tracker = Tracker() if request.method == 'POST': campaign_form = CampaignForm(data=request.POST, instance=campaign) tracker_form = TrackerForm(data=request.POST, instance=tracker, prefix='t') design_form = DesignForm(data=request.POST, instance=design) if campaign_form.is_valid() and tracker_form.is_valid() and design_form.is_valid(): c = campaign_form.save(commit=False) c.save() d = design_form.save(commit=False) d.save() t = tracker_form.save(commit=False) t.campaign = c t.design = d t.save() tracker_log = TrackerLog(tracker=t) tracker_log.date = datetime.today() tracker_log.sold_total = 0 tracker_log.save() return render_to_response('campaign/new_done.html', {'tracker':t}, context_instance=RequestContext(request)) else: return render_to_response('campaign/new.html', {'campaign_form':campaign_form, 'design_form':design_form, 'tracker_form':tracker_form, 'action': action, 'button':button, 'header':header}, context_instance=RequestContext(request)) else: campaign_form = CampaignForm( instance=campaign) tracker_form = TrackerForm(instance=tracker, prefix='t') design_form = DesignForm(instance=design) return render_to_response('campaign/new.html', {'campaign_form':campaign_form, 'design_form':design_form, 'tracker_form':tracker_form, 'action': action, 'button':button, 'header':header}, context_instance=RequestContext(request))
def edit_tracker(request, tracker): try: t = Tracker.objects.get(pk=tracker) except Tracker.DoesNotExist: return HttpResponse("Tracker is invalid.") try: form = FormCss.objects.get(tracker=t) except FormCss.DoesNotExist: return HttpResponse("Form is not valid.") if request.POST: design = DesignForm(data=request.POST, instance=form) tracker_form = TrackerForm(data=request.POST, instance=t, prefix='t') campaign_form = CampaignForm(data=request.POST, instance=t.campaign) if design.is_valid() and tracker_form.is_valid( ) and campaign_form.is_valid(): design.save() tracker_form.save() campaign_form.save() return HttpResponseRedirect("/campaign/list/") else: design = DesignForm(instance=form) tracker_form = TrackerForm(instance=t, prefix='t') campaign_form = CampaignForm(instance=t.campaign) return render_to_response('campaign/edit_tracker.html', { 'design_form': design, 'campaign_form': campaign_form, 'tracker_form': tracker_form }, context_instance=RequestContext(request))
def new_campaign(request, campaignpk=""): if campaignpk: campaign = Campaign.objects.get(pk=campaignpk) action = '/campaign/tracker/add/' + campaignpk + '/' button = 'Add Tracker' header = 'Add Tracker To Campaign' else: campaign = Campaign(user=request.user, impressions=0, clicks=0, leads_total=0, leads_sold=0) action = '/campaign/new/' button = 'Add Campaign' header = 'Add A New Campaign' design = FormCss() tracker = Tracker() if request.method == 'POST': campaign_form = CampaignForm(data=request.POST, instance=campaign) tracker_form = TrackerForm(data=request.POST, instance=tracker, prefix='t') design_form = DesignForm(data=request.POST, instance=design) if campaign_form.is_valid() and tracker_form.is_valid( ) and design_form.is_valid(): c = campaign_form.save(commit=False) c.save() d = design_form.save(commit=False) d.save() t = tracker_form.save(commit=False) t.campaign = c t.design = d t.save() tracker_log = TrackerLog(tracker=t) tracker_log.date = datetime.today() tracker_log.sold_total = 0 tracker_log.save() return render_to_response('campaign/new_done.html', {'tracker': t}, context_instance=RequestContext(request)) else: return render_to_response('campaign/new.html', { 'campaign_form': campaign_form, 'design_form': design_form, 'tracker_form': tracker_form, 'action': action, 'button': button, 'header': header }, context_instance=RequestContext(request)) else: campaign_form = CampaignForm(instance=campaign) tracker_form = TrackerForm(instance=tracker, prefix='t') design_form = DesignForm(instance=design) return render_to_response('campaign/new.html', { 'campaign_form': campaign_form, 'design_form': design_form, 'tracker_form': tracker_form, 'action': action, 'button': button, 'header': header }, context_instance=RequestContext(request))