Beispiel #1
0
def order_comments_by_score_for(context, link):
    """
    Preloads threaded comments in the same way Mezzanine initially does,
    but here we order them by score.
    """
    comments = defaultdict(list)
    qs = link.comments.visible().select_related("user", "user__profile")
    for comment in order_by_score(qs, CommentList.score_fields, "submit_date"):
        comments[comment.replied_to_id].append(comment)
    context["all_comments"] = comments
    return ""
Beispiel #2
0
 def get_context_data(self, **kwargs):
     context = super(ScoreOrderingView, self).get_context_data(**kwargs)
     qs = context["object_list"]
     context["by_score"] = self.kwargs.get("by_score", True)
     if context["by_score"]:
         qs = order_by_score(qs, self.score_fields, self.date_field)
     else:
         qs = qs.order_by("-" + self.date_field)
     context["object_list"] = paginate(qs, self.request.GET.get("page", 1),
         settings.ITEMS_PER_PAGE, settings.MAX_PAGING_LINKS)
     context["title"] = self.get_title(context)
     return context
Beispiel #3
0
 def get_context_data(self, **kwargs):
     context = super(ScoreOrderingView, self).get_context_data(**kwargs)
     qs = context["object_list"]
     context["by_score"] = self.kwargs.get("by_score", True)
     if context["by_score"]:
         qs = order_by_score(qs, self.score_fields, self.date_field)
     else:
         qs = qs.order_by("-" + self.date_field)
     context["object_list"] = paginate(qs, self.request.GET.get("page", 1),
         settings.ITEMS_PER_PAGE, settings.MAX_PAGING_LINKS)
     # Update context_object_name variable
     context_object_name = self.get_context_object_name(context["object_list"])
     context[context_object_name] = context["object_list"]
     context["title"] = self.get_title(context)
     return context