def add_post_data(request, add_type): """ Add Type is passed via the URI Valid Types and actions are: campaign - new, update template - new, update recipient - new, update """ # Add Campaign if add_type == 'campaign': action = request.POST['action'] campaign_name = request.POST['c_name'] campaign_description = request.POST['c_desc'] campaign_template = request.POST['c_template'] if action == 'new': campaign = Campaign() elif action == 'update': campaign = Campaign.objects.get(pk=campaign_id) else: error_line = "Not a Valid Campaign Action" campaign.name = campaign_name campaign.description = campaign_description campaign.template_id = campaign_template campaign.created = timezone.now() campaign.save() campaign_id = campaign.id return redirect('/campaign/{0}'.format(campaign_id)) # Add Recipients if add_type == 'recipient': action = request.POST['action'] campaign_id = request.POST['c_id'] campaign = Campaign.objects.get(pk=campaign_id) csv_file = request.FILES real_name = request.POST['real_name'] email_add = request.POST['email_add'] # check for CSV File - Override single email add if csv_file and action == 'new': csv_file = csv_file['css_import'] recipients = [] try: csv_data = csv_file.read() csv_date = csv_data.replace('\r', '') lines = csv_data.split('\n') with transaction.commit_on_success(): for line in lines: if len(line) > 10: uid = ''.join([ random.choice(string.ascii_letters + string.digits) for n in xrange(8) ]) real_name, email_add = line.split(',') recipient = Recipient(real_name=real_name, email_address=email_add, campaign=campaign, uid=uid) recipient.save() except Exception as e: error_line = "Unable to parse CSV File - {0}".format(e) return render(request, 'error.html', {'error': error_line}) # Check for single Entry elif real_name and email_add: uid = ''.join([ random.choice(string.ascii_letters + string.digits) for n in xrange(8) ]) recipient = Recipient(real_name=real_name, email_address=email_add, campaign=campaign, uid=uid) recipient.save() else: error = "Unable to Add recipients" return render(request, 'error.html', {'error': error_line}) return redirect('/campaign/{0}/#tracking'.format(campaign_id)) # Add / Update Templates if add_type == 'template': # Details template_id = request.POST['id'] title = request.POST['title'] description = request.POST['description'] # Email display_name = request.POST['display_name'] email_address = request.POST['email_address'] subject_line = request.POST['subject_line'] smtp_id = request.POST['smtp_id'] email_design = request.POST['email_design'] # Word Document document_name = request.POST['document_name'] try: document_enable = request.POST['document_enable'] document_enable = 1 except: document_enable = 0 document_design = request.POST['document_design'] # Portal portal_uri = request.POST['portal_uri'] try: portal_plugins = request.POST['portal_plugin'] portal_plugins = 1 except: portal_plugins = 0 portal_design = request.POST['portal_design'] portal_redirect = request.POST['portal_redirect'] action = request.POST['action'] # Process The Post Data if action == 'delete': # return here pass if action == 'new': template = Template() if action == 'update': template = Template.objects.get(pk=template_id) smtp_server = SMTPServer.objects.get(pk=smtp_id) template.title = title template.description = description template.display_name = display_name template.email_address = email_address template.subject_line = subject_line template.smtpServer = smtp_server template.email_design = email_design template.portal_uri = portal_uri template.portal_plugins = portal_plugins template.portal_design = portal_design template.portal_redirect = portal_redirect template.document_enable = document_enable template.document_name = document_name template.document_design = document_design template.save() template_id = template.id return redirect('/template/{0}'.format(template_id)) error_line = "Not a Valid POST Request" return render(request, 'error.html', {'error': error_line})
recipient.portal_open = fake.date_time_between(start_date="-2d", end_date="now") recipient.os_system = random.choice(os_list) if recipient.os_system == 'Android': recipient.web_client = 'Chrome Mobile' elif recipient.os_system == 'BlackBerry OS': recipient.web_client = 'BlackBerry WebKit' else: recipient.web_client = random.choice(browser_list) recipient.reader_version = random.choice(reader_list) recipient.flash_version = random.choice(flash_list) recipient.java_version = random.choice(java_list) recipient.silverlight_version = random.choice(silver_list) recipient.shockwave_version = random.choice(shock_list) recipient.ip_address = '144.76.87.236' if document_choice: recipient.document_open = fake.date_time_between(start_date="-2d", end_date="now") recipient.document_client = random.choice(doc_list) recipient.ip_address = '144.76.87.236' if webbug_choice: recipient.email_open = fake.date_time_between(start_date="-2d", end_date="now") recipient.email_client = random.choice(email_list) recipient.ip_address = '144.76.87.236' # Save the Recipient recipient.save()
recipient.os_system = random.choice(os_list) if recipient.os_system == 'Android': recipient.web_client = 'Chrome Mobile' elif recipient.os_system == 'BlackBerry OS': recipient.web_client = 'BlackBerry WebKit' else: recipient.web_client = random.choice(browser_list) recipient.reader_version = random.choice(reader_list) recipient.flash_version = random.choice(flash_list) recipient.java_version = random.choice(java_list) recipient.silverlight_version = random.choice(silver_list) recipient.shockwave_version = random.choice(shock_list) recipient.ip_address = '144.76.87.236' if document_choice: recipient.document_open = fake.date_time_between(start_date="-2d", end_date="now") recipient.document_client = random.choice(doc_list) recipient.ip_address = '144.76.87.236' if webbug_choice: recipient.email_open = fake.date_time_between(start_date="-2d", end_date="now") recipient.email_client = random.choice(email_list) recipient.ip_address = '144.76.87.236' # Save the Recipient recipient.save()
def add_post_data(request, add_type): """ Add Type is passed via the URI Valid Types and actions are: campaign - new, update template - new, update recipient - new, update """ # Add Campaign if add_type == 'campaign': action = request.POST['action'] campaign_name = request.POST['c_name'] campaign_description = request.POST['c_desc'] campaign_template = request.POST['c_template'] if action == 'new': campaign = Campaign() elif action == 'update': campaign = Campaign.objects.get(pk=campaign_id) else: error_line = "Not a Valid Campaign Action" campaign.name = campaign_name campaign.description = campaign_description campaign.template_id = campaign_template campaign.created = timezone.now() campaign.save() campaign_id = campaign.id return redirect('/campaign/{0}'.format(campaign_id)) # Add Recipients if add_type == 'recipient': action = request.POST['action'] campaign_id = request.POST['c_id'] campaign = Campaign.objects.get(pk=campaign_id) csv_file = request.FILES real_name = request.POST['real_name'] email_add = request.POST['email_add'] # check for CSV File - Override single email add if csv_file and action == 'new': csv_file = csv_file['css_import'] recipients = [] try: csv_data = csv_file.read() csv_date = csv_data.replace('\r', '') lines = csv_data.split('\n') with transaction.commit_on_success(): for line in lines: if len(line) > 10: uid = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)]) real_name, email_add = line.split(',') recipient = Recipient(real_name=real_name, email_address=email_add, campaign=campaign, uid=uid) recipient.save() except Exception as e: error_line = "Unable to parse CSV File - {0}".format(e) return render(request, 'error.html', {'error':error_line}) # Check for single Entry elif real_name and email_add: uid = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(8)]) recipient = Recipient(real_name=real_name, email_address=email_add, campaign=campaign, uid=uid) recipient.save() else: error = "Unable to Add recipients" return render(request, 'error.html', {'error':error_line}) return redirect('/campaign/{0}/#tracking'.format(campaign_id)) # Add / Update Templates if add_type == 'template': # Details template_id = request.POST['id'] title = request.POST['title'] description = request.POST['description'] # Email display_name = request.POST['display_name'] email_address = request.POST['email_address'] subject_line = request.POST['subject_line'] smtp_id = request.POST['smtp_id'] email_design = request.POST['email_design'] # Word Document document_name = request.POST['document_name'] try: document_enable = request.POST['document_enable'] document_enable = 1 except: document_enable = 0 document_design = request.POST['document_design'] # Portal portal_uri = request.POST['portal_uri'] try: portal_plugins = request.POST['portal_plugin'] portal_plugins = 1 except: portal_plugins = 0 portal_design = request.POST['portal_design'] portal_redirect = request.POST['portal_redirect'] action = request.POST['action'] # Process The Post Data if action == 'delete': # return here pass if action == 'new': template = Template() if action == 'update': template = Template.objects.get(pk=template_id) smtp_server = SMTPServer.objects.get(pk=smtp_id) template.title = title template.description = description template.display_name = display_name template.email_address = email_address template.subject_line = subject_line template.smtpServer = smtp_server template.email_design = email_design template.portal_uri = portal_uri template.portal_plugins = portal_plugins template.portal_design = portal_design template.portal_redirect = portal_redirect template.document_enable = document_enable template.document_name = document_name template.document_design = document_design template.save() template_id = template.id return redirect('/template/{0}'.format(template_id)) error_line = "Not a Valid POST Request" return render(request, 'error.html', {'error':error_line})