Skip to content
Browse files

Merge pull request #4 from jbinary/fixes

Fixes
  • Loading branch information...
2 parents 7294566 + 25a1c0e commit 6dbd3f1d3e82fa9d33e442e6a62375e8536e44f0 @stefanfoulis committed
Showing with 16 additions and 6 deletions.
  1. +12 −4 database_email_backend/admin.py
  2. +4 −2 database_email_backend/backend.py
View
16 database_email_backend/admin.py
@@ -7,8 +7,10 @@
from django.core.mail import message
from django.db.models import Count
from django.utils.functional import update_wrapper
-from database_email_backend.models import Email, Attachment
from django.utils.translation import ugettext as _
+from django.template.defaultfilters import linebreaks_filter
+
+from database_email_backend.models import Email, Attachment
WIDE_INPUT_SIZE = '80'
@@ -41,8 +43,8 @@ class EmailAdmin(admin.ModelAdmin):
list_display = ('from_email', 'to_emails', 'subject', 'body_stripped', 'sent_at', 'attachment_count')
date_hierarchy = 'sent_at'
search_fields = ('from_email', 'to_emails', 'subject', 'body',)
- exclude = ('raw',)
- readonly_fields = list_display + ('cc_emails', 'bcc_emails', 'all_recipients', 'headers', 'body',)
+ exclude = ('raw', 'body')
+ readonly_fields = list_display + ('cc_emails', 'bcc_emails', 'all_recipients', 'headers', 'body_br',)
inlines = (AttachmentInlineAdmin,)
def queryset(self, request):
@@ -86,6 +88,12 @@ def serve_attachment(self, request, email_id, attachment_id, filename, extra_con
response["Content-Length"] = len(attachment.content)
return response
+ def body_br(self, obj):
+ return linebreaks_filter(obj.body)
+ body_br.allow_tags = True
+ body_br.short_description = 'body'
+ body_br.admin_order_field = 'body'
+
admin.site.register(Email, EmailAdmin)
@@ -155,4 +163,4 @@ def get_model_perms(self, request):
'change': False,
'delete': False
}
-admin.site.register(SendEmail, SendEmailAdmin)
+admin.site.register(SendEmail, SendEmailAdmin)
View
6 database_email_backend/backend.py
@@ -1,14 +1,14 @@
#-*- coding: utf-8 -*-
from email.MIMEBase import MIMEBase
+
from django.core.mail.backends.base import BaseEmailBackend
from django.utils.encoding import smart_unicode
+
from database_email_backend.models import Email, Attachment
class DatabaseEmailBackend(BaseEmailBackend):
def send_messages(self, email_messages):
- if not email_messages:
- return
for message in email_messages:
email = Email.objects.create(
from_email = u'%s' % message.from_email,
@@ -35,3 +35,5 @@ def send_messages(self, email_messages):
content=content,
mimetype=mimetype
)
+ return len(email_messages)
+

0 comments on commit 6dbd3f1

Please sign in to comment.
Something went wrong with that request. Please try again.