def save(self):
published = False
post = super(AdminPostForm, self).save(commit=False)
if post.pk is None or Post.objects.filter(pk=post.pk, published=None).count():
if self.cleaned_data["state"] == Post.STATE_CHOICES[-1][0]:
post.published = timezone.now()
published = True
render_func = curry(
load_path_attr(
settings.PINAX_BLOG_MARKUP_CHOICE_MAP[self.cleaned_data["markup"]]["parser"]
)
)
post.teaser_html = render_func(self.cleaned_data["teaser"])
post.content_html = render_func(self.cleaned_data["content"])
post.updated = timezone.now()
post.save()
r = Revision()
r.post = post
r.title = post.title
r.teaser = self.cleaned_data["teaser"]
r.content = self.cleaned_data["content"]
r.author = post.author
r.updated = post.updated
r.published = post.published
r.save()
if can_tweet() and self.cleaned_data["tweet"]:
post.tweet()
if published:
post_published.send(sender=Post, post=post)
return post
评论列表
文章目录