Show More
@@ -13,6 +13,8 b' from boards.views.base import BaseBoardV' | |||||
13 | from boards.views.posting_mixin import PostMixin |
|
13 | from boards.views.posting_mixin import PostMixin | |
14 | import neboard |
|
14 | import neboard | |
15 |
|
15 | |||
|
16 | TAG_DELIMITER = ' ' | |||
|
17 | ||||
16 | PARAMETER_CURRENT_PAGE = 'current_page' |
|
18 | PARAMETER_CURRENT_PAGE = 'current_page' | |
17 | PARAMETER_PAGINATOR = 'paginator' |
|
19 | PARAMETER_PAGINATOR = 'paginator' | |
18 | PARAMETER_THREADS = 'threads' |
|
20 | PARAMETER_THREADS = 'threads' | |
@@ -48,7 +50,7 b' class AllThreadsView(PostMixin, BaseBoar' | |||||
48 | form.session = request.session |
|
50 | form.session = request.session | |
49 |
|
51 | |||
50 | if form.is_valid(): |
|
52 | if form.is_valid(): | |
51 |
return self. |
|
53 | return self.create_thread(request, form) | |
52 | if form.need_to_ban: |
|
54 | if form.need_to_ban: | |
53 | # Ban user because he is suspected to be a bot |
|
55 | # Ban user because he is suspected to be a bot | |
54 | self._ban_current_user(request) |
|
56 | self._ban_current_user(request) | |
@@ -64,11 +66,27 b' class AllThreadsView(PostMixin, BaseBoar' | |||||
64 | context[PARAMETER_PAGINATOR] = paginator |
|
66 | context[PARAMETER_PAGINATOR] = paginator | |
65 | context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page)) |
|
67 | context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page)) | |
66 |
|
68 | |||
67 | # TODO This method should be refactored |
|
69 | def parse_tags_string(self, tag_strings): | |
|
70 | """ | |||
|
71 | Parses tag list string and returns tag object list. | |||
|
72 | """ | |||
|
73 | ||||
|
74 | tags = [] | |||
|
75 | ||||
|
76 | if tag_strings: | |||
|
77 | tag_strings = tag_strings.split(TAG_DELIMITER) | |||
|
78 | for tag_name in tag_strings: | |||
|
79 | tag_name = string.lower(tag_name.strip()) | |||
|
80 | if len(tag_name) > 0: | |||
|
81 | tag, created = Tag.objects.get_or_create(name=tag_name) | |||
|
82 | tags.append(tag) | |||
|
83 | ||||
|
84 | return tags | |||
|
85 | ||||
68 | @transaction.atomic |
|
86 | @transaction.atomic | |
69 |
def |
|
87 | def create_thread(self, request, form, html_response=True): | |
70 | """ |
|
88 | """ | |
71 |
|
|
89 | Creates a new thread with an opening post. | |
72 | """ |
|
90 | """ | |
73 |
|
91 | |||
74 | ip = utils.get_client_ip(request) |
|
92 | ip = utils.get_client_ip(request) | |
@@ -92,31 +110,20 b' class AllThreadsView(PostMixin, BaseBoar' | |||||
92 | else: |
|
110 | else: | |
93 | image = None |
|
111 | image = None | |
94 |
|
112 | |||
95 | tags = [] |
|
|||
96 |
|
||||
97 | tag_strings = data['tags'] |
|
113 | tag_strings = data['tags'] | |
98 |
|
114 | |||
99 | if tag_strings: |
|
115 | tags = self.parse_tags_string(tag_strings) | |
100 | tag_strings = tag_strings.split(' ') |
|
|||
101 | for tag_name in tag_strings: |
|
|||
102 | tag_name = string.lower(tag_name.strip()) |
|
|||
103 | if len(tag_name) > 0: |
|
|||
104 | tag, created = Tag.objects.get_or_create(name=tag_name) |
|
|||
105 | tags.append(tag) |
|
|||
106 |
|
116 | |||
107 | post = Post.objects.create_post(title=title, text=text, ip=ip, |
|
117 | post = Post.objects.create_post(title=title, text=text, ip=ip, | |
108 | image=image, tags=tags, |
|
118 | image=image, tags=tags, | |
109 | user=self._get_user(request)) |
|
119 | user=self._get_user(request)) | |
110 |
|
120 | |||
111 | thread_to_show = (opening_post.id if opening_post else post.id) |
|
|||
112 |
|
||||
113 | if html_response: |
|
121 | if html_response: | |
114 | if opening_post: |
|
122 | return redirect(post.get_url()) | |
115 | return redirect( |
|
|||
116 | reverse('thread', kwargs={'post_id': thread_to_show}) + |
|
|||
117 | '#' + str(post.id)) |
|
|||
118 | else: |
|
|||
119 | return redirect('thread', post_id=thread_to_show) |
|
|||
120 |
|
123 | |||
121 | def get_threads(self): |
|
124 | def get_threads(self): | |
|
125 | """ | |||
|
126 | Gets list of threads that will be shown on a page. | |||
|
127 | """ | |||
|
128 | ||||
122 | return Thread.objects.filter(archived=False).order_by('-bump_time') |
|
129 | return Thread.objects.filter(archived=False).order_by('-bump_time') |
@@ -39,7 +39,7 b' class TagView(AllThreadsView, Dispatcher' | |||||
39 | form.session = request.session |
|
39 | form.session = request.session | |
40 |
|
40 | |||
41 | if form.is_valid(): |
|
41 | if form.is_valid(): | |
42 |
return self. |
|
42 | return self.create_thread(request, form) | |
43 | if form.need_to_ban: |
|
43 | if form.need_to_ban: | |
44 | # Ban user because he is suspected to be a bot |
|
44 | # Ban user because he is suspected to be a bot | |
45 | self._ban_current_user(request) |
|
45 | self._ban_current_user(request) |
General Comments 0
You need to be logged in to leave comments.
Login now