From 2a9ddddc897881a5670a6d96877782acfadca8a7 Mon Sep 17 00:00:00 2001 From: Aaron Schif Date: Mon, 10 Feb 2014 13:40:09 -0600 Subject: [PATCH] Functional, rudimentary and glitchy --- djcelery_email/fields.py | 18 +++++++++++------- djcelery_email/tasks.py | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/djcelery_email/fields.py b/djcelery_email/fields.py index 4a1621b..6283d2a 100644 --- a/djcelery_email/fields.py +++ b/djcelery_email/fields.py @@ -2,9 +2,13 @@ import six from django.core.validators import validate_email -from django.core.exceptions import ValidationError from django.db.models import TextField, SubfieldBase from django.utils.translation import ugettext as _ +from django.forms import Field + + +class EmailsFormField(Field): + pass class EmailsListField(TextField): @@ -20,9 +24,8 @@ def to_python(self, value): def validate(self, value, model_instance): super(EmailsListField, self).validate(value, model_instance) - if self.blank and not value: - for email in value: - validate_email(email) + for email in value: + validate_email(email) def get_prep_value(self, value): if isinstance(value, six.string_types): @@ -30,6 +33,7 @@ def get_prep_value(self, value): else: return ', '.join(value) - def value_to_string(self, obj): - value = self._get_val_from_obj(obj) - return self.get_db_prep_value(value) + def formfield(self, **kwargs): + defaults = {'form_class': EmailsFormField} + defaults.update(kwargs) + return super(EmailsListField, self).formfield(**defaults) \ No newline at end of file diff --git a/djcelery_email/tasks.py b/djcelery_email/tasks.py index 1caaea0..b28bc83 100644 --- a/djcelery_email/tasks.py +++ b/djcelery_email/tasks.py @@ -1,7 +1,7 @@ from django.conf import settings from django.core.mail import get_connection -from celery.task import task +from celery import shared_task from djcelery_email.models import EMail @@ -20,7 +20,7 @@ # @task(**TASK_CONFIG) -@task() +@shared_task() def send_emails(): conn = get_connection(backend=BACKEND) @@ -34,7 +34,7 @@ def send_emails(): finally: conn.close() -@task() +@shared_task() def clean_old(): pass # EMail.objects.filter()