Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_context(self, request, *args, **kwargs):
context = super(EntryPage, self).get_context(request, *args, **kwargs)
context['blog_page'] = self.blog_page
return context
body = StreamField(MyStreamBlock(), blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
class LeftSidebarPage(MenuPage):
body = StreamField(MyStreamBlock(), blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
class StreamFieldEntryPage(EntryPage):
streamfield = StreamField(MyStreamBlock(), blank=True)
content_panels = EntryPage.content_panels + [
StreamFieldPanel('streamfield')
]
BlogPage.subpage_types.append(StreamFieldEntryPage)
# Let everyone know when a new page is published
def send_to_discord(sender, **kwargs):
instance = kwargs['instance']
# Only post new post. No updates.
if instance.first_published_at != instance.last_published_at:
return
if settings.DEBUG:
return
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()
self.import_entry_tags(item_node.findall('category'), page)
)
# I tryed to convert excerpt to markdown using tomd without success
values = {
"content": "Breaking news on OSR website !",
"embeds": [{
"title": instance.title,
"url": "https://openstudyroom.org" + instance.url,
"description": excerpt,
}]
}
r = requests.post(discord_url, json=values)
r.raise_for_status()
# Register two receivers
page_published.connect(send_to_discord, sender=EntryPage)
page_published.connect(send_to_discord, sender=StreamFieldEntryPage)
@receiver(post_save, sender=ForumPost)
def forum_post_to_discord(sender, instance, **kwargs):
# don't announce edits
instance.refresh_from_db()
if instance.updates_count > 0:
return
# don't announce private admins forums forum.
# This should be properly handled with a test if anonymous user can read forum.
parent_id = instance.topic.forum.parent
if parent_id is not None and parent_id.pk == 12:
return
if settings.DEBUG:
return
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
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()
self.import_entry_tags(item_node.findall('category'), page)
self.import_entry_categories(item_node.findall('category'), page)