Byteflow has a feature when authoring blogs that allows you to save your post as a draft. I use it constantly, but someone requested via a ticket to have a “Preview” option, allowing you to see your blog post (logically the same as saving it as a draft) before you post it. If anyone is interested in utilizing a “Preview” option, see the patch below. Basically all it does is utilize the draft option, but takes you to the generated draft to “Preview” it before you make it public. I don’t think it will be committed into the code base, but if anyone is looking to have this functionality now, see below code.
# HG changeset patch
# User bsmith@linode.just-another.net
# Date 1212543690 14400
# Node ID 4282e3429846d5193a798bdd14807f6c3ef579ac
# Parent 2c4fb2b21cc5c7b9cfbf7a1692af6e34a9bb5391
Preview post (and draft it).
diff -r 2c4fb2b21cc5 -r 4282e3429846 apps/blog/models.py
--- a/apps/blog/models.py Mon Jun 02 19:41:33 2008 -0400
+++ b/apps/blog/models.py Tue Jun 03 21:41:30 2008 -0400
@@ -7,7 +7,7 @@ from django.utils.html import strip_tags
from django.utils.html import strip_tags
from django.contrib.contenttypes import generic
from django.dispatch import dispatcher
—
+from lib.exceptions import RedirectException
from lib.helpers import reverse
from render import render
from blog.managers import PostManager, PublicPostManager, FeaturedPostManager
@@ -38,6 +38,7 @@ class Post(models.Model):
upd_date = models.DateTimeField(_(u'Date'), auto_now=True, editable=False)
is_draft = models.BooleanField(verbose_name=u'Post would act as draft', default=False)
is_featured = models.BooleanField(verbose_name=u'Featured post', default=False)
+ is_preview = models.BooleanField(verbose_name=u'Preview Before Submission', default=True)
enable_comments = models.BooleanField(default=True)
tags = TagField()
@@ -53,7 +54,7 @@ class Post(models.Model):
search_fields = ('name', 'text')
list_filter = ('date', )
fields = (
— (None, {'fields': ('author', ('name', 'slug'), 'tags', 'text', 'render_method', 'date', ('is_draft', 'enable_comments'))}),
+ (None, {'fields': ('author', ('name', 'slug'), 'tags', 'text', 'render_method', 'date',('is_preview','is_draft', 'enable_comments'))}),
('Featured post', {'classes': 'collapse', 'fields': ('is_featured', 'teaser')}),
)
if settings.WYSIWYG_ENABLE:
@@ -80,7 +81,13 @@ class Post(models.Model):
self.slug = slugify(self.name)
self.text = self.text.strip()
self.html = render(self.text, self.render_method, unsafe=True)
— super(Post, self).save()
+ if self.is_preview:
+ message = 'This is a preview of your post'
+ self.is_draft = True
+ super(Post, self).save()
+ raise RedirectException(self.get_absolute_url(), notice_message=message)
+ else:
+ super(Post, self).save()
def comments_open(self):
if settings.COMMENTS_EXPIRE_DAYS:
And to implement it via a template, try something like this:
{% if object.is_preview %}
<div id="post-draft">THIS IS A PREVIEW <a href="/admin/blog/post/{{ object.id }}/">Continue Editing</a></div>
{% endif %}

Comments
Hey Benajamin,
I handle this “operationally”. Like you suggest, I click the “draft” button, and when I’m ready, click on “save and continue editing”. When the edit form reshows, there is a button that says “view on site” in the upper right. I open that up in a new tab, and presto, a “preview”. FWIW, once it’s open, you can continue to “save and continue edit”, and then refresh it and the new changes are reflected in that tab. (Does that make sense?)
Once I’m done, I unclick “draft”
That’s usually the way I do it as well. This patch just drops an extra step :D. Like I said, I don’t think it will be included in the byteflow code base, I just wanted it out there in case anyone found it useful. I’m sure there will be a smoother way to do “preview” a post once the admin interface is complete.
Ah, I hope I didn’t come across as devaluing your post/code. I am certainly very happy you posted it and hope you continue! I did apply your tag patch — at least I think I did.
Oh no, I didn’t think that at all! I am thankful for your input, it’s always constructive. Also, I should let you know that I think your re-captcha is broken, or it doesn’t like me.. I tried to respond to one of your posts and it just won’t take my input.
Ah, thanks for the heads up. I switched from re-captcha to simple. Wonder why it stopped working…..ah, well.
Comment form for «Byteflow preview blog post»