← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/anti_spam_2 into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/anti_spam_2 into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/anti_spam_2/+merge/308074

- Fix Latest Posts box
- No hidden posts in feeds
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/anti_spam_2 into lp:widelands-website.
=== modified file 'local_settings.py.sample'
--- local_settings.py.sample	2016-08-05 18:20:29 +0000
+++ local_settings.py.sample	2016-10-10 19:35:39 +0000
@@ -33,6 +33,11 @@
 # This Backend shows Emails in console
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
 
+# Anti spam keywords
+# If these are found, the posts/topics in forum get hidden
+ANTI_SPAM_BODY = ['']
+ANTI_SPAM_TOPIC = ['']
+
 # Uncomment 'LOGGING = {...}' for debugging purposes when you have set DEBUG=False.
 # Use then in the code:
 

=== modified file 'pybb/feeds.py'
--- pybb/feeds.py	2016-06-06 18:26:47 +0000
+++ pybb/feeds.py	2016-10-10 19:35:39 +0000
@@ -14,6 +14,7 @@
             return self.one_title % obj.name
         
     def items(self, obj):
+
         if obj == self.all_objects:
             return obj.order_by('-created')[:15]
         else:
@@ -54,10 +55,10 @@
     title_template = 'pybb/feeds/posts_title.html'
     description_template = 'pybb/feeds/posts_description.html'
 
-    all_objects = Post.objects
+    all_objects = Post.objects.filter(hidden=False)
 
     def items_for_object(self,obj):
-        return Post.objects.filter( topic__forum = obj ).order_by('-created')[:15]
+        return Post.objects.filter( hidden = False, topic__forum = obj ).order_by('-created')[:15]
 
     def item_author_name(self, item):
         """
@@ -73,10 +74,10 @@
     title_template = 'pybb/feeds/topics_title.html'
     description_template = 'pybb/feeds/topics_description.html'
     
-    all_objects = Topic.objects
+    all_objects = Topic.objects.exclude(posts__hidden = True)
 
     def items_for_object(self,item):
-        return Topic.objects.filter( forum = item ).order_by('-created')[:15]
+        return Topic.objects.exclude( posts__hidden = True ).filter( forum = item ).order_by('-created')[:15]
 
     def item_author_name(self, item):
         """

=== modified file 'pybb/templatetags/pybb_extras.py'
--- pybb/templatetags/pybb_extras.py	2016-03-02 21:02:38 +0000
+++ pybb/templatetags/pybb_extras.py	2016-10-10 19:35:39 +0000
@@ -79,13 +79,15 @@
 import time
 @register.inclusion_tag('pybb/last_posts.html', takes_context=True)
 def pybb_last_posts(context, number = 5):
-    last_posts = Post.objects.order_by('-created').select_related()[:25]
+    last_posts = Post.objects.order_by('-created').select_related()[:50]
     check = []
     answer = []
     for post in last_posts:
         if (post.topic_id not in check) and len(check) < 5:
-            check = check + [post.topic_id]
-            answer = answer + [post]
+            if not post.hidden:
+                # Gather only not hidden posts
+                check = check + [post.topic_id]
+                answer = answer + [post]
     return {
         'posts': answer,
         }

=== modified file 'templates/pybb/last_posts.html'
--- templates/pybb/last_posts.html	2016-10-08 09:30:34 +0000
+++ templates/pybb/last_posts.html	2016-10-10 19:35:39 +0000
@@ -9,13 +9,11 @@
 	<div class="columnModuleBox">
 		<ul>
 			{% for post in posts %}
-				{% if not post.hidden %}
 				<li>
 					{{ post.topic.forum.name }}<br />
 					<a href="{{ post.get_absolute_url }}" title="{{ post.topic.name }}">{{ post.topic.name|pybb_cut_string:30 }}</a><br />
 					by <a href="{% url 'profile_view' post.user %}">{{post.user.username}}</a> {{ post.created|minutes }} ago
 				</li>
-				{% endif %}
 			{% endfor %}
 		</ul>
 	</div>


Follow ups