Example #1
0
def new_organizer(request):
  required_fields_list = [
    'email',
  ]
  organizer_insert_dict = {'email':request.POST['email']}
  organizer = Organizer(**organizer_insert_dict)
  organizer.save()
  return HttpResponseRedirect('/create_campaign/')
Example #2
0
def save_campaign(request):
  """Creates a new campaign"""
  required_fields_list = [
    'campaign_url',
    'decision_makers',
    'email',
  ]
  for field in required_fields_list:
    if field not in request.POST:
      return HttpResponse('Missing %s param in request' % (field))
  email = request.POST.get('email', None)
  name = request.POST.get('name', None)
  new_organizer = None
  if email is not None:
    try:
      new_organizer = Organizer.objects.get(email=email)
    except Organizer.DoesNotExist:
      new_organizer = Organizer(email=email)
      new_organizer.save()
  try:
    campaign = Campaign.objects.get(campaign_url=request.POST['campaign_url'])
    return HttpResponse('Campaign Already Exists with that url')
  except Campaign.DoesNotExist:
    new_campaign_params = {
      'campaign_url': request.POST['campaign_url'],
      'organizer': new_organizer,
      'name': name,
    } 
    campaign = Campaign(**new_campaign_params)
    campaign.save()
    decision_makers = request.POST['decision_makers'].split(',') # this will be a list of ids from the form
    for dm_id in decision_makers:
      try:
        dm = DecisionMaker.objects.get(pk=dm_id)
      except DecisionMaker.DoesNotExist:
        continue
      campaign.decision_maker.add(dm)
    response_iframe = '<iframe src="%sresponses/?campaign_id=%s" height="200" height="200" scrolling="no" frameborder="0"></iframe>' % (settings.URL_ROOT, campaign.id)
    takeaction_iframe = '<iframe src="%sbutton/?campaign_id=%s" height="90" width="150" scrolling="no" frameborder="0"></iframe>' % (settings.URL_ROOT, campaign.id)
    return render_to_response('create_campaign.html', {'takeaction_iframe': takeaction_iframe, 'response_iframe': response_iframe}, context_instance=RequestContext(request))