From 4ae02f421c7178f631ac61ec620685886b744502 Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Tue, 6 Dec 2011 14:00:52 -0500 Subject: [PATCH] Add form fields for future date publishing. --- biblion/admin.py | 1 + biblion/forms.py | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/biblion/admin.py b/biblion/admin.py index 0fbb14b..63adb7f 100644 --- a/biblion/admin.py +++ b/biblion/admin.py @@ -30,6 +30,7 @@ class PostAdmin(admin.ModelAdmin): "teaser", "content", "publish", + "publish_date", ] if can_tweet(): fields.append("tweet") diff --git a/biblion/forms.py b/biblion/forms.py index 5261157..328a433 100644 --- a/biblion/forms.py +++ b/biblion/forms.py @@ -71,6 +71,10 @@ class PostForm(forms.ModelForm): required = False, help_text = u"Checking this will publish this article on the site", ) + publish_date = forms.DateTimeField( + required = False, + help_text = u"Posts will not appear on the site until the publish date.", + ) if can_tweet(): tweet = forms.BooleanField( @@ -110,9 +114,11 @@ def __init__(self, *args, **kwargs): # @@@ can a post be unpublished then re-published? should be pulled # from latest revision maybe? self.fields["publish"].initial = bool(post.published) + self.fields["publish_date"].initial = post.published # @@@ remove it for now when editing if self.instance is not None: del self.fields["publish"] + del self.fields["publish_date"] def save(self): post = super(PostForm, self).save(commit=False) @@ -124,7 +130,10 @@ def save(self): if Post.objects.filter(pk=post.pk, published=None).count(): if self.cleaned_data["publish"]: post.published = datetime.datetime.now() - + + if self.cleaned_data["publish_date"]: + post.published = self.cleaned_data["publish_date"] + render_func = curry(load_path_attr(PARSER[0]), **PARSER[1]) post.teaser_html = render_func(self.cleaned_data["teaser"]) @@ -177,7 +186,11 @@ class AdminPostForm(forms.ModelForm): required = False, help_text = u"Checking this will publish this articles on the site", ) - + publish_date = forms.DateTimeField( + required = False, + help_text = u"Posts will not appear on the site until the publish date." + ) + if can_tweet(): tweet = forms.BooleanField( required = False, @@ -203,6 +216,7 @@ def __init__(self, *args, **kwargs): # @@@ can a post be unpublished then re-published? should be pulled # from latest revision maybe? self.fields["publish"].initial = bool(post.published) + self.fields["publish_date"].initial = post.published def save(self): post = super(AdminPostForm, self).save(commit=False) @@ -214,7 +228,10 @@ def save(self): if Post.objects.filter(pk=post.pk, published=None).count(): if self.cleaned_data["publish"]: post.published = datetime.datetime.now() - + + if self.cleaned_data["publish_date"]: + post.published = self.cleaned_data["publish_date"] + render_func = curry(load_path_attr(PARSER[0]), **PARSER[1]) post.teaser_html = render_func(self.cleaned_data["teaser"])