Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def post(self, request, entry_page_id, *args, **kwargs):
try:
entry_page = EntryPage.objects.get(pk=entry_page_id)
blog_page = entry_page.blog_page
num_comments = 0
if blog_page.disqus_api_secret:
num_comments = get_num_comments_with_disqus(blog_page, entry_page)
entry_page.num_comments = num_comments
entry_page.save()
return HttpResponse()
except EntryPage.DoesNotExist:
raise Http404
creation_date = timezone.make_aware(creation_date, pytz.timezone('GMT'))
content = content.decode('UTF-8')
excerpt = strip_tags(item_node.find(u'{{{0:s}excerpt/}}encoded'.format(self.WP_NS)).text or '')
if not excerpt and content:
excerpt = Truncator(content).words(50)
slug = slugify(title)[:255] or u'post-{0:s}'.format(item_node.find(u'{{{0:s}}}post_id'.format(self.WP_NS)).text)
creator = item_node.find('{http://purl.org/dc/elements/1.1/}creator').text
try:
entry_date = datetime.strptime(item_node.find(u'{{{0:s}}}post_date_gmt'.format(self.WP_NS)).text,
'%Y-%m-%d %H:%M:%S')
except ValueError:
entry_date = datetime.strptime(item_node.find(u'{{{0:s}}}post_date'.format(self.WP_NS)).text,
'%Y-%m-%d %H:%M:%S')
# Create page
try:
page = EntryPage.objects.get(slug=slug)
except EntryPage.DoesNotExist:
page = EntryPage(
title=title,
body=content,
excerpt=strip_tags(excerpt),
slug=slug,
go_live_at=entry_date,
first_published_at=creation_date,
date=creation_date,
owner=self.authors.get(creator),
seo_title=title,
search_description=excerpt,
live=item_node.find(u'{{{0:s}}}status'.format(self.WP_NS)).text == 'publish')
self.blogpage.add_child(instance=page)
revision = self.blogpage.save_revision()
revision.publish()