home » zplus/freepost.git
Author zPlus <zplus@peers.community> 2020-06-05 07:05:35
Committer zPlus <zplus@peers.community> 2020-06-05 07:05:35
Commit c253864 (patch)
Tree 7b59742
Parent(s)

Show list of duplicate posts when submitting.


commits diff: 9d3c76a..c253864
3 files changed, 27 insertions, 15 deletionsdownload


Diffstat
-rwxr-xr-x freepost/__init__.py 22
-rw-r--r-- freepost/database.py 18
-rwxr-xr-x freepost/templates/submit.html 2

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+16/-6 M   freepost/__init__.py
index 76da281..df1beec
old size: 27K - new size: 28K
@@ -658,12 +658,22 @@ def submit_check ():
658 658 # Retrieve link
659 659 link = request.forms.getunicode ('link').strip ()
660 660
661 - # If there is a URL, make sure it has a "scheme"
662 - if len (link) > 0 and urlparse (link).scheme == '':
663 - link = 'http://' + link
664 -
665 - if database.post_exists(link):
666 - return template ('submit.html', flash='Link has already been submitted.')
661 + if len (link) > 0:
662 + # If there is a URL, make sure it has a "scheme"
663 + if urlparse (link).scheme == '':
664 + link = 'http://' + link
665 +
666 + # Check if this link was already posted in order to avoid duplicate posting.
667 + previous_posts = database.link_exists(link)
668 + if previous_posts:
669 + posts_list = ''.join([
670 + '<li><a href="{link}">{title}</a></li>'.format(
671 + link = application.get_url ('post', hash_id=post['hashId']),
672 + title = post['title'])
673 + for post in previous_posts ])
674 +
675 + return template ('submit.html',
676 + flash='This link was already submitted:<ul>{posts}</ul>'.format(posts=posts_list))
667 677
668 678 # Retrieve topics
669 679 topics = request.forms.getunicode ('topics')

+10/-8 M   freepost/database.py
index be03477..83110a7
old size: 21K - new size: 22K
@@ -97,24 +97,26 @@ def username_exists (username, case_sensitive = True):
97 97
98 98 return cursor.fetchone() is not None
99 99
100 - # Check if post with same link exists
101 - def post_exists (link):
100 + # Check if post with same link exists. This is used to check for duplicates.
101 + # Returns an empty list if the link wasn't posted before, otherwise returns the posts.
102 + def link_exists (link):
102 103 if not link:
103 - return None
104 + return []
104 105
105 106 with db:
106 107 cursor = db.execute(
107 108 """
108 - SELECT *
109 - FROM post
110 - WHERE LOWER(link) = LOWER(:link)
109 + SELECT *
110 + FROM post
111 + WHERE LOWER(link) = LOWER(:link)
112 + ORDER BY created DESC
111 113 """,
112 114 {
113 115 'link': link
114 116 }
115 117 )
116 -
117 - return cursor.fetchone() is not None
118 +
119 + return cursor.fetchall()
118 120
119 121 # Create new user account
120 122 def new_user (username, password):

+1/-1 M   freepost/templates/submit.html
index 6b81327..0a3f365
old size: 1K - new size: 1K
@@ -8,7 +8,7 @@
8 8
9 9 {% if flash %}
10 10 <div class="alert bg-red">
11 - {{ flash }}
11 + {{ flash|safe }}
12 12 </div>
13 13 {% endif %}
14 14