def contact(request): if request.POST: name = request.POST.get('name') contact_type = request.POST.get('type') reason = request.POST.get('reason') from_email = request.POST.get('email') phone_num = request.POST.get('phone') comment = request.POST.get('comment') form = CaptchaForm(request.POST) if form.is_valid(): components = [] component_ids = {'My.jobs Error': {'id': '12903'}, 'Job Seeker': {'id': '12902'}, 'Employer': {'id': '12900'}, 'Partner': {'id': '12901'}, 'Request Demo': {'id': '13900'}} if component_ids.get(reason): components.append(component_ids.get(reason)) components.append(component_ids.get(contact_type)) issue_dict = { 'summary': '%s - %s' % (reason, from_email), 'description': '%s' % comment, 'issuetype': {'name': 'Task'}, 'customfield_10400': str(name), 'customfield_10401': str(from_email), 'customfield_10402': str(phone_num), 'components': components} subject = 'Contact My.jobs by a(n) %s' % contact_type body = """ Name: %s Is a(n): %s Email: %s %s """ % (name, contact_type, from_email, comment) to_jira = log_to_jira(subject, body, issue_dict, from_email) if to_jira: time = datetime.datetime.now().strftime( '%A, %B %d, %Y %l:%M %p') return HttpResponse(json.dumps({'validation': 'success', 'name': name, 'c_type': contact_type, 'reason': reason, 'c_email': from_email, 'phone': phone_num, 'comment': comment, 'c_time': time})) else: return HttpResponse('success') else: return HttpResponse(json.dumps({'validation': 'failed', 'errors': form.errors.items()})) else: form = CaptchaForm() data_dict = {'form': form} return render_to_response('contact.html', data_dict, RequestContext(request))
def event_list_to_email_log(event_list): """ :param event_list: A list of events, where each event is a dictionary. :return: A list of EmailLog objects. """ events_to_create = [] for event in event_list: category = event.get('category', '') email_log_args = { 'email': event['email'], 'event': event['event'], 'received': date.fromtimestamp(float(event['timestamp'])), 'category': category, # Events can have a response (delivered, deferred), # a reason (bounce, block), or neither, but never # both. 'reason': event.get('response', event.get('reason', '')) } if event['event'] == 'bounce' and category == 'My.jobs email redirect': subject = 'My.jobs email redirect failure' body = """ Contact: %s Type: %s Reason: %s Status: %s """ % (event['email'], event['type'], event['reason'], event['status']) issue_dict = { 'summary': 'Redirect email failure', 'description': body, 'issuetype': {'name': 'Bug'} } log_to_jira(subject, body, issue_dict, event['email']) is_list = isinstance(category, list) for env in ['QC', 'Staging', 'Local', 'Jenkins']: # This event has multiple attached categories and env is one of them # or there is only one category, which is env. if (is_list and env in category) or \ (not is_list and category == env): break else: if is_list: try: category.remove('Production') except ValueError: pass else: if len(category) == 1: # This preserves our prior functionality - if there are # legitimately multiple categories on this email, # category will remain a list and this will get logged # by NewRelic. category = category[0] elif category == 'Production': category = '' # These categories resemble the following: # Saved Search Sent (<list of keys>|event_id) try: event_id = category.split('|')[-1][:-1] except AttributeError: newrelic.agent.record_exception(*sys.exc_info()) return [] if event_id: try: log = SavedSearchLog.objects.get(uuid=event_id) email_log_args['send_log'] = log if event['event'] not in BAD_EMAIL: log.was_received = True log.save() except SavedSearchLog.DoesNotExist: pass events_to_create.append(EmailLog(**email_log_args)) return events_to_create
def event_list_to_email_log(event_list): """ :param event_list: A list of events, where each event is a dictionary. :return: A list of EmailLog objects. """ events_to_create = [] for event in event_list: category = event.get('category', '') email_log_args = { 'email': event['email'], 'event': event['event'], 'received': date.fromtimestamp(float(event['timestamp'])), 'category': category, # Events can have a response (delivered, deferred), # a reason (bounce, block), or neither, but never # both. 'reason': event.get('response', event.get('reason', '')) } if event['event'] == 'bounce' and category == 'My.jobs email redirect': subject = 'My.jobs email redirect failure' body = """ Contact: %s Type: %s Reason: %s Status: %s """ % (event['email'], event['type'], event['reason'], event['status']) issue_dict = { 'summary': 'Redirect email failure', 'description': body, 'issuetype': { 'name': 'Bug' } } log_to_jira(subject, body, issue_dict, event['email']) is_list = isinstance(category, list) for env in ['QC', 'Staging', 'Local', 'Jenkins']: # This event has multiple attached categories and env is one of them # or there is only one category, which is env. if (is_list and env in category) or \ (not is_list and category == env): break else: if is_list: try: category.remove('Production') except ValueError: pass else: if len(category) == 1: # This preserves our prior functionality - if there are # legitimately multiple categories on this email, # category will remain a list and this will get logged # by NewRelic. category = category[0] elif category == 'Production': category = '' # These categories resemble the following: # Saved Search Sent (<list of keys>|event_id) try: event_id = category.split('|')[-1][:-1] except AttributeError: newrelic.agent.record_exception(*sys.exc_info()) return [] if event_id: try: log = SavedSearchLog.objects.get(uuid=event_id) email_log_args['send_log'] = log if event['event'] not in BAD_EMAIL: log.was_received = True log.save() except SavedSearchLog.DoesNotExist: pass events_to_create.append(EmailLog(**email_log_args)) return events_to_create
def contact(request): if request.POST: name = request.POST.get('name') contact_type = request.POST.get('type') reason = request.POST.get('reason') from_email = request.POST.get('email') phone_num = request.POST.get('phone') comment = request.POST.get('comment') form = CaptchaForm(request.POST) if form.is_valid(): components = [] component_ids = { 'My.jobs Error': { 'id': '12903' }, 'Job Seeker': { 'id': '12902' }, 'Employer': { 'id': '12900' }, 'Partner': { 'id': '12901' }, 'Request Demo': { 'id': '13900' } } if component_ids.get(reason): components.append(component_ids.get(reason)) components.append(component_ids.get(contact_type)) issue_dict = { 'summary': '%s - %s' % (reason, from_email), 'description': '%s' % comment, 'issuetype': { 'name': 'Task' }, 'customfield_10400': str(name), 'customfield_10401': str(from_email), 'customfield_10402': str(phone_num), 'components': components } subject = 'Contact My.jobs by a(n) %s' % contact_type body = """ Name: %s Is a(n): %s Email: %s %s """ % (name, contact_type, from_email, comment) to_jira = log_to_jira(subject, body, issue_dict, from_email) if to_jira: time = datetime.datetime.now().strftime( '%A, %B %d, %Y %l:%M %p') return HttpResponse( json.dumps({ 'validation': 'success', 'name': name, 'c_type': contact_type, 'reason': reason, 'c_email': from_email, 'phone': phone_num, 'comment': comment, 'c_time': time })) else: return HttpResponse('success') else: return HttpResponse( json.dumps({ 'validation': 'failed', 'errors': form.errors.items() })) else: form = CaptchaForm() data_dict = {'form': form} return render_to_response('contact.html', data_dict, RequestContext(request))