Show More
@@ -1,11 +1,19 b'' | |||||
1 | from django.shortcuts import redirect |
|
1 | from django.shortcuts import redirect | |
2 | from boards import views, utils |
|
2 | from boards import views, utils | |
3 | from boards.models import Ban |
|
3 | from boards.models import Ban | |
|
4 | from django.utils.html import strip_spaces_between_tags | |||
|
5 | from django.conf import settings | |||
|
6 | ||||
|
7 | RESPONSE_CONTENT_TYPE = 'Content-Type' | |||
|
8 | ||||
|
9 | TYPE_HTML = 'text/html' | |||
4 |
|
10 | |||
5 |
|
11 | |||
6 | class BanMiddleware: |
|
12 | class BanMiddleware: | |
7 | """This is run before showing the thread. Banned users don't need to see |
|
13 | """ | |
8 | anything""" |
|
14 | This is run before showing the thread. Banned users don't need to see | |
|
15 | anything | |||
|
16 | """ | |||
9 |
|
17 | |||
10 | def process_view(self, request, view_func, view_args, view_kwargs): |
|
18 | def process_view(self, request, view_func, view_args, view_kwargs): | |
11 |
|
19 | |||
@@ -16,4 +24,17 b' class BanMiddleware:' | |||||
16 | if bans.exists(): |
|
24 | if bans.exists(): | |
17 | ban = bans[0] |
|
25 | ban = bans[0] | |
18 | if not ban.can_read: |
|
26 | if not ban.can_read: | |
19 | return redirect(views.you_are_banned) No newline at end of file |
|
27 | return redirect(views.you_are_banned) | |
|
28 | ||||
|
29 | ||||
|
30 | class MinifyHTMLMiddleware(object): | |||
|
31 | def process_response(self, request, response): | |||
|
32 | try: | |||
|
33 | compress_html = settings.COMPRESS_HTML | |||
|
34 | except AttributeError: | |||
|
35 | compress_html = False | |||
|
36 | ||||
|
37 | if TYPE_HTML in response[RESPONSE_CONTENT_TYPE] and compress_html: | |||
|
38 | response.content = strip_spaces_between_tags( | |||
|
39 | response.content.strip()) | |||
|
40 | return response No newline at end of file |
@@ -114,6 +114,7 b' MIDDLEWARE_CLASSES = (' | |||||
114 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
114 | 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
115 | 'django.contrib.messages.middleware.MessageMiddleware', |
|
115 | 'django.contrib.messages.middleware.MessageMiddleware', | |
116 | 'boards.middlewares.BanMiddleware', |
|
116 | 'boards.middlewares.BanMiddleware', | |
|
117 | 'boards.middlewares.MinifyHTMLMiddleware', | |||
117 | ) |
|
118 | ) | |
118 |
|
119 | |||
119 | ROOT_URLCONF = 'neboard.urls' |
|
120 | ROOT_URLCONF = 'neboard.urls' | |
@@ -220,6 +221,7 b' ENABLE_CAPTCHA = False' | |||||
220 | CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds |
|
221 | CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds | |
221 | POSTING_DELAY = 20 # seconds |
|
222 | POSTING_DELAY = 20 # seconds | |
222 |
|
223 | |||
|
224 | COMPRESS_HTML = True | |||
223 |
|
225 | |||
224 | def custom_show_toolbar(request): |
|
226 | def custom_show_toolbar(request): | |
225 | return DEBUG |
|
227 | return DEBUG |
General Comments 0
You need to be logged in to leave comments.
Login now