Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use a choice list instead of a checkbox to choose between raw HTML an…

…d reST.
  • Loading branch information...
commit 536176cf8bab4716357f93ff9222a9ecfc05cc1f 1 parent 4aba276
@jphalip jphalip authored
View
37 django_website/blog/migrations/0008_auto__del_field_entry_use_raw_html.py
@@ -0,0 +1,37 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'Entry.use_raw_html'
+ db.delete_column('blog_entries', 'use_raw_html')
+
+
+ def backwards(self, orm):
+
+ # Adding field 'Entry.use_raw_html'
+ db.add_column('blog_entries', 'use_raw_html', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+
+ models = {
+ 'blog.entry': {
+ 'Meta': {'ordering': "('-pub_date',)", 'object_name': 'Entry', 'db_table': "'blog_entries'"},
+ 'author': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'body': ('django.db.models.fields.TextField', [], {}),
+ 'body_html': ('django.db.models.fields.TextField', [], {}),
+ 'headline': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'pub_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'summary': ('django.db.models.fields.TextField', [], {}),
+ 'summary_html': ('django.db.models.fields.TextField', [], {})
+ }
+ }
+
+ complete_apps = ['blog']
View
38 django_website/blog/migrations/0009_auto__add_field_entry_content_format.py
@@ -0,0 +1,38 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Entry.content_format'
+ db.add_column('blog_entries', 'content_format', self.gf('django.db.models.fields.CharField')(default='html', max_length=50), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Entry.content_format'
+ db.delete_column('blog_entries', 'content_format')
+
+
+ models = {
+ 'blog.entry': {
+ 'Meta': {'ordering': "('-pub_date',)", 'object_name': 'Entry', 'db_table': "'blog_entries'"},
+ 'author': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'body': ('django.db.models.fields.TextField', [], {}),
+ 'body_html': ('django.db.models.fields.TextField', [], {}),
+ 'content_format': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'headline': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'pub_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'summary': ('django.db.models.fields.TextField', [], {}),
+ 'summary_html': ('django.db.models.fields.TextField', [], {})
+ }
+ }
+
+ complete_apps = ['blog']
View
24 django_website/blog/models.py
@@ -1,11 +1,14 @@
import akismet
import datetime
+from docutils.core import publish_parts
+
from django.conf import settings
from django.db import models
from django.contrib.sites.models import Site
from django.contrib.comments.signals import comment_was_posted
from django.utils.encoding import smart_str
-from docutils.core import publish_parts
+from django.utils.translation import ugettext_lazy as _
+
class EntryManager(models.Manager):
@@ -16,17 +19,22 @@ def published(self):
def active(self):
return super(EntryManager, self).get_query_set().filter(is_active=True)
+CONTENT_FORMAT_CHOICES = (
+ (u'reST', u'reStructuredText'),
+ (u'html', u'Raw HTML'),
+)
+
class Entry(models.Model):
headline = models.CharField(max_length=200)
slug = models.SlugField(unique_for_date='pub_date')
- is_active = models.BooleanField(help_text="Tick to make the entry live on site (see also the publication date). Note that administrators (like yourself) are allowed to preview inactive content whereas other users and the general public aren't.", default=False)
- pub_date = models.DateTimeField(help_text='For an entry to be published, it must be active and its publication date must be in the past.')
+ is_active = models.BooleanField(help_text=_("Tick to make this entry live (see also the publication date). Note that administrators (like yourself) are allowed to preview inactive entries whereas the general public aren't."), default=False)
+ pub_date = models.DateTimeField(verbose_name=_("Publication date"), help_text=_("For an entry to be published, it must be active and its publication date must be in the past."))
+ content_format = models.CharField(choices=CONTENT_FORMAT_CHOICES, max_length=50)
summary = models.TextField()
- summary_html = models.TextField(help_text="Use reStructuredText unless specified otherwise")
- body = models.TextField(help_text="Use reStructuredText unless specified otherwise")
+ summary_html = models.TextField()
+ body = models.TextField()
body_html = models.TextField()
author = models.CharField(max_length=100)
- use_raw_html = models.BooleanField(help_text="Tick if you prefer to manually enter raw HTML instead of reStructureText formats in the summary and body. This option's main purpose is to cope with old entries that were entirely written in raw HTML.", default=False)
objects = EntryManager()
@@ -55,10 +63,10 @@ def comments_enabled(self):
return delta.days < 60
def save(self, *args, **kwargs):
- if self.use_raw_html:
+ if self.content_format == u'html':
self.summary_html = self.summary
self.body_html = self.body
- else:
+ elif self.content_format == u'reST':
settings_overrides = {
'doctitle_xform': False,
'initial_header_level': 4,
Please sign in to comment.
Something went wrong with that request. Please try again.