##// END OF EJS Templates
Added test for all views get requests. Fixed banned view failing this test
neko259 -
r545:9c27ae2e 1.7-dev
parent child Browse files
Show More
@@ -1,233 +1,257 b''
1 # coding=utf-8
1 # coding=utf-8
2 import time
3 import logging
4
2 from django.test import TestCase
5 from django.test import TestCase
3 from django.test.client import Client
6 from django.test.client import Client
4 import time
7 from django.core.urlresolvers import reverse, NoReverseMatch
5
8
6 from boards.models import Post, Tag
9 from boards.models import Post, Tag
10 from boards import urls
7 from neboard import settings
11 from neboard import settings
8
12
9 PAGE_404 = 'boards/404.html'
13 PAGE_404 = 'boards/404.html'
10
14
11 TEST_TEXT = 'test text'
15 TEST_TEXT = 'test text'
12
16
13 NEW_THREAD_PAGE = '/'
17 NEW_THREAD_PAGE = '/'
14 THREAD_PAGE_ONE = '/thread/1/'
18 THREAD_PAGE_ONE = '/thread/1/'
15 THREAD_PAGE = '/thread/'
19 THREAD_PAGE = '/thread/'
16 TAG_PAGE = '/tag/'
20 TAG_PAGE = '/tag/'
17 HTTP_CODE_REDIRECT = 302
21 HTTP_CODE_REDIRECT = 302
18 HTTP_CODE_OK = 200
22 HTTP_CODE_OK = 200
19 HTTP_CODE_NOT_FOUND = 404
23 HTTP_CODE_NOT_FOUND = 404
20
24
25 logger = logging.getLogger(__name__)
26
21
27
22 class PostTests(TestCase):
28 class PostTests(TestCase):
23
29
24 def _create_post(self):
30 def _create_post(self):
25 return Post.objects.create_post(title='title',
31 return Post.objects.create_post(title='title',
26 text='text')
32 text='text')
27
33
28 def test_post_add(self):
34 def test_post_add(self):
29 """Test adding post"""
35 """Test adding post"""
30
36
31 post = self._create_post()
37 post = self._create_post()
32
38
33 self.assertIsNotNone(post, 'No post was created')
39 self.assertIsNotNone(post, 'No post was created')
34
40
35 def test_delete_post(self):
41 def test_delete_post(self):
36 """Test post deletion"""
42 """Test post deletion"""
37
43
38 post = self._create_post()
44 post = self._create_post()
39 post_id = post.id
45 post_id = post.id
40
46
41 Post.objects.delete_post(post)
47 Post.objects.delete_post(post)
42
48
43 self.assertFalse(Post.objects.filter(id=post_id).exists())
49 self.assertFalse(Post.objects.filter(id=post_id).exists())
44
50
45 def test_delete_thread(self):
51 def test_delete_thread(self):
46 """Test thread deletion"""
52 """Test thread deletion"""
47
53
48 opening_post = self._create_post()
54 opening_post = self._create_post()
49 thread = opening_post.thread_new
55 thread = opening_post.thread_new
50 reply = Post.objects.create_post("", "", thread=thread)
56 reply = Post.objects.create_post("", "", thread=thread)
51
57
52 thread.delete_with_posts()
58 thread.delete_with_posts()
53
59
54 self.assertFalse(Post.objects.filter(id=reply.id).exists())
60 self.assertFalse(Post.objects.filter(id=reply.id).exists())
55
61
56 def test_post_to_thread(self):
62 def test_post_to_thread(self):
57 """Test adding post to a thread"""
63 """Test adding post to a thread"""
58
64
59 op = self._create_post()
65 op = self._create_post()
60 post = Post.objects.create_post("", "", thread=op.thread_new)
66 post = Post.objects.create_post("", "", thread=op.thread_new)
61
67
62 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
68 self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
63 self.assertEqual(op.thread_new.last_edit_time, post.pub_time,
69 self.assertEqual(op.thread_new.last_edit_time, post.pub_time,
64 'Post\'s create time doesn\'t match thread last edit'
70 'Post\'s create time doesn\'t match thread last edit'
65 ' time')
71 ' time')
66
72
67 def test_delete_posts_by_ip(self):
73 def test_delete_posts_by_ip(self):
68 """Test deleting posts with the given ip"""
74 """Test deleting posts with the given ip"""
69
75
70 post = self._create_post()
76 post = self._create_post()
71 post_id = post.id
77 post_id = post.id
72
78
73 Post.objects.delete_posts_by_ip('0.0.0.0')
79 Post.objects.delete_posts_by_ip('0.0.0.0')
74
80
75 self.assertFalse(Post.objects.filter(id=post_id).exists())
81 self.assertFalse(Post.objects.filter(id=post_id).exists())
76
82
77 def test_get_thread(self):
83 def test_get_thread(self):
78 """Test getting all posts of a thread"""
84 """Test getting all posts of a thread"""
79
85
80 opening_post = self._create_post()
86 opening_post = self._create_post()
81
87
82 for i in range(0, 2):
88 for i in range(0, 2):
83 Post.objects.create_post('title', 'text',
89 Post.objects.create_post('title', 'text',
84 thread=opening_post.thread_new)
90 thread=opening_post.thread_new)
85
91
86 thread = opening_post.thread_new
92 thread = opening_post.thread_new
87
93
88 self.assertEqual(3, thread.replies.count())
94 self.assertEqual(3, thread.replies.count())
89
95
90 def test_create_post_with_tag(self):
96 def test_create_post_with_tag(self):
91 """Test adding tag to post"""
97 """Test adding tag to post"""
92
98
93 tag = Tag.objects.create(name='test_tag')
99 tag = Tag.objects.create(name='test_tag')
94 post = Post.objects.create_post(title='title', text='text', tags=[tag])
100 post = Post.objects.create_post(title='title', text='text', tags=[tag])
95
101
96 thread = post.thread_new
102 thread = post.thread_new
97 self.assertIsNotNone(post, 'Post not created')
103 self.assertIsNotNone(post, 'Post not created')
98 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
104 self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
99 self.assertTrue(thread in tag.threads.all(), 'Thread not added to tag')
105 self.assertTrue(thread in tag.threads.all(), 'Thread not added to tag')
100
106
101 def test_thread_max_count(self):
107 def test_thread_max_count(self):
102 """Test deletion of old posts when the max thread count is reached"""
108 """Test deletion of old posts when the max thread count is reached"""
103
109
104 for i in range(settings.MAX_THREAD_COUNT + 1):
110 for i in range(settings.MAX_THREAD_COUNT + 1):
105 self._create_post()
111 self._create_post()
106
112
107 self.assertEqual(settings.MAX_THREAD_COUNT,
113 self.assertEqual(settings.MAX_THREAD_COUNT,
108 len(Post.objects.get_threads()))
114 len(Post.objects.get_threads()))
109
115
110 def test_pages(self):
116 def test_pages(self):
111 """Test that the thread list is properly split into pages"""
117 """Test that the thread list is properly split into pages"""
112
118
113 for i in range(settings.MAX_THREAD_COUNT):
119 for i in range(settings.MAX_THREAD_COUNT):
114 self._create_post()
120 self._create_post()
115
121
116 all_threads = Post.objects.get_threads()
122 all_threads = Post.objects.get_threads()
117
123
118 posts_in_second_page = Post.objects.get_threads(page=2)
124 posts_in_second_page = Post.objects.get_threads(page=2)
119 first_post = posts_in_second_page[0]
125 first_post = posts_in_second_page[0]
120
126
121 self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id,
127 self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id,
122 first_post.id)
128 first_post.id)
123
129
124 def test_linked_tag(self):
130 def test_linked_tag(self):
125 """Test adding a linked tag"""
131 """Test adding a linked tag"""
126
132
127 linked_tag = Tag.objects.create(name=u'tag1')
133 linked_tag = Tag.objects.create(name=u'tag1')
128 tag = Tag.objects.create(name=u'tag2', linked=linked_tag)
134 tag = Tag.objects.create(name=u'tag2', linked=linked_tag)
129
135
130 post = Post.objects.create_post("", "", tags=[tag])
136 post = Post.objects.create_post("", "", tags=[tag])
131
137
132 self.assertTrue(linked_tag in post.thread_new.tags.all(),
138 self.assertTrue(linked_tag in post.thread_new.tags.all(),
133 'Linked tag was not added')
139 'Linked tag was not added')
134
140
135
141
136 class PagesTest(TestCase):
142 class PagesTest(TestCase):
137
143
138 def test_404(self):
144 def test_404(self):
139 """Test receiving error 404 when opening a non-existent page"""
145 """Test receiving error 404 when opening a non-existent page"""
140
146
141 tag_name = u'test_tag'
147 tag_name = u'test_tag'
142 tag = Tag.objects.create(name=tag_name)
148 tag = Tag.objects.create(name=tag_name)
143 client = Client()
149 client = Client()
144
150
145 Post.objects.create_post('title', TEST_TEXT, tags=[tag])
151 Post.objects.create_post('title', TEST_TEXT, tags=[tag])
146
152
147 existing_post_id = Post.objects.all()[0].id
153 existing_post_id = Post.objects.all()[0].id
148 response_existing = client.get(THREAD_PAGE + str(existing_post_id) +
154 response_existing = client.get(THREAD_PAGE + str(existing_post_id) +
149 '/')
155 '/')
150 self.assertEqual(HTTP_CODE_OK, response_existing.status_code,
156 self.assertEqual(HTTP_CODE_OK, response_existing.status_code,
151 u'Cannot open existing thread')
157 u'Cannot open existing thread')
152
158
153 response_not_existing = client.get(THREAD_PAGE + str(
159 response_not_existing = client.get(THREAD_PAGE + str(
154 existing_post_id + 1) + '/')
160 existing_post_id + 1) + '/')
155 self.assertEqual(PAGE_404,
161 self.assertEqual(PAGE_404,
156 response_not_existing.templates[0].name,
162 response_not_existing.templates[0].name,
157 u'Not existing thread is opened')
163 u'Not existing thread is opened')
158
164
159 response_existing = client.get(TAG_PAGE + tag_name + '/')
165 response_existing = client.get(TAG_PAGE + tag_name + '/')
160 self.assertEqual(HTTP_CODE_OK,
166 self.assertEqual(HTTP_CODE_OK,
161 response_existing.status_code,
167 response_existing.status_code,
162 u'Cannot open existing tag')
168 u'Cannot open existing tag')
163
169
164 response_not_existing = client.get(TAG_PAGE + u'not_tag' + '/')
170 response_not_existing = client.get(TAG_PAGE + u'not_tag' + '/')
165 self.assertEqual(PAGE_404,
171 self.assertEqual(PAGE_404,
166 response_not_existing.templates[0].name,
172 response_not_existing.templates[0].name,
167 u'Not existing tag is opened')
173 u'Not existing tag is opened')
168
174
169 reply_id = Post.objects.create_post('', TEST_TEXT,
175 reply_id = Post.objects.create_post('', TEST_TEXT,
170 thread=Post.objects.all()[0]
176 thread=Post.objects.all()[0]
171 .thread)
177 .thread)
172 response_not_existing = client.get(THREAD_PAGE + str(
178 response_not_existing = client.get(THREAD_PAGE + str(
173 reply_id) + '/')
179 reply_id) + '/')
174 self.assertEqual(PAGE_404,
180 self.assertEqual(PAGE_404,
175 response_not_existing.templates[0].name,
181 response_not_existing.templates[0].name,
176 u'Reply is opened as a thread')
182 u'Reply is opened as a thread')
177
183
178
184
179 class FormTest(TestCase):
185 class FormTest(TestCase):
180 def test_post_validation(self):
186 def test_post_validation(self):
181 # Disable captcha for the test
187 # Disable captcha for the test
182 captcha_enabled = settings.ENABLE_CAPTCHA
188 captcha_enabled = settings.ENABLE_CAPTCHA
183 settings.ENABLE_CAPTCHA = False
189 settings.ENABLE_CAPTCHA = False
184
190
185 client = Client()
191 client = Client()
186
192
187 valid_tags = u'tag1 tag_2 тег_3'
193 valid_tags = u'tag1 tag_2 тег_3'
188 invalid_tags = u'$%_356 ---'
194 invalid_tags = u'$%_356 ---'
189
195
190 response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
196 response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
191 'text': TEST_TEXT,
197 'text': TEST_TEXT,
192 'tags': valid_tags})
198 'tags': valid_tags})
193 self.assertEqual(response.status_code, HTTP_CODE_REDIRECT,
199 self.assertEqual(response.status_code, HTTP_CODE_REDIRECT,
194 msg='Posting new message failed: got code ' +
200 msg='Posting new message failed: got code ' +
195 str(response.status_code))
201 str(response.status_code))
196
202
197 self.assertEqual(1, Post.objects.count(),
203 self.assertEqual(1, Post.objects.count(),
198 msg='No posts were created')
204 msg='No posts were created')
199
205
200 client.post(NEW_THREAD_PAGE, {'text': TEST_TEXT,
206 client.post(NEW_THREAD_PAGE, {'text': TEST_TEXT,
201 'tags': invalid_tags})
207 'tags': invalid_tags})
202 self.assertEqual(1, Post.objects.count(), msg='The validation passed '
208 self.assertEqual(1, Post.objects.count(), msg='The validation passed '
203 'where it should fail')
209 'where it should fail')
204
210
205 # Change posting delay so we don't have to wait for 30 seconds or more
211 # Change posting delay so we don't have to wait for 30 seconds or more
206 old_posting_delay = settings.POSTING_DELAY
212 old_posting_delay = settings.POSTING_DELAY
207 # Wait fot the posting delay or we won't be able to post
213 # Wait fot the posting delay or we won't be able to post
208 settings.POSTING_DELAY = 1
214 settings.POSTING_DELAY = 1
209 time.sleep(settings.POSTING_DELAY + 1)
215 time.sleep(settings.POSTING_DELAY + 1)
210 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
216 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
211 'tags': valid_tags})
217 'tags': valid_tags})
212 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
218 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
213 msg=u'Posting new message failed: got code ' +
219 msg=u'Posting new message failed: got code ' +
214 str(response.status_code))
220 str(response.status_code))
215 # Restore posting delay
221 # Restore posting delay
216 settings.POSTING_DELAY = old_posting_delay
222 settings.POSTING_DELAY = old_posting_delay
217
223
218 self.assertEqual(2, Post.objects.count(),
224 self.assertEqual(2, Post.objects.count(),
219 msg=u'No posts were created')
225 msg=u'No posts were created')
220
226
221 # Restore captcha setting
227 # Restore captcha setting
222 settings.ENABLE_CAPTCHA = captcha_enabled
228 settings.ENABLE_CAPTCHA = captcha_enabled
223
229
224
230
225 class ViewTest(TestCase):
231 class ViewTest(TestCase):
226 def test_index(self):
232
233 def test_all_views(self):
234 '''
235 Try opening all views defined in ulrs.py that don't need additional
236 parameters
237 '''
238
227 client = Client()
239 client = Client()
240 for url in urls.urlpatterns:
241 try:
242 view_name = url.name
243 logger.debug('Testing view %s' % view_name)
228
244
229 response = client.get('/')
245 try:
230 self.assertEqual(HTTP_CODE_OK, response.status_code, 'Index page not '
246 response = client.get(reverse(view_name))
231 'opened')
247
232 self.assertEqual('boards/posting_general.html', response.templates[0]
248 self.assertEqual(HTTP_CODE_OK, response.status_code,
233 .name, 'Index page should open posting_general template')
249 '%s view not opened' % view_name)
250 except NoReverseMatch:
251 # This view just needs additional arguments
252 pass
253 except Exception, e:
254 self.fail('Got exception %s at %s view' % (e, view_name))
255 except AttributeError:
256 # This is normal, some views do not have names
257 pass
@@ -1,76 +1,76 b''
1 from django.conf.urls import patterns, url, include
1 from django.conf.urls import patterns, url, include
2 from boards import views
2 from boards import views
3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
4 from boards.views import api, tag_threads, all_threads, archived_threads, login
4 from boards.views import api, tag_threads, all_threads, archived_threads, login
5
5
6 js_info_dict = {
6 js_info_dict = {
7 'packages': ('boards',),
7 'packages': ('boards',),
8 }
8 }
9
9
10 urlpatterns = patterns('',
10 urlpatterns = patterns('',
11
11
12 # /boards/
12 # /boards/
13 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
13 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
14 # /boards/page/
14 # /boards/page/
15 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
15 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
16 name='index'),
16 name='index'),
17
17
18 url(r'^archive/$', archived_threads.ArchiveView.as_view(), name='archive'),
18 url(r'^archive/$', archived_threads.ArchiveView.as_view(), name='archive'),
19 url(r'^archive/page/(?P<page>\w+)/$',
19 url(r'^archive/page/(?P<page>\w+)/$',
20 archived_threads.ArchiveView.as_view(), name='archive'),
20 archived_threads.ArchiveView.as_view(), name='archive'),
21
21
22 # login page
22 # login page
23 url(r'^login/$', login.LoginView.as_view(), name='login'),
23 url(r'^login/$', login.LoginView.as_view(), name='login'),
24
24
25 # /boards/tag/tag_name/
25 # /boards/tag/tag_name/
26 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
26 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
27 name='tag'),
27 name='tag'),
28 # /boards/tag/tag_id/page/
28 # /boards/tag/tag_id/page/
29 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
29 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
30 tag_threads.TagView.as_view(), name='tag'),
30 tag_threads.TagView.as_view(), name='tag'),
31
31
32 # /boards/tag/tag_name/unsubscribe/
32 # /boards/tag/tag_name/unsubscribe/
33 url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe,
33 url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe,
34 name='tag_subscribe'),
34 name='tag_subscribe'),
35 # /boards/tag/tag_name/unsubscribe/
35 # /boards/tag/tag_name/unsubscribe/
36 url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe,
36 url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe,
37 name='tag_unsubscribe'),
37 name='tag_unsubscribe'),
38
38
39 # /boards/thread/
39 # /boards/thread/
40 url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(),
40 url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(),
41 name='thread'),
41 name='thread'),
42 url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView
42 url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView
43 .as_view(), name='thread_mode'),
43 .as_view(), name='thread_mode'),
44 url(r'^settings/$', views.settings, name='settings'),
44 url(r'^settings/$', views.settings, name='settings'),
45 url(r'^tags/$', views.all_tags, name='tags'),
45 url(r'^tags/$', views.all_tags, name='tags'),
46 url(r'^captcha/', include('captcha.urls')),
46 url(r'^captcha/', include('captcha.urls')),
47 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
47 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
48 url(r'^authors/$', views.authors, name='authors'),
48 url(r'^authors/$', views.authors, name='authors'),
49 url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'),
49 url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'),
50 url(r'^ban/(?P<post_id>\w+)/$', views.ban, name='ban'),
50 url(r'^ban/(?P<post_id>\w+)/$', views.ban, name='ban'),
51
51
52 url(r'^banned/$', views.banned.BannedView.as_view, name='banned'),
52 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
53 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
53 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
54
54
55 # RSS feeds
55 # RSS feeds
56 url(r'^rss/$', AllThreadsFeed()),
56 url(r'^rss/$', AllThreadsFeed()),
57 url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()),
57 url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()),
58 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
58 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
59 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
59 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
60 url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()),
60 url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()),
61
61
62 # i18n
62 # i18n
63 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict, name='js_info_dict'),
63 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict, name='js_info_dict'),
64
64
65 # API
65 # API
66 url(r'^api/post/(?P<post_id>\w+)/$', api.get_post, name="get_post"),
66 url(r'^api/post/(?P<post_id>\w+)/$', api.get_post, name="get_post"),
67 url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_update_time>\w+)/$',
67 url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_update_time>\w+)/$',
68 api.api_get_threaddiff, name="get_thread_diff"),
68 api.api_get_threaddiff, name="get_thread_diff"),
69 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
69 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
70 name='get_threads'),
70 name='get_threads'),
71 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
71 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
72 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
72 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
73 name='get_thread'),
73 name='get_thread'),
74 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post, name='add_post'),
74 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post, name='add_post'),
75
75
76 )
76 )
@@ -1,16 +1,16 b''
1 from django.shortcuts import get_object_or_404, render
1 from django.shortcuts import get_object_or_404, render
2 from boards import utils
2 from boards import utils
3 from boards.models import Ban
3 from boards.models import Ban
4 from boards.views.base import BaseBoardView
4 from boards.views.base import BaseBoardView
5
5
6
6
7 class BannedView(BaseBoardView):
7 class BannedView(BaseBoardView):
8
8
9 def get(self, request):
9 def get(self, request):
10 """Show the page that notifies that user is banned"""
10 """Show the page that notifies that user is banned"""
11
11
12 context = self.get_context_data(request)
12 context = self.get_context_data(request=request)
13
13
14 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
14 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
15 context['ban_reason'] = ban.reason
15 context['ban_reason'] = ban.reason
16 return render(request, 'boards/staticpages/banned.html', context)
16 return render(request, 'boards/staticpages/banned.html', context)
General Comments 0
You need to be logged in to leave comments. Login now