Skip to content

Commit

Permalink
Add form fields for future date publishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrb committed Dec 6, 2011
1 parent fcb2d05 commit 4ae02f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions biblion/admin.py
Expand Up @@ -30,6 +30,7 @@ class PostAdmin(admin.ModelAdmin):
"teaser",
"content",
"publish",
"publish_date",
]
if can_tweet():
fields.append("tweet")
Expand Down
23 changes: 20 additions & 3 deletions biblion/forms.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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"])
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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"])
Expand Down

0 comments on commit 4ae02f4

Please sign in to comment.