def create_campaign(req): campaign_url = req.POST["url"] if not campaign_url.startswith("http://"): campaign_url = "http://" + campaign_url if req.POST['campaign_type'] == 'raffle': template_val = 0 campaign_url_val = "http://i.bnet.com/blogs/verizon-prepping-the-ipad.jpg" elif req.POST['campaign_type'] == 'discount': campaign_url_val = campaign_url template_val = 2 else: template_val = 0 campaign_url_val = campaign_url c = Campaign( url=campaign_url, url_redeem=campaign_url_val, template=template_val ) c.save() print "CAMPAIGN CREATE", c.page_views c.campaign_type = req.POST['campaign_type'] c.save() c.setHash() create_attr(c, name='post', value='') create_attr(c, name='follow', value='') return HttpResponse(json.dumps({"campaign_hash": c.chash}))
def create_campaign(self, advertiser, index=1): campaign = Campaign(advertiser=advertiser, name='Random Campaign %s' % index, campaign_type=CAMPAIGN_NATIVE, bid_type=BID_CPM) campaign.save() return campaign
def edit(request, campaign_id=None, template='campaign/campaign_edit_form.html'): ctx = {} approved_campaign_edit = False FormClass = forms.get_campaign_form(request) if campaign_id is not None: # We are in update mode. Get the campaign instance if it belongs to # this user and it has not yet been submitted for admin approval. campaign = get_object_or_404( Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user) #is_submitted=False mode = 'update' ctx['campaign'] = campaign if campaign.is_approved: # Approved campaigns use a different form to track changes FormClass = forms.get_campaign_edit_form(campaign, request) approved_campaign_edit = True else: campaign = Campaign(artist=request.user.get_profile().artist) mode = 'create' if request.POST: form = FormClass(data=request.POST, files=request.FILES, instance=campaign) if form.is_valid(): if approved_campaign_edit: campaign_change = form.save(commit=True) ActionItem.objects.q_admin_action(campaign, 'approve-campaign-edit') email_template('Campaign Edited: approval requested by %s' % request.user.username, 'campaign/email/request_approval_edit.txt', {'campaign': campaign}, to_list=settings.CAMPAIGN_APPROVERS, fail_silently=False) request.user.message_set.create(message=_( "This is what your updated campaign page will look like once an admin approves your changes." )) else: campaign = form.save(commit=False) campaign.save() request.user.message_set.create(message=_( "This is what your updated campaign page will look like. If you are happy with it, please submit it for approval." )) if campaign_id is None: _log.info('Campaign created: (%s) %s', campaign.pk, campaign.short_title) else: _log.info('Campaign updated: (%s) %s', campaign.pk, campaign.short_title) return HttpResponseRedirect(campaign.get_absolute_url()) else: form = FormClass(instance=campaign) ctx.update({'form': form, 'mode': mode}) return render_view(request, template, ctx)
def createNewCampaign(request): if request.POST: title = request.POST['campaignTitle'] description = request.POST['description'] #startDate = request.POST['startDate'] endDate = request.POST['endDate'] perk = request.POST['perkDescription'] #requirement = request.POST['requirement'] slots = request.POST['slots'] category_id = request.POST['categoryOption'] category = Category.objects.get(id=category_id) if request.FILES.get('image') is not None: image = request.FILES['image'] if image.content_type in ['image/jpeg','image/png','image/bmp']: pass else: image=None else: image=None campaign = Campaign(title=title,description=description,slots=slots, perk=perk,category=category, endDate=endDate,image=image,user=request.user) if request.POST['offerType']=='cash': campaign.cash = True elif request.POST['offerType']=='product': campaign.product = True elif request.POST['offerType']=='discount': campaign.discount = True platforms = request.POST.getlist('platform') print platforms for platform in platforms: if platform == 'twitter': campaign.twitter=True elif platform == 'instagram': campaign.instagram=True elif platform =='youtube': campaign.youtube=True campaign.save() return HttpResponseRedirect('/campaign/%s'%campaign.slug) else: args={} args.update(csrf(request)) return render_to_response('new_campaign.html',args)
def create_campaign_original(req): if "campaign_type" not in req.POST: return HttpResponse(json.dumps({"status": "error"})) campaign_type = req.POST["campaign_type"] code = req.POST["code"] max_people = req.POST["max_people"] min_people = req.POST["min_people"] percent = req.POST["percent"] start_date = req.POST["promotion_date_start"] start_time = req.POST["promotion_time_start"] end_date = req.POST["promotion_date_end"] end_time = req.POST["promotion_time_end"] from_name = req.POST["from_name"] message = req.POST["campaign_message"] subdomain = req.POST["subdomain"] url = req.POST["url_redeem"] start_dt = datetime.datetime.strptime(start_date.strip() + " " + start_time.strip(), "%m/%d/%Y %I:%M %p") end_dt = datetime.datetime.strptime(end_date.strip() + " " + end_time.strip(), "%m/%d/%Y %I:%M %p") c = Campaign( start_date_time=start_dt, end_date_time=end_dt, code=code, percent=percent, url=url, max_people=max_people, min_people=min_people, message=message, subdomain=subdomain, from_name=from_name, campaign_type=campaign_type ) c.save() c.setHash() if campaign_type == "business": return _create_business(c, req) elif campaign_type == "hotel": return _create_hotel(c, req) elif campaign_type == "product": return _create_product(c, req) elif campaign_type == "event": return _create_event(c, req) return HttpResponse(json.dumps({}))
def edit(request, campaign_id=None, template='campaign/campaign_edit_form.html'): ctx = {} approved_campaign_edit = False FormClass = forms.get_campaign_form(request) if campaign_id is not None: # We are in update mode. Get the campaign instance if it belongs to # this user and it has not yet been submitted for admin approval. campaign = get_object_or_404(Campaign.visible_objects, pk=campaign_id, artist__user_profile__user=request.user) #is_submitted=False mode = 'update' ctx['campaign'] = campaign if campaign.is_approved: # Approved campaigns use a different form to track changes FormClass = forms.get_campaign_edit_form(campaign, request) approved_campaign_edit = True else: campaign = Campaign(artist=request.user.get_profile().artist) mode = 'create' if request.POST: form = FormClass(data=request.POST, files=request.FILES, instance=campaign) if form.is_valid(): if approved_campaign_edit: campaign_change = form.save(commit=True) ActionItem.objects.q_admin_action(campaign, 'approve-campaign-edit') email_template('Campaign Edited: approval requested by %s' % request.user.username, 'campaign/email/request_approval_edit.txt', {'campaign':campaign}, to_list=settings.CAMPAIGN_APPROVERS, fail_silently=False) request.user.message_set.create(message=_("This is what your updated campaign page will look like once an admin approves your changes.")) else: campaign = form.save(commit=False) campaign.save() request.user.message_set.create(message=_("This is what your updated campaign page will look like. If you are happy with it, please submit it for approval.")) if campaign_id is None: _log.info('Campaign created: (%s) %s', campaign.pk, campaign.short_title) else: _log.info('Campaign updated: (%s) %s', campaign.pk, campaign.short_title) return HttpResponseRedirect(campaign.get_absolute_url()) else: form = FormClass(instance=campaign) ctx.update({'form':form, 'mode':mode}) return render_view(request, template, ctx)
def publish_new_manifesto(request): password = request.POST.get('password') return_data = {} if not request.user.check_password(password): return_data['STATUS'] = '0' return_data['MESSAGE'] = 'Wrong password' else: return_data['MESSAGE'] = [] manifesto_title = request.POST.get('manifestoTitle') manifesto_language = request.POST.get('manifestoLanguage') manifesto = Campaign() manifesto.title = manifesto_title manifesto.client = Client.objects.get(user=request.user) manifesto.language = Language.objects.get(id=manifesto_language) manifesto.date_created = datetime.datetime.now() manifesto.save() try: manifesto.save() return_data['MESSAGE'].append({ 'STATUS': '1', 'MESSAGE': 'Campaign has been created' }) manifesto = Campaign.objects.get( client=Client.objects.get(user=request.user), language=manifesto_language, title=manifesto_title) manifesto_content = json.loads( request.POST.get('manifestoContent')) for item in manifesto_content: try: manifesto_item = CampaignItems() manifesto_item.campaign = manifesto manifesto_item.title = item['contentTitle'] manifesto_item.content = item['content'] manifesto_item.save() return_data['MESSAGE'].append({ 'STATUS': '1', 'MESSAGE': '{} has been added to campaign.'.format( item['contentTitle']) }) except: return_data['MESSAGE'].append({ 'STATUS': '0', 'MESSAGE': '{} could not be added to the campaign.'.format( item['contentTitle']) }) except: return_data['MESSAGE'].append({ 'STATUS': '0', 'MESSAGE': 'Campaign failed to be published' }) return HttpResponse(json.dumps(return_data))
def create_campaigns(): Campaign.objects.all().delete() for pk, fields in mapeos.iteritems(): if pk in skip_mapeos: continue #get extra data #adata = json.load(urllib2.urlopen('http://datea.pe/api/v1/mapping/'+str(pk)+'/?format=json')) c = Campaign(pk=pk) c.user_id = get_user(fields['user']['id']) c.name = fields['name'] c.published = fields['published'] c.featured = fields['featured'] c.short_description = fields['short_description'] c.mission = fields['mission'] c.information_destiny = fields['information_destiny'] c.long_description = fields['long_description'] c.client_domain = datea if fields['center']: c.center = GEOSGeometry(fields['center']) if fields['boundary']: c.boundary = GEOSGeometry(fields['boundary']) if fields['end_date']: c.end_date = date_parser(fields['end_date']) if fields['image']: c.image_id = fields['image']['id'] c.category_id = fields['category']['id'] # main hashtag if fields['hashtag']: tname = remove_accents(hashtagify(fields['hashtag'].replace('#', ''))) else: tname = remove_accents(hashtagify(fields['name'].replace('#', ''))) if Campaign.objects.filter(slug=slugify(tname)).count() == 0: c.slug = slugify(tname) else: c.slug = slugify(fields['slug']) print "CAMPAIGN TAG NAME", tname existing = Tag.objects.filter(tag__iexact=tname) if existing.count() == 0: t = Tag() t.tag = tname t.title = fields['name'].strip() #t.description = fields['short_description'] t.save() c.main_tag_id = t.pk else: c.main_tag_id = existing[0].pk c.save() # secondary tags (m2m after save) for ipk in fields['item_categories']: tag = find_tag(ipk) c.secondary_tags.add(tag) created = date_parser(fields['created']) modified = date_parser(fields['modified']) Campaign.objects.filter(pk=c.pk).update(created=created, modified=modified)