##// END OF EJS Templates
Merge remote changes
Bohdan Horbeshko -
r2116:f1427fde merge opera_mini_fix
parent child Browse files
Show More
@@ -1,3 +1,5 b''
1 import re
2
1 from django.core.paginator import EmptyPage
3 from django.core.paginator import EmptyPage
2 from django.http import Http404
4 from django.http import Http404
3 from django.shortcuts import render, redirect
5 from django.shortcuts import render, redirect
@@ -38,6 +40,7 b" PARAMETER_RSS_URL = 'rss_url'"
38 TEMPLATE = 'boards/all_threads.html'
40 TEMPLATE = 'boards/all_threads.html'
39 DEFAULT_PAGE = 1
41 DEFAULT_PAGE = 1
40
42
43 PATTERN_THREAD_NUMBER = re.compile(r'^(\D*)(\d+)(\D*)$')
41
44
42 class AllThreadsView(BaseBoardView, PaginatedMixin, DispatcherMixin):
45 class AllThreadsView(BaseBoardView, PaginatedMixin, DispatcherMixin):
43
46
@@ -59,18 +62,8 b' class AllThreadsView(BaseBoardView, Pagi'
59 if not form:
62 if not form:
60 t_from_id = request.GET.get('t_from_id')
63 t_from_id = request.GET.get('t_from_id')
61 if t_from_id:
64 if t_from_id:
62 source_op = Post.objects.get(id=int(t_from_id))
65 form = self.get_rollover_form(request, t_from_id,
63 tags_str = ' '.join([tag.get_name() for tag in source_op.get_thread().get_tags()])
66 subscribe_by_default)
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 })
74 else:
67 else:
75 form = ThreadForm(error_class=PlainErrorList,
68 form = ThreadForm(error_class=PlainErrorList,
76 initial={FORM_TAGS: self.tag_name,
69 initial={FORM_TAGS: self.tag_name,
@@ -149,3 +142,29 b' class AllThreadsView(BaseBoardView, Pagi'
149 settings_manager = get_settings_manager(request)
142 settings_manager = get_settings_manager(request)
150 settings_manager.set_setting(SETTING_ONLY_FAVORITES,
143 settings_manager.set_setting(SETTING_ONLY_FAVORITES,
151 not settings_manager.get_setting(SETTING_ONLY_FAVORITES, False))
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