Reformat using black
This commit is contained in:
parent
efee4ad081
commit
a87fb49918
221 changed files with 19127 additions and 7310 deletions
|
@ -12,27 +12,35 @@ import re
|
|||
|
||||
|
||||
# https://lsimons.wordpress.com/2011/03/17/stripping-illegal-characters-out-of-xml-in-python/
|
||||
def escape_xml_illegal_chars(val, replacement='?'):
|
||||
_illegal_xml_chars_RE = re.compile(u'[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]')
|
||||
def escape_xml_illegal_chars(val, replacement="?"):
|
||||
_illegal_xml_chars_RE = re.compile(
|
||||
"[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]"
|
||||
)
|
||||
return _illegal_xml_chars_RE.sub(replacement, val)
|
||||
|
||||
|
||||
class ProblemFeed(Feed):
|
||||
title = 'Recently Added %s Problems' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest problems added on the %s website' % settings.SITE_LONG_NAME
|
||||
title = "Recently Added %s Problems" % settings.SITE_NAME
|
||||
link = "/"
|
||||
description = (
|
||||
"The latest problems added on the %s website" % settings.SITE_LONG_NAME
|
||||
)
|
||||
|
||||
def items(self):
|
||||
return Problem.objects.filter(is_public=True, is_organization_private=False).defer('description')\
|
||||
.order_by('-date', '-id')[:25]
|
||||
return (
|
||||
Problem.objects.filter(is_public=True, is_organization_private=False)
|
||||
.defer("description")
|
||||
.order_by("-date", "-id")[:25]
|
||||
)
|
||||
|
||||
def item_title(self, problem):
|
||||
return problem.name
|
||||
|
||||
def item_description(self, problem):
|
||||
key = 'problem_feed:%d' % problem.id
|
||||
key = "problem_feed:%d" % problem.id
|
||||
desc = cache.get(key)
|
||||
if desc is None:
|
||||
desc = str(markdown(problem.description, 'problem'))[:500] + '...'
|
||||
desc = str(markdown(problem.description, "problem"))[:500] + "..."
|
||||
desc = escape_xml_illegal_chars(desc)
|
||||
cache.set(key, desc, 86400)
|
||||
return desc
|
||||
|
@ -49,21 +57,21 @@ class AtomProblemFeed(ProblemFeed):
|
|||
|
||||
|
||||
class CommentFeed(Feed):
|
||||
title = 'Latest %s Comments' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest comments on the %s website' % settings.SITE_LONG_NAME
|
||||
title = "Latest %s Comments" % settings.SITE_NAME
|
||||
link = "/"
|
||||
description = "The latest comments on the %s website" % settings.SITE_LONG_NAME
|
||||
|
||||
def items(self):
|
||||
return Comment.most_recent(AnonymousUser(), 25)
|
||||
|
||||
def item_title(self, comment):
|
||||
return '%s -> %s' % (comment.author.user.username, comment.page_title)
|
||||
return "%s -> %s" % (comment.author.user.username, comment.page_title)
|
||||
|
||||
def item_description(self, comment):
|
||||
key = 'comment_feed:%d' % comment.id
|
||||
key = "comment_feed:%d" % comment.id
|
||||
desc = cache.get(key)
|
||||
if desc is None:
|
||||
desc = str(markdown(comment.body, 'comment'))
|
||||
desc = str(markdown(comment.body, "comment"))
|
||||
desc = escape_xml_illegal_chars(desc)
|
||||
cache.set(key, desc, 86400)
|
||||
return desc
|
||||
|
@ -80,21 +88,23 @@ class AtomCommentFeed(CommentFeed):
|
|||
|
||||
|
||||
class BlogFeed(Feed):
|
||||
title = 'Latest %s Blog Posts' % settings.SITE_NAME
|
||||
link = '/'
|
||||
description = 'The latest blog posts from the %s' % settings.SITE_LONG_NAME
|
||||
title = "Latest %s Blog Posts" % settings.SITE_NAME
|
||||
link = "/"
|
||||
description = "The latest blog posts from the %s" % settings.SITE_LONG_NAME
|
||||
|
||||
def items(self):
|
||||
return BlogPost.objects.filter(visible=True, publish_on__lte=timezone.now()).order_by('-sticky', '-publish_on')
|
||||
return BlogPost.objects.filter(
|
||||
visible=True, publish_on__lte=timezone.now()
|
||||
).order_by("-sticky", "-publish_on")
|
||||
|
||||
def item_title(self, post):
|
||||
return post.title
|
||||
|
||||
def item_description(self, post):
|
||||
key = 'blog_feed:%d' % post.id
|
||||
key = "blog_feed:%d" % post.id
|
||||
summary = cache.get(key)
|
||||
if summary is None:
|
||||
summary = str(markdown(post.summary or post.content, 'blog'))
|
||||
summary = str(markdown(post.summary or post.content, "blog"))
|
||||
summary = escape_xml_illegal_chars(summary)
|
||||
cache.set(key, summary, 86400)
|
||||
return summary
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue