2 Commits 375a757a8d ... bea1b44204

Author SHA1 Message Date
  zPlus bea1b44204 Fix #83 convert text URLs to links. 5 years ago
  zPlus 9358dda803 Fix #84 Add list of topics to posts' page. 5 years ago
3 changed files with 29 additions and 3 deletions
  1. 4 2
      freepost/__init__.py
  2. 18 0
      freepost/database.py
  3. 7 1
      freepost/templates/post.html

+ 4 - 2
freepost/__init__.py

@@ -38,11 +38,11 @@ template = functools.partial (
             'md2txt': lambda text: bleach.clean (markdown.markdown (text),
                                                  tags=[], attributes={}, styles=[], strip=True),
             # Convert markdown to html
-            'md2html': lambda text: bleach.clean (markdown.markdown (
+            'md2html': lambda text: bleach.clean (bleach.linkify (markdown.markdown (
                                         text,
                                         # https://python-markdown.github.io/extensions/
                                         extensions=[ 'extra', 'admonition', 'nl2br', 'smarty' ],
-                                        output_format='html5')),
+                                        output_format='html5'))),
             # Get the domain part of a URL
             'netloc': lambda url: urlparse (url).netloc
         },
@@ -476,6 +476,7 @@ def post_thread (hash_id):
     user = session.user ()
     post = database.get_post (hash_id, user['id'] if user else None)
     comments = database.get_post_comments (post['id'], user['id'] if user else None)
+    topics = database.get_post_topics (post['id'])
     
     # Group comments by parent
     comments_tree = {}
@@ -520,6 +521,7 @@ def post_thread (hash_id):
         'post.html',
         post=post,
         comments=comments,
+        topics=topics,
         show_source=show_source,
         votes = {
             'post': {},

+ 18 - 0
freepost/database.py

@@ -441,6 +441,24 @@ def get_post_comments (post_id, session_user_id = None):
     
     return cursor.fetchall ()
 
+# Retrieve all topics for a specific post
+def get_post_topics (post_id):
+    cursor = db.cursor (MySQLdb.cursors.DictCursor)
+    
+    cursor.execute (
+        """
+        SELECT T.name
+        FROM topic AS T
+        WHERE T.post_id = %(post)s
+        ORDER BY T.name ASC
+        """,
+        {
+            'post': post_id
+        }
+    )
+    
+    return cursor.fetchall ()
+
 # Submit a new comment to a post
 def new_comment (comment_text, post_hash_id, user_id, parent_user_id = None, parent_comment_id = None):
     # Create a hash_id for the new comment

+ 7 - 1
freepost/templates/post.html

@@ -25,7 +25,13 @@
                 {{ post.link|netloc }}
             </div>
         {% endif %}
-
+        
+        <div class="topics">
+            {% for topic in topics %}
+                <a href="{{ url ('topic', name=topic.name) }}" class="topic">{{ topic.name }}</a>
+            {% endfor %}
+        </div>
+        
         <div class="info">
             {{ vote ('post', post, user) }}