in kitsune/dashboards/readouts.py [0:0]
def get_queryset(self, max=None):
if self.mode in set(m[0] for m in self.modes):
period = self.mode
else:
period = self.default_mode
ignore_categories = [
NAVIGATION_CATEGORY,
ADMINISTRATION_CATEGORY,
HOW_TO_CONTRIBUTE_CATEGORY,
]
qs = (
Document.objects.visible(
self.user,
locale=settings.WIKI_DEFAULT_LANGUAGE,
is_archived=False,
is_localizable=True,
parent__isnull=True,
latest_localizable_revision__isnull=False,
)
.exclude(html__startswith=REDIRECT_HTML)
.filter(
no_translation_exists(self.locale)
| visible_translation_exists(self.user, self.locale)
)
)
if self.product:
qs = qs.filter(products=self.product)
if not self.product.questions_enabled(locale=self.locale):
# The product does not have a forum for this locale.
ignore_categories.append(CANNED_RESPONSES_CATEGORY)
transdoc_subquery = Document.objects.filter(
locale=self.locale,
parent=OuterRef("pk"),
).filter(
Exists(
Revision.objects.filter(document=OuterRef("pk")).filter(
Q(is_approved=True) | Q(reviewed__isnull=True)
)
)
)
qs = (
qs.exclude(category__in=ignore_categories)
.annotate(
transdoc_slug=Subquery(transdoc_subquery.values("slug")),
transdoc_title=Subquery(transdoc_subquery.values("title")),
transdoc_current_revision_based_on_id=Subquery(
transdoc_subquery.values("current_revision__based_on__id")
),
needs_review=Exists(
Revision.objects.filter(
document__parent=OuterRef("pk"),
document__locale=self.locale,
reviewed__isnull=True,
).filter(
Q(id__gt=F("document__current_revision__id"))
| Q(document__current_revision__isnull=True),
)
),
)
.annotate(most_significant_change=MOST_SIGNIFICANT_CHANGE_READY_TO_TRANSLATE_SUBQUERY)
.annotate(num_visits=get_visits_subquery(period=period))
.order_by(F("num_visits").desc(nulls_last=True), Coalesce("transdoc_title", "title"))
)
if max:
qs = qs[:max]
return qs.values_list(
"slug",
"title",
"transdoc_slug",
"transdoc_title",
"num_visits",
"most_significant_change",
"needs_review",
)