home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2019-01-18 20:28:24
Committer zPlus <zplus@peers.community> 2019-01-18 20:28:24
Commit 2749021 (patch)
Tree bf3b941
Parent(s)

Peers Jam - January 18th, 2019 - Add "Peers Jam" banner to freepost's homepage - Fixed #51 "Teaser Text & Feed of latest comments" - Fixed #53 "Autofocus username on login page" - Fixed #61 "Blank comments" - Fixed #64 "Next and Previous buttons at bottom of page" - Fixed #67 "Light up link of current page"


commits diff: 885970c..2749021
7 files changed, 103 insertions, 2 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 17
-rw-r--r-- freepost/database.py 23
-rw-r--r-- freepost/templates/banner.html 16
-rw-r--r-- freepost/templates/layout.html 3
-rwxr-xr-x freepost/templates/login.html 2
-rw-r--r-- freepost/templates/posts.html 15
-rw-r--r-- freepost/templates/rss_comments.xml 29

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+17/-0 M   freepost/__init__.py
index 27ab976..9aeb8f8
old size: 26K - new size: 26K
@@ -851,6 +851,23 @@ def rss (sorting):
851 851
852 852 return template ('rss.xml', base_url=base_url, posts=posts)
853 853
854 + @get ('/rss_comments', name='rss_comments')
855 + def rss_comments ():
856 + """
857 + Output an RSS feed of the latest comments.
858 + """
859 +
860 + # Retrieve the hostname from the HTTP request.
861 + # This is used to build absolute URLs in the RSS feed.
862 + base_url = request.urlparts.scheme + '://' + request.urlparts.netloc
863 +
864 + comments = database.get_latest_comments ()
865 +
866 + # Set correct Content-Type header for this RSS feed
867 + response.content_type = 'application/rss+xml; charset=UTF-8'
868 +
869 + return template ('rss_comments.xml', base_url=base_url, comments=comments)
870 +
854 871 @get ('/<filename:path>', name='static')
855 872 def static (filename):
856 873 """

+23/-0 M   freepost/database.py
index 74b5759..426fa11
old size: 18K - new size: 19K
@@ -508,6 +508,29 @@ def get_comment (hash_id, session_user_id = None):
508 508
509 509 return cursor.fetchone ()
510 510
511 + # Retrieve last N newest comments
512 + def get_latest_comments ():
513 + cursor = db.cursor (MySQLdb.cursors.DictCursor)
514 +
515 + cursor.execute (
516 + """
517 + SELECT
518 + C.*,
519 + P.hashId AS postHashId,
520 + P.title AS postTitle,
521 + U.username
522 + FROM comment AS C
523 + JOIN user AS U ON C.userId = U.id
524 + JOIN post AS P ON P.id = C.postId
525 + ORDER BY C.id DESC
526 + LIMIT 50
527 + """,
528 + {
529 + }
530 + )
531 +
532 + return cursor.fetchall ()
533 +
511 534 # Update a comment
512 535 def update_comment (text, comment_hash_id, user_id):
513 536 cursor = db.cursor (MySQLdb.cursors.DictCursor)

+16/-0 M   freepost/templates/banner.html
index 1008ce4..b18df14
old size: 878B - new size: 1K
@@ -30,3 +30,19 @@
30 30 |_____|\___/|_| /_/
31 31 </pre>
32 32 #}
33 +
34 + {# Peers Jam #}
35 + {% set datetime = now() %}
36 + {% if datetime.isoweekday() == 5 and datetime['hour'] >= 19 and datetime['hour'] <= 21 %}
37 + <div class="bg-green" style="margin: 0 0 2em 0; padding: .5em;">
38 + <img alt="" title="" src="images/pulse.gif" style="height: 1em;" />
39 + <a href="https://peers.community/#jam">Peers Jam</a>
40 + </div>
41 + {% endif %}
42 +
43 +
44 +
45 +
46 +
47 +
48 +

+2/-1 M   freepost/templates/layout.html
index ee15dee..163382b
old size: 6K - new size: 6K
@@ -113,7 +113,8 @@
113 113 <li>
114 114 <img alt="RSS" title="" src="/images/rss.png" />
115 115 <a href="/rss/hot">Hot</a> •
116 - <a href="/rss/new">New</a>
116 + <a href="/rss/new">New</a> •
117 + <a href="/rss_comments">Comments</a>
117 118 </li>
118 119 <li>
119 120 <img alt="Source" title="" src="/images/source.png" />

+1/-1 M   freepost/templates/login.html
index 905f0a2..0823f82
old size: 1K - new size: 1K
@@ -16,7 +16,7 @@
16 16
17 17 <form action="" method="post">
18 18 <div>
19 - <input type="text" name="username" placeholder="Username" class="form-control" required />
19 + <input type="text" name="username" placeholder="Username" class="form-control" required autofocus />
20 20 </div>
21 21
22 22 <div>

+15/-0 M   freepost/templates/posts.html
index ae714d7..5871745
old size: 4K - new size: 5K
@@ -87,6 +87,15 @@
87 87 class="button button_default1">
88 88 Previous
89 89 </button>
90 +
91 + {% if page_number > 4 %}
92 + <button type="submit"
93 + name="page"
94 + value="{{ page_number - 5 }}"
95 + class="button button_default1">
96 + -5
97 + </button>
98 + {% endif %}
90 99 </form>
91 100 {% endif %}
92 101
@@ -106,6 +115,12 @@
106 115
107 116 <button type="submit"
108 117 name="page"
118 + value="{{ page_number + 5 }}"
119 + class="button button_default1">
120 + +5
121 + </button>
122 + <button type="submit"
123 + name="page"
109 124 value="{{ page_number + 1 }}"
110 125 class="button button_default1">
111 126 Next

+29/-0 A   freepost/templates/rss_comments.xml
index 0000000..5537f82
old size: 0B - new size: 1K
new file mode: -rw-r--r--
@@ -0,0 +1,29 @@
1 + <?xml version="1.0" encoding="UTF-8" ?>
2 + <rss version="2.0">
3 + <channel>
4 + <title>freepost - Latest comments</title>
5 + <description></description>
6 + <link>{{ base_url }}</link>
7 + <lastBuildDate>{{ now () }}</lastBuildDate>
8 +
9 + {% for comment in comments %}
10 + {# freepost URL of this comment #}
11 + {% set freepost_url = base_url ~ url ('post', hash_id=comment.postHashId) %}
12 +
13 + <item>
14 + <guid isPermaLink="false">{{ comment.hashId }}</guid>
15 + <title>TITLE</title>
16 + <description>
17 + <![CDATA[
18 + <p>{{ comment.text }}</p>
19 + <p>{{ comment.vote }} votes</p>
20 + ]]>
21 + </description>
22 + <link>{{ freepost_url }}</link>
23 + <freepostLink>{{ freepost_url }}</freepostLink>
24 + <pubDate>{{ comment.created }}</pubDate>
25 + <author>{{ comment.username }}</author>
26 + </item>
27 + {% endfor %}
28 + </channel>
29 + </rss>