From 1e74945a410001bb747e6e90760fac01ec76b68e Mon Sep 17 00:00:00 2001 From: Bryce Boe Date: Mon, 13 Feb 2012 17:24:29 -0800 Subject: [PATCH] Add ability to distinguish between when comments have zero replies, and when their reply tree wasn't built. --- r2/r2/controllers/front.py | 5 +++++ r2/r2/controllers/listingcontroller.py | 9 ++++++++- r2/r2/lib/template_helpers.py | 13 +++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 052aaa92e..f077cac2c 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -487,6 +487,11 @@ class FrontController(RedditController): listing = LinkListing(builder) pane = listing.listing() + # Indicate that the comment tree wasn't built for comments + for i in pane.things: + if hasattr(i, 'body'): + i.child = None + return pane def _edit_modcontrib_reddit(self, location, num, after, reverse, count, created): diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index 350bdcaee..7bf83e4d4 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -708,7 +708,14 @@ class MessageController(ListingController): if (self.where == 'messages' and (c.user.pref_threaded_messages or self.message)): return Listing(self.builder_obj).listing() - return ListingController.listing(self) + pane = ListingController.listing(self) + + # Indicate that the comment tree wasn't built for comments + for i in pane.things: + if i.was_comment: + i.child = None + + return pane def query(self): if self.where == 'messages': diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index 42e3f7983..1400239a5 100644 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -186,10 +186,15 @@ def replace_render(listing, item, render_func): style = style or c.render_style or 'html' replacements = {} - child_txt = ( hasattr(item, "child") and item.child )\ - and item.child.render(style = style) or "" - replacements["childlisting"] = child_txt - + if hasattr(item, 'child'): + if item.child: + replacements['childlisting'] = item.child.render(style=style) + else: + # Special case for when the comment tree wasn't built which + # occurs both in the inbox and spam page view of comments. + replacements['childlisting'] = None + else: + replacements['childlisting'] = '' #only LinkListing has a show_nums attribute if listing: