Permalink
Browse files

Merge pull request #15 from oraclebill/fix_django_ugettextlazy_incomp…

…atibility

Fix django ugettextlazy incompatibility
  • Loading branch information...
2 parents 7eae449 + ae94fb3 commit 86d28a3ad12bc107e01b1f1de5bed551e12541d0 @themartorana committed Dec 15, 2011
Showing with 18 additions and 6 deletions.
  1. +16 −5 postmark/core.py
  2. +2 −1 test/demo/forms.py
View
@@ -26,6 +26,18 @@
except ImportError:
raise Exception('Cannot use python-postmark library without Python 2.6 or greater, or Python 2.4 or 2.5 and the "simplejson" library')
+class PMJSONEncoder(json.JSONEncoder):
+ def default(self, o):
+ try:
+ if hasattr(o, '_proxy____str_cast') and callable(o._proxy____str_cast):
+ return o._proxy____str_cast()
+ elif hasattr(o, '_proxy____unicode_cast'):
+ return unicode(o)
+ except:
+ pass
+
+ return super(PMJSONEncoder, self).default(o)
+
#
#
__POSTMARK_URL__ = 'http://api.postmarkapp.com/'
@@ -379,14 +391,13 @@ def send(self, test=None):
# If this is a test, just print the message
if test:
- print 'JSON message is:\n%s' % json.dumps(json_message)
+ print 'JSON message is:\n%s' % json.dumps(json_message, cls=PMJSONEncoder)
return
-
# Set up the url Request
req = urllib2.Request(
__POSTMARK_URL__ + 'email',
- json.dumps(json_message),
+ json.dumps(json_message, cls=PMJSONEncoder),
{
'Accept': 'application/json',
'Content-Type': 'application/json',
@@ -464,7 +475,7 @@ def send(self, test=None):
req = urllib2.Request(
__POSTMARK_URL__ + 'email/batch',
- json.dumps(json_message),
+ json.dumps(json_message, cls=PMJSONEncoder),
{
'Accept': 'application/json',
'Content-Type': 'application/json',
@@ -483,7 +494,7 @@ def send(self, test=None):
# If this is a test, just print the message
if test:
- print 'JSON message is:\n%s' % json.dumps(json_message)
+ print 'JSON message is:\n%s' % json.dumps(json_message, cls=PMJSONEncoder)
return
# Attempt send
View
@@ -2,6 +2,7 @@
from django import forms
from django.conf import settings
from django.core.mail import send_mail
+from django.utils.translation import ugettext_lazy
class EmailForm(forms.Form):
@@ -14,7 +15,7 @@ def save(self, fail_silently=False):
"""
Build and send the email message.
"""
- send_mail(subject=self.cleaned_data['subject'],
+ send_mail(subject=ugettext_lazy(self.cleaned_data['subject']),
message=self.cleaned_data['body'],
from_email=self.cleaned_data['sender'],
recipient_list=[addr.strip() for addr in self.cleaned_data['to'].split(',')],

0 comments on commit 86d28a3

Please sign in to comment.