Guilherme Gondim committed 9d3a4a6

require a content or raise a validation error and add default text to Newsletter.text_content when the newsletter has only html content

Comments (0)

Files changed (1)


 from datetime import datetime
 from django.conf import settings
+from django.core.exceptions import ValidationError
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
     def __unicode__(self):
         return unicode(self.title)
+    def clean(self):
+        if not self.html_content and not self.text_content:
+            raise ValidationError(_('You must provide a HTML or text content!'))
+        # Set the pub_date for published items if it hasn't been set already.
+        if self.status == 'published' and self.pub_date is None:
+            self.pub_date =
+    def save(self, *args, **kwargs):
+        if not self.text_content and self.html_content:
+            self.text_content = _(
+                'This message contains an HTML formatted message but your '
+                'e-mail client does not support the display of HTML.'
+            )
+        return super(Newsletter, self).save(*args, **kwargs)
     def send(self):
         subject = self.title
         text_content, html_content = self.text_content, self.html_content
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.