aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/database.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-06 18:21:34 +0100
committerGravatar Gareth Coles <[email protected]>2018-05-06 18:21:34 +0100
commitefb902f3f293db4aac6e57b9f3a84143d84a90e9 (patch)
tree69fd91e690f1b8e150b839927c8bb312ebf81abc /pysite/database.py
parentI linted that, I swear (diff)
[Wiki] Misc improvements, plus a beta search feature
Diffstat (limited to 'pysite/database.py')
-rw-r--r--pysite/database.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/pysite/database.py b/pysite/database.py
index 86c8685d..41fbd253 100644
--- a/pysite/database.py
+++ b/pysite/database.py
@@ -1,8 +1,10 @@
# coding=utf-8
+import html
import json
import logging
import os
from typing import Any, Callable, Dict, Iterator, List, Optional, Union
+import re
import rethinkdb
from flask import abort
@@ -22,6 +24,9 @@ ALL_TABLES = {
"wiki_revisions": "id"
}
+STRIP_REGEX = re.compile(r"<[^<]+?>")
+WIKI_TABLE = "wiki"
+
class RethinkDB:
@@ -55,6 +60,13 @@ class RethinkDB:
tables = ", ".join([f"{table} ({count} items)" for table, count in initialized.items()])
self.log.debug(f"Initialized the following tables: {tables}")
+ # Upgrade wiki articles
+ for article in self.pluck(WIKI_TABLE, "html", "text", "slug"):
+ if "text" not in article:
+ article["text"] = html.unescape(STRIP_REGEX.sub("", article["html"]).strip())
+
+ self.insert(WIKI_TABLE, article, conflict="update")
+
def create_tables(self) -> List[str]:
"""
Creates whichever tables exist in the ALL_TABLES
@@ -496,9 +508,6 @@ class RethinkDB:
"""
Map a function over every document in a table, with the possibility of modifying it
- r.table('users').map(
- lambda doc: doc.merge({'user_id': doc['id']}).without('id')).run(conn)
-
As an example, you could do the following to rename the "id" field to "user_id" for all documents
in the "users" table.