diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-02-25 20:01:08 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-02-25 20:01:08 +0000 |
| commit | 8a70334640b31229d53e982bd59d951fe15aecbc (patch) | |
| tree | 793c50ad4f6fea8de6507672aa123adade5f3abf /django/core | |
| parent | 43829a95d3e5740250794a0b4400fd813e724a2e (diff) | |
newforms-admin: Merged to [4579]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4580 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/mail.py | 22 | ||||
| -rw-r--r-- | django/core/validators.py | 10 |
2 files changed, 24 insertions, 8 deletions
diff --git a/django/core/mail.py b/django/core/mail.py index cc99659adb..b9966c2af0 100644 --- a/django/core/mail.py +++ b/django/core/mail.py @@ -3,7 +3,8 @@ from django.conf import settings from email.MIMEText import MIMEText from email.Header import Header -import smtplib, rfc822 +from email.Utils import formatdate +import smtplib import socket import time import random @@ -33,21 +34,34 @@ class SafeMIMEText(MIMEText): val = Header(val, settings.DEFAULT_CHARSET) MIMEText.__setitem__(self, name, val) -def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD): +def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None): """ Easy wrapper for sending a single message to a recipient list. All members of the recipient list will see the other recipients in the 'To' field. + + If auth_user is None, the EMAIL_HOST_USER setting is used. + If auth_password is None, the EMAIL_HOST_PASSWORD setting is used. """ + if auth_user is None: + auth_user = settings.EMAIL_HOST_USER + if auth_password is None: + auth_password = settings.EMAIL_HOST_PASSWORD return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password) -def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD): +def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None): """ Given a datatuple of (subject, message, from_email, recipient_list), sends each message to each recipient list. Returns the number of e-mails sent. If from_email is None, the DEFAULT_FROM_EMAIL setting is used. If auth_user and auth_password are set, they're used to log in. + If auth_user is None, the EMAIL_HOST_USER setting is used. + If auth_password is None, the EMAIL_HOST_PASSWORD setting is used. """ + if auth_user is None: + auth_user = settings.EMAIL_HOST_USER + if auth_password is None: + auth_password = settings.EMAIL_HOST_PASSWORD try: server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT) if auth_user and auth_password: @@ -65,7 +79,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST msg['Subject'] = subject msg['From'] = from_email msg['To'] = ', '.join(recipient_list) - msg['Date'] = rfc822.formatdate() + msg['Date'] = formatdate() try: random_bits = str(random.getrandbits(64)) except AttributeError: # Python 2.3 doesn't have random.getrandbits(). diff --git a/django/core/validators.py b/django/core/validators.py index a2f3dc3bc3..ebfbd3961e 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -312,11 +312,12 @@ class RequiredIfOtherFieldGiven(RequiredIfOtherFieldsGiven): RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message) class RequiredIfOtherFieldEquals(object): - def __init__(self, other_field, other_value, error_message=None): + def __init__(self, other_field, other_value, error_message=None, other_label=None): self.other_field = other_field self.other_value = other_value + other_label = other_label or other_value self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), { - 'field': other_field, 'value': other_value}) + 'field': other_field, 'value': other_label}) self.always_test = True def __call__(self, field_data, all_data): @@ -324,11 +325,12 @@ class RequiredIfOtherFieldEquals(object): raise ValidationError(self.error_message) class RequiredIfOtherFieldDoesNotEqual(object): - def __init__(self, other_field, other_value, error_message=None): + def __init__(self, other_field, other_value, other_label=None, error_message=None): self.other_field = other_field self.other_value = other_value + other_label = other_label or other_value self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), { - 'field': other_field, 'value': other_value}) + 'field': other_field, 'value': other_label}) self.always_test = True def __call__(self, field_data, all_data): |
