Move task so celery will register it (bug 693828)
This commit is contained in:
Родитель
b40d450d4d
Коммит
bfd2e2a5a3
|
@ -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: <campaign>_FLG and <campaign>_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
|
|
@ -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: <campaign>_FLG and <campaign>_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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче