Skip to content

Commit

Permalink
add a post_published signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schreiber committed Jan 4, 2012
1 parent 1e37dd4 commit 3a0f116
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 9 additions & 9 deletions biblion/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.contrib.sites.models import Site

from biblion.models import Biblion, Post, Revision, Image
from biblion.signals import post_published
from biblion.utils.twitter import can_tweet
from biblion.utils.slugify import slugify_unique

Expand Down Expand Up @@ -219,24 +220,23 @@ def __init__(self, *args, **kwargs):

def save(self):
post = super(AdminPostForm, self).save(commit=False)

if post.pk is None:
if self.cleaned_data["publish"]:
post.published = datetime.datetime.now()
else:
if Post.objects.filter(pk=post.pk, published=None).count():
if self.cleaned_data["publish"]:
post.published = datetime.datetime.now()
# only publish the first time publish has been checked
if (post.pk is None or Post.objects.filter(pk=post.pk, published=None).count()) and self.cleaned_data["publish"]:
post.published = datetime.datetime.now()
send_published_signal = True

if self.cleaned_data["publish_date"]:
post.published = self.cleaned_data["publish_date"]

post.markup_type = self.cleaned_data["markup_type"]
post.teaser = self.cleaned_data["teaser"]
post.content = self.cleaned_data["content"]
post.updated = datetime.datetime.now()
post.save()

if send_published_signal:
post_published.send(sender=self, pk=post.pk)

r = Revision()
r.post = post
r.title = post.title
Expand Down
4 changes: 4 additions & 0 deletions biblion/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.dispatch import Signal


post_published = Signal(providing_args=["pk"])

0 comments on commit 3a0f116

Please sign in to comment.