1a107601fa490ca69215facceebe3d0dc5e7f1f8 | 6bcef0037bdb2d139a15065c3f31e872bae79df3 | ||
---|---|---|---|
79 | 79 | ||
80 | @property | 80 | @property |
81 | def already_submitted_link(self): | 81 | def already_submitted_link(self): |
82 | return self.permalink + '?already_submitted=true' | 82 | return self.make_permalink_slow() + '?already_submitted=true' |
83 | 83 | ||
84 | def resubmit_link(self, sr_url = False): | 84 | def resubmit_link(self, sr_url = False): |
85 | submit_url = self.subreddit_slow.path if sr_url else '/' | 85 | submit_url = self.subreddit_slow.path if sr_url else '/' |
... | ... | ||
193 | c.user.pref_newwindow, | 193 | c.user.pref_newwindow, |
194 | c.user.pref_frame, | 194 | c.user.pref_frame, |
195 | c.user.pref_compress, | 195 | c.user.pref_compress, |
196 | c.user.pref_media, | ||
196 | request.host, | 197 | request.host, |
198 | c.cname, | ||
197 | wrapped.author == c.user, | 199 | wrapped.author == c.user, |
198 | wrapped.likes, | 200 | wrapped.likes, |
199 | wrapped.saved, | 201 | wrapped.saved, |
... | ... | ||
208 | s = ''.join(s) | 210 | s = ''.join(s) |
209 | return s | 211 | return s |
210 | 212 | ||
211 | @property | 213 | def make_permalink(self, sr): |
212 | def permalink(self): | 214 | p = "comments/%s/%s/" % (self._id36, title_to_url(self.title)) |
213 | return "/comments/%s/%s/" % (self._id36, title_to_url(self.title)) | 215 | if not c.cname: |
216 | res = "/r/%s/%s" % (sr.name, p) | ||
217 | elif sr != c.site: | ||
218 | res = "http://%s/r/%s/%s" % (g.domain, sr.name, p) | ||
219 | else: | ||
220 | res = "/%s" % p | ||
221 | return res | ||
214 | 222 | ||
223 | def make_permalink_slow(self): | ||
224 | return self.make_permalink(self.subreddit_slow) | ||
225 | |||
215 | @classmethod | 226 | @classmethod |
216 | def add_props(cls, user, wrapped): | 227 | def add_props(cls, user, wrapped): |
217 | from r2.lib.count import incr_counts | 228 | from r2.lib.count import incr_counts |
... | ... | ||
247 | item.clicked = bool(clicked.get((user, item, 'click'))) | 258 | item.clicked = bool(clicked.get((user, item, 'click'))) |
248 | item.num = None | 259 | item.num = None |
249 | item.score_fmt = Score.number_only | 260 | item.score_fmt = Score.number_only |
261 | item.permalink = item.make_permalink(item.subreddit) | ||
250 | 262 | ||
251 | if c.user_is_loggedin: | 263 | if c.user_is_loggedin: |
252 | incr_counts(wrapped) | 264 | incr_counts(wrapped) |
... | ... | ||
333 | bool(c.user_is_loggedin), | 345 | bool(c.user_is_loggedin), |
334 | c.focal_comment == self._id36, | 346 | c.focal_comment == self._id36, |
335 | request.host, | 347 | request.host, |
348 | c.cname, | ||
336 | wrapped.author == c.user, | 349 | wrapped.author == c.user, |
337 | wrapped.likes, | 350 | wrapped.likes, |
338 | wrapped.friend, | 351 | wrapped.friend, |
... | ... | ||
347 | s = ''.join(s) | 360 | s = ''.join(s) |
348 | return s | 361 | return s |
349 | 362 | ||
350 | @property | 363 | def make_permalink(self, link, sr=None): |
351 | def permalink(self): | 364 | return link.make_permalink(sr) + self._id36 |
352 | if not self._loaded: | ||
353 | self._load() | ||
354 | |||
355 | try: | ||
356 | l = Link._byID(self.link_id, True) | ||
357 | return l.permalink + self._id36 | ||
358 | except NotFound: | ||
359 | return "" | ||
360 | |||
361 | 365 | ||
366 | def make_permalink_slow(self): | ||
367 | l = Link._byID(self.link_id, data=True) | ||
368 | return self.make_permalink(l, l.subreddit_slow) | ||
369 | |||
362 | @classmethod | 370 | @classmethod |
363 | def add_props(cls, user, wrapped): | 371 | def add_props(cls, user, wrapped): |
364 | #fetch parent links | 372 | #fetch parent links |
365 | links = Link._byID(set(l.link_id for l in wrapped), True) | 373 | links = Link._byID(set(l.link_id for l in wrapped), True) |
374 | |||
366 | 375 | ||
367 | #get srs for comments that don't have them (old comments) | 376 | #get srs for comments that don't have them (old comments) |
368 | for cm in wrapped: | 377 | for cm in wrapped: |
... | ... | ||
378 | cids = dict((w._id, w) for w in wrapped) | 387 | cids = dict((w._id, w) for w in wrapped) |
379 | 388 | ||
380 | for item in wrapped: | 389 | for item in wrapped: |
390 | item.link = links.get(item.link_id) | ||
391 | if not hasattr(item, 'subreddit'): | ||
392 | item.subreddit = item.subreddit_slow | ||
381 | if hasattr(item, 'parent_id'): | 393 | if hasattr(item, 'parent_id'): |
382 | if cids.has_key(item.parent_id): | 394 | if cids.has_key(item.parent_id): |
383 | item.parent_permalink = '#' + utils.to36(item.parent_id) | 395 | item.parent_permalink = '#' + utils.to36(item.parent_id) |
384 | else: | 396 | else: |
385 | parent = Comment._byID(item.parent_id) | 397 | parent = Comment._byID(item.parent_id) |
386 | item.parent_permalink = parent.permalink | 398 | item.parent_permalink = parent.make_permalink(item.link, item.subreddit) |
387 | else: | 399 | else: |
388 | item.parent_permalink = None | 400 | item.parent_permalink = None |
389 | 401 | ||
390 | item.can_reply = (item.sr_id in can_reply_srs) | 402 | item.can_reply = (item.sr_id in can_reply_srs) |
391 | 403 | ||
392 | if not hasattr(item, 'subreddit'): | ||
393 | item.subreddit = item.subreddit_slow | ||
394 | 404 | ||
395 | # not deleted on profile pages, | 405 | # not deleted on profile pages, |
396 | # deleted if spam and not author or admin | 406 | # deleted if spam and not author or admin |
... | ... | ||
406 | item.deleted or | 416 | item.deleted or |
407 | c.user_is_admin)) | 417 | c.user_is_admin)) |
408 | 418 | ||
409 | item.link = links.get(item.link_id) | ||
410 | if not hasattr(item,'editted'): | 419 | if not hasattr(item,'editted'): |
411 | item.editted = False | 420 | item.editted = False |
412 | #will get updated in builder | 421 | #will get updated in builder |
413 | item.num_children = 0 | 422 | item.num_children = 0 |
414 | item.score_fmt = Score.points | 423 | item.score_fmt = Score.points |
424 | item.permalink = item.make_permalink(item.link, item.subreddit) | ||
415 | 425 | ||
416 | class MoreComments(object): | 426 | class MoreComments(object): |
417 | show_spam = False | 427 | show_spam = False |
... | ... | ||
432 | if parent: | 442 | if parent: |
433 | self.parent_id = parent._id | 443 | self.parent_id = parent._id |
434 | self.parent_name = parent._fullname | 444 | self.parent_name = parent._fullname |
435 | self.parent_permalink = parent.permalink | 445 | self.parent_permalink = parent.make_permalink(link) |
436 | self.link_name = link._fullname | 446 | self.link_name = link._fullname |
437 | self.link_id = link._id | 447 | self.link_id = link._id |
438 | self.depth = depth | 448 | self.depth = depth |