From bfd2e2a5a3fead3d29ad36775748b239edb3ba4f Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Tue, 11 Oct 2011 16:09:39 -0700 Subject: [PATCH] Move task so celery will register it (bug 693828) --- apps/devhub/responsys.py | 41 ---------------------------------------- apps/devhub/tasks.py | 35 ++++++++++++++++++++++++++++++++-- apps/devhub/views.py | 11 ++++++----- 3 files changed, 39 insertions(+), 48 deletions(-) delete mode 100644 apps/devhub/responsys.py diff --git a/apps/devhub/responsys.py b/apps/devhub/responsys.py deleted file mode 100644 index 930723abc7..0000000000 --- a/apps/devhub/responsys.py +++ /dev/null @@ -1,41 +0,0 @@ -from datetime import date -import urllib2 - -from django.conf import settings -from django.utils.http import urlencode - -from celery.decorators import task - - -def make_source_url(request): - """Responsys expects the URL in the format example.com/foo.""" - return request.get_host() + request.get_full_path() - - -@task -def subscribe(campaign, address, format='html', source_url='', - lang='', country=''): - """ - Subscribe a user to a list in responsys. There should be two - fields within the Responsys system named by the "campaign" - parameter: _FLG and _DATE. - """ - - data = { - 'LANG_LOCALE': lang, - 'COUNTRY_': country, - 'SOURCE_URL': source_url, - 'EMAIL_ADDRESS_': address, - 'EMAIL_FORMAT_': 'H' if format == 'html' else 'T', - } - - data['%s_FLG' % campaign] = 'Y' - data['%s_DATE' % campaign] = date.today().strftime('%Y-%m-%d') - data['_ri_'] = settings.RESPONSYS_ID - - try: - res = urllib2.urlopen('http://awesomeness.mozilla.org/pub/rf', - data=urlencode(data)) - return res.code == 200 - except urllib2.URLError: - return False diff --git a/apps/devhub/tasks.py b/apps/devhub/tasks.py index 5d22650a19..8a2cdb9e16 100644 --- a/apps/devhub/tasks.py +++ b/apps/devhub/tasks.py @@ -1,10 +1,10 @@ # -*- coding: utf8 -*- import base64 +from datetime import date import json import logging import os import path -import shutil import socket import sys import traceback @@ -13,6 +13,7 @@ import uuid from django.conf import settings from django.core.management import call_command +from django.utils.http import urlencode from celeryutils import task from statsd import statsd @@ -20,7 +21,7 @@ from tower import ugettext as _ import amo from amo.decorators import write, set_modified_on -from amo.utils import guard, slugify, resize_image, remove_icons +from amo.utils import guard, resize_image, remove_icons from addons.models import Addon from applications.management.commands import dump_apps from applications.models import Application, AppVersion @@ -29,6 +30,7 @@ from files.models import FileUpload, File, FileValidation from PIL import Image + log = logging.getLogger('z.devhub.task') @@ -412,3 +414,32 @@ def start_perf_test_for_file(file_id, os_name, app_name, **kw): file_ = File.objects.get(pk=file_id) # TODO(Kumar) store token to retrieve results later? perf.start_perf_test(file_, os_name, app_name) + + +@task +def subscribe_to_responsys(campaign, address, format='html', source_url='', + lang='', country='', **kw): + """ + Subscribe a user to a list in responsys. There should be two + fields within the Responsys system named by the "campaign" + parameter: _FLG and _DATE. + """ + + data = { + 'LANG_LOCALE': lang, + 'COUNTRY_': country, + 'SOURCE_URL': source_url, + 'EMAIL_ADDRESS_': address, + 'EMAIL_FORMAT_': 'H' if format == 'html' else 'T', + } + + data['%s_FLG' % campaign] = 'Y' + data['%s_DATE' % campaign] = date.today().strftime('%Y-%m-%d') + data['_ri_'] = settings.RESPONSYS_ID + + try: + res = urllib2.urlopen('http://awesomeness.mozilla.org/pub/rf', + data=urlencode(data)) + return res.code == 200 + except urllib2.URLError: + return False diff --git a/apps/devhub/views.py b/apps/devhub/views.py index 2ec7e6e328..f870f2d1be 100644 --- a/apps/devhub/views.py +++ b/apps/devhub/views.py @@ -58,7 +58,7 @@ from versions.models import Version from product_details import product_details from zadmin.models import ValidationResult -from . import forms, tasks, feeds, responsys, signals +from . import forms, tasks, feeds, signals log = commonware.log.getLogger('z.devhub') paypal_log = commonware.log.getLogger('z.paypal') @@ -1613,10 +1613,11 @@ def newsletter(request): if request.method == 'POST': if form.is_valid(): data = form.cleaned_data - responsys.subscribe.delay( - 'ABOUT_ADDONS', data['email'], data['format'], - responsys.make_source_url(request), request.LANG, - data['region']) + # Responsys expects the URL in the format example.com/foo. + responsys_url = request.get_host() + request.get_full_path() + tasks.subscribe_to_responsys.delay('ABOUT_ADDONS', data['email'], + data['format'], responsys_url, + request.LANG, data['region']) messages.success(request, _('Thanks for subscribing!')) return redirect('devhub.community.newsletter')