Show More
@@ -1,3 +1,5 b'' | |||
|
1 | import re | |
|
2 | ||
|
1 | 3 | from django.core.paginator import EmptyPage |
|
2 | 4 | from django.http import Http404 |
|
3 | 5 | from django.shortcuts import render, redirect |
@@ -38,6 +40,7 b" PARAMETER_RSS_URL = 'rss_url'" | |||
|
38 | 40 | TEMPLATE = 'boards/all_threads.html' |
|
39 | 41 | DEFAULT_PAGE = 1 |
|
40 | 42 | |
|
43 | PATTERN_THREAD_NUMBER = re.compile(r'^(\D*)(\d+)(\D*)$') | |
|
41 | 44 | |
|
42 | 45 | class AllThreadsView(BaseBoardView, PaginatedMixin, DispatcherMixin): |
|
43 | 46 | |
@@ -59,18 +62,8 b' class AllThreadsView(BaseBoardView, Pagi' | |||
|
59 | 62 | if not form: |
|
60 | 63 | t_from_id = request.GET.get('t_from_id') |
|
61 | 64 | if t_from_id: |
|
62 | source_op = Post.objects.get(id=int(t_from_id)) | |
|
63 | tags_str = ' '.join([tag.get_name() for tag in source_op.get_thread().get_tags()]) | |
|
64 | post_link = '[post]{}[/post]'.format(source_op.id) #FIXME To constants | |
|
65 | new_title = source_op.get_title() + ' NEW' # TODO More intelligent name change | |
|
66 | ||
|
67 | form = ThreadForm(error_class=PlainErrorList, | |
|
68 | initial={ | |
|
69 | FORM_TAGS: tags_str, | |
|
70 | 'subscribe': subscribe_by_default, | |
|
71 | FORM_TEXT: post_link, | |
|
72 | FORM_TITLE: new_title, | |
|
73 | }) | |
|
65 | form = self.get_rollover_form(request, t_from_id, | |
|
66 | subscribe_by_default) | |
|
74 | 67 | else: |
|
75 | 68 | form = ThreadForm(error_class=PlainErrorList, |
|
76 | 69 | initial={FORM_TAGS: self.tag_name, |
@@ -149,3 +142,29 b' class AllThreadsView(BaseBoardView, Pagi' | |||
|
149 | 142 | settings_manager = get_settings_manager(request) |
|
150 | 143 | settings_manager.set_setting(SETTING_ONLY_FAVORITES, |
|
151 | 144 | not settings_manager.get_setting(SETTING_ONLY_FAVORITES, False)) |
|
145 | ||
|
146 | def get_rollover_form(self, request, t_from_id, subscribe_by_default): | |
|
147 | """ | |
|
148 | Create a new form template, passing on threads, link to the old thread, | |
|
149 | and incremeting the thread number in the title if there is any | |
|
150 | (or adding 2 if there isn't, normally meaning this was the first | |
|
151 | thread in a series). | |
|
152 | """ | |
|
153 | source_op = Post.objects.get(id=int(t_from_id)) | |
|
154 | tags_str = ' '.join([tag.get_name() for tag in source_op.get_thread().get_tags()]) | |
|
155 | post_link = '[post]{}[/post]'.format(source_op.id) #FIXME To constants | |
|
156 | ||
|
157 | old_title = source_op.get_title() | |
|
158 | m = PATTERN_THREAD_NUMBER.match(old_title) | |
|
159 | if m: | |
|
160 | new_title = m.group(1) + str(int(m.group(2)) + 1) + m.group(3) | |
|
161 | else: | |
|
162 | new_title = old_title + ' 2' | |
|
163 | ||
|
164 | return ThreadForm(error_class=PlainErrorList, | |
|
165 | initial={ | |
|
166 | FORM_TAGS: tags_str, | |
|
167 | 'subscribe': subscribe_by_default, | |
|
168 | FORM_TEXT: post_link, | |
|
169 | FORM_TITLE: new_title, | |
|
170 | }) |
General Comments 0
You need to be logged in to leave comments.
Login now