Show More
@@ -146,18 +146,7 b' class Post(models.Model, Viewable):' | |||
|
146 | 146 | def get_absolute_url(self, thread=None): |
|
147 | 147 | # Url is cached only for the "main" thread. When getting url |
|
148 | 148 | # for other threads, do it manually. |
|
149 |
|
|
|
150 | ||
|
151 | if url is None: | |
|
152 | if thread is None: | |
|
153 | thread = self.get_thread() | |
|
154 | opening = self.is_opening() | |
|
155 | opening_id = self.id if opening else thread.get_opening_post_id() | |
|
156 | url = reverse('thread', kwargs={'post_id': opening_id}) | |
|
157 | if not opening: | |
|
158 | url += '#' + str(self.id) | |
|
159 | ||
|
160 | return url | |
|
149 | return self.url | |
|
161 | 150 | |
|
162 | 151 | def get_thread(self): |
|
163 | 152 | return self.thread |
@@ -309,9 +298,14 b' class Post(models.Model, Viewable):' | |||
|
309 | 298 | except ObjectDoesNotExist: |
|
310 | 299 | pass |
|
311 | 300 | |
|
312 | def build_url(self): | |
|
313 | self.url = self.get_absolute_url() | |
|
314 | self.save(update_fields=['url']) | |
|
301 | def _build_url(self): | |
|
302 | opening = self.is_opening() | |
|
303 | opening_id = self.id if opening else self.get_thread().get_opening_post_id() | |
|
304 | url = reverse('thread', kwargs={'post_id': opening_id}) | |
|
305 | if not opening: | |
|
306 | url += '#' + str(self.id) | |
|
307 | ||
|
308 | return url | |
|
315 | 309 | |
|
316 | 310 | def save(self, force_insert=False, force_update=False, using=None, |
|
317 | 311 | update_fields=None): |
@@ -329,8 +323,9 b' class Post(models.Model, Viewable):' | |||
|
329 | 323 | |
|
330 | 324 | super().save(force_insert, force_update, using, update_fields) |
|
331 | 325 | |
|
332 | if self.url is None: | |
|
333 | self.build_url() | |
|
326 | if new_post: | |
|
327 | self.url = self._build_url() | |
|
328 | super().save(update_fields=['url']) | |
|
334 | 329 | |
|
335 | 330 | def get_text(self) -> str: |
|
336 | 331 | return self._text_rendered |
General Comments 0
You need to be logged in to leave comments.
Login now