def run_task(self, task, *args, **kwargs):
tasks = {
"cleanup-messages" : self.messages.queue.cleanup,
+ "rebake-wiki" : self.wiki.rebake,
"scan-files" : self.releases.scan_files,
"send-all-messages" : self.messages.queue.send_all,
"update-blog-feeds" : self.blog.update_feeds,
import logging
import os.path
import re
+import tornado.gen
import urllib.parse
from . import misc
page = self._get_page("INSERT INTO wiki(page, author_uid, markdown, changes, address) \
VALUES(%s, %s, %s, %s, %s) RETURNING *", page, author.uid, content or None, changes, address)
+ # Render markdown
+ page.bake()
+
# Send email to all watchers
page._send_watcher_emails(excludes=[author])
# Just creates a blank last version of the page
self.create_page(page, author=author, content=None, **kwargs)
+ @tornado.gen.coroutine
+ def rebake(self):
+ """
+ Re-renders all wiki pages
+ """
+ pages = self._get_pages("SELECT * FROM wiki ORDER BY timestamp DESC")
+
+ for page in pages:
+ logging.info("Baking %s from %s" % (page.page, page.timestamp))
+
+ with self.db.transaction():
+ page.bake()
+
def make_breadcrumbs(self, url):
# Split and strip all empty elements (double slashes)
parts = list(e for e in url.split("/") if e)
def html(self):
return self.data.html or self._render(self.markdown)
+ def bake(self):
+ """
+ Renders the page's markdown to HTML and stores
+ it in the database.
+ """
+ self.db.execute("UPDATE wiki SET html = %s WHERE id = %s",
+ self._render(self.markdown), self.id)
+
@property
def timestamp(self):
return self.data.timestamp