1111 - /toggle_tag_subscription
1212 - /tag_list
1313"""
14- from flask import request , render_template , Blueprint , g
14+ from flask import current_app , request , render_template , Blueprint , g
1515from sqlalchemy import and_
1616import logging
1717
@@ -42,7 +42,7 @@ def render_batch_tags():
4242 sort_desc = not sort_asc
4343 feed_params = from_request_get_feed_params (request )
4444
45- # get all tags
45+ excluded_tags = current_app . config . get ( 'EXCLUDED_TAGS' )
4646 all_tags = db_session .query (Tag ).all ()
4747 tags_to_posts = {}
4848 nonzero_tags = []
@@ -54,7 +54,8 @@ def render_batch_tags():
5454 db_session .delete (tag )
5555 db_session .commit ()
5656
57- tags_to_posts [tag .id ] = [(post .path , post .title ) for post in posts ]
57+ tags_to_posts [tag .id ] = [(post .path , post .title ) for post in posts if
58+ post .is_published and not post .contains_excluded_tags ]
5859 nonzero_tags .append (tag )
5960 # so that we can use the tag in the jinja template
6061 db_session .expunge (tag )
@@ -119,6 +120,9 @@ def render_tag_pages():
119120 if tag [0 ] == '#' :
120121 tag = tag [1 :]
121122
123+ if tag in current_app .config .get ('EXCLUDED_TAGS' ):
124+ return render_template ('error.html' )
125+
122126 tag_obj = (db_session .query (Tag )
123127 .filter (Tag .name == tag )
124128 .first ())
@@ -211,6 +215,11 @@ def toggle_tag_subscription():
211215 try :
212216 # retrieve relevant tag and user args from request
213217 tag_name = request .args .get ('tag_name' , '' )
218+
219+ if tag_name in current_app .config .get ('EXCLUDED_TAGS' ):
220+ logging .warning ("Trying to subscribe to an excluded tag" )
221+ return ""
222+
214223 subscribe_action = request .args .get ('subscribe_action' , '' )
215224 if subscribe_action not in ['unsubscribe' , 'subscribe' ]:
216225 logging .warning ("ERROR processing request" )
0 commit comments