Example #1
0
def show_check(request, name):
    """Show details about failing check."""
    try:
        check = CHECKS[name]
    except KeyError:
        raise Http404("No check matches the given query.")

    url_params = {}

    kwargs = {
        "component__translation__unit__check__check": name,
    }

    form = FilterForm(request.GET)
    if form.is_valid():
        if form.cleaned_data.get("lang"):
            kwargs["component__translation__language__code"] = form.cleaned_data["lang"]
            url_params["lang"] = form.cleaned_data["lang"]

        # This has to be done after updating url_params
        if form.cleaned_data.get("project") and "/" not in form.cleaned_data["project"]:
            return redirect_param(
                "show_check_project",
                encode_optional(url_params),
                project=form.cleaned_data["project"],
                name=name,
            )

    projects = (
        request.user.allowed_projects.filter(**kwargs)
        .annotate(
            check_count=Count("component__translation__unit__check"),
            dismissed_check_count=conditional_sum(
                1, component__translation__unit__check__dismissed=True
            ),
            active_check_count=conditional_sum(
                1, component__translation__unit__check__dismissed=False
            ),
            translated_check_count=conditional_sum(
                1,
                component__translation__unit__check__dismissed=False,
                component__translation__unit__state__gte=STATE_TRANSLATED,
            ),
        )
        .order()
    )

    return render(
        request,
        "check.html",
        {
            "projects": projects,
            "title": check.name,
            "check": check,
            "url_params": encode_optional(url_params),
        },
    )
Example #2
0
def show_check_project(request, name, project):
    """Show checks failing in a project."""
    prj = get_project(request, project)
    try:
        check = CHECKS[name]
    except KeyError:
        raise Http404("No check matches the given query.")

    url_params = {}

    kwargs = {
        "project": prj,
        "translation__unit__check__check": name,
    }

    form = FilterForm(request.GET)
    if form.is_valid():
        if form.cleaned_data.get("lang"):
            kwargs["translation__language__code"] = form.cleaned_data["lang"]
            url_params["lang"] = form.cleaned_data["lang"]

    components = (
        Component.objects.filter(**kwargs)
        .annotate(
            check_count=Count("translation__unit__check"),
            dismissed_check_count=conditional_sum(
                1, translation__unit__check__dismissed=True
            ),
            active_check_count=conditional_sum(
                1, translation__unit__check__dismissed=False
            ),
            translated_check_count=conditional_sum(
                1,
                translation__unit__check__dismissed=False,
                translation__unit__state__gte=STATE_TRANSLATED,
            ),
        )
        .order()
    )

    return render(
        request,
        "check_project.html",
        {
            "components": components,
            "title": "{0}/{1}".format(force_str(prj), check.name),
            "check": check,
            "project": prj,
            "url_params": encode_optional(url_params),
        },
    )
Example #3
0
def show_checks(request):
    """List of failing checks."""
    url_params = {}
    user = request.user

    kwargs = {
        "unit__translation__component__project_id__in": user.allowed_project_ids,
    }

    form = FilterForm(request.GET)
    if form.is_valid():
        if form.cleaned_data.get("project"):
            kwargs["unit__translation__component__project__slug"] = form.cleaned_data[
                "project"
            ]
            url_params["project"] = form.cleaned_data["project"]

        if form.cleaned_data.get("lang"):
            kwargs["unit__translation__language__code"] = form.cleaned_data["lang"]
            url_params["lang"] = form.cleaned_data["lang"]

        if form.cleaned_data.get("component"):
            kwargs["unit__translation__component__slug"] = form.cleaned_data[
                "component"
            ]
            url_params["component"] = form.cleaned_data["component"]

    allchecks = (
        Check.objects.filter(**kwargs)
        .values("check")
        .annotate(
            check_count=Count("id"),
            dismissed_check_count=conditional_sum(1, dismissed=True),
            active_check_count=conditional_sum(1, dismissed=False),
            translated_check_count=conditional_sum(
                1, dismissed=False, unit__state__gte=STATE_TRANSLATED
            ),
        )
    )

    return render(
        request,
        "checks.html",
        {
            "checks": allchecks,
            "title": _("Failing checks"),
            "url_params": encode_optional(url_params),
        },
    )
Example #4
0
 def count_changes(self):
     if self.last_changed:
         monthly = timezone.now() - timedelta(days=30)
         recently = self.last_changed - timedelta(hours=6)
         changes = self._object.change_set.content().aggregate(
             total=Count("id"),
             recent=conditional_sum(timestamp__gt=recently),
             monthly=conditional_sum(timestamp__gt=monthly),
         )
         self.store("recent_changes", changes["recent"])
         self.store("monthly_changes", changes["monthly"])
         self.store("total_changes", changes["total"])
     else:
         self.store("recent_changes", 0)
         self.store("monthly_changes", 0)
         self.store("total_changes", 0)
Example #5
0
def show_check_component(request, name, project, component):
    """Show checks failing in a component."""
    component = get_component(request, project, component)
    try:
        check = CHECKS[name]
    except KeyError:
        raise Http404("No check matches the given query.")

    kwargs = {}

    if request.GET.get("lang"):
        kwargs["language__code"] = request.GET["lang"]

    translations = (
        Translation.objects.filter(
            component=component, unit__check__check=name, **kwargs
        )
        .annotate(
            check_count=Count("unit__check"),
            dismissed_check_count=conditional_sum(1, unit__check__dismissed=True),
            active_check_count=conditional_sum(1, unit__check__dismissed=False),
            translated_check_count=conditional_sum(
                1, unit__check__dismissed=False, unit__state__gte=STATE_TRANSLATED
            ),
        )
        .order_by("language__code")
        .select_related("language")
    )

    return render(
        request,
        "check_component.html",
        {
            "translations": translations,
            "title": "{0}/{1}".format(force_str(component), check.name),
            "check": check,
            "component": component,
        },
    )
Example #6
0
    def prefetch_basic(self):
        from weblate.trans.models import Unit

        base = self._object.unit_set
        stats = base.aggregate(
            all=Count("id"),
            all_words=Sum("num_words"),
            all_chars=Sum(Length("source")),
            fuzzy=conditional_sum(1, state=STATE_FUZZY),
            fuzzy_words=conditional_sum("num_words", state=STATE_FUZZY),
            fuzzy_chars=conditional_sum(Length("source"), state=STATE_FUZZY),
            translated=conditional_sum(1, state__gte=STATE_TRANSLATED),
            translated_words=conditional_sum("num_words",
                                             state__gte=STATE_TRANSLATED),
            translated_chars=conditional_sum(Length("source"),
                                             state__gte=STATE_TRANSLATED),
            todo=conditional_sum(1, state__lt=STATE_TRANSLATED),
            todo_words=conditional_sum("num_words",
                                       state__lt=STATE_TRANSLATED),
            todo_chars=conditional_sum(Length("source"),
                                       state__lt=STATE_TRANSLATED),
            nottranslated=conditional_sum(1, state=STATE_EMPTY),
            nottranslated_words=conditional_sum("num_words",
                                                state=STATE_EMPTY),
            nottranslated_chars=conditional_sum(Length("source"),
                                                state=STATE_EMPTY),
            approved=conditional_sum(1, state__gte=STATE_APPROVED),
            approved_words=conditional_sum("num_words",
                                           state__gte=STATE_APPROVED),
            approved_chars=conditional_sum(Length("source"),
                                           state__gte=STATE_APPROVED),
            unlabeled=conditional_sum(1, labels__isnull=True),
            unlabeled_words=conditional_sum("num_words", labels__isnull=True),
            unlabeled_chars=conditional_sum(Length("source"),
                                            labels__isnull=True),
        )
        check_stats = Unit.objects.filter(id__in=set(
            base.filter(check__dismissed=False).values_list("id", flat=True)
        )).aggregate(
            allchecks=Count("id"),
            allchecks_words=Sum("num_words"),
            allchecks_chars=Sum(Length("source")),
            translated_checks=conditional_sum(1, state=STATE_TRANSLATED),
            translated_checks_words=conditional_sum("num_words",
                                                    state=STATE_TRANSLATED),
            translated_checks_chars=conditional_sum(Length("source"),
                                                    state=STATE_TRANSLATED),
        )
        suggestion_stats = Unit.objects.filter(id__in=set(
            base.filter(suggestion__isnull=False).values_list(
                "id", flat=True))).aggregate(
                    suggestions=Count("id"),
                    suggestions_words=Sum("num_words"),
                    suggestions_chars=Sum(Length("source")),
                    approved_suggestions=conditional_sum(
                        1, state__gte=STATE_APPROVED),
                    approved_suggestions_words=conditional_sum(
                        "num_words", state__gte=STATE_APPROVED),
                    approved_suggestions_chars=conditional_sum(
                        Length("source"), state__gte=STATE_APPROVED),
                )
        comment_stats = Unit.objects.filter(id__in=set(
            base.filter(comment__resolved=False).values_list(
                "id", flat=True))).aggregate(
                    comments=Count("id"),
                    comments_words=Sum("num_words"),
                    comments_chars=Sum(Length("source")),
                )
        for key, value in chain(
                stats.items(),
                check_stats.items(),
                suggestion_stats.items(),
                comment_stats.items(),
        ):
            self.store(key, value)

        # Calculate some values
        self.store("languages", 1)

        # Calculate percents
        self.calculate_basic_percents()

        # Last change timestamp
        self.fetch_last_change()
Example #7
0
    def _prefetch_basic(self):
        base = self._object.unit_set.annotate(
            active_checks_count=Count("check", filter=Q(check__dismissed=False)),
            suggestion_count=Count("suggestion"),
            comment_count=Count("comment", filter=Q(comment__resolved=False)),
        )
        stats = base.aggregate(
            all=Count("id"),
            all_words=Sum("num_words"),
            all_chars=Sum(Length("source")),
            fuzzy=conditional_sum(1, state=STATE_FUZZY),
            fuzzy_words=conditional_sum("num_words", state=STATE_FUZZY),
            fuzzy_chars=conditional_sum(Length("source"), state=STATE_FUZZY),
            readonly=conditional_sum(1, state=STATE_READONLY),
            readonly_words=conditional_sum("num_words", state=STATE_READONLY),
            readonly_chars=conditional_sum(Length("source"), state=STATE_READONLY),
            translated=conditional_sum(1, state__gte=STATE_TRANSLATED),
            translated_words=conditional_sum("num_words", state__gte=STATE_TRANSLATED),
            translated_chars=conditional_sum(
                Length("source"), state__gte=STATE_TRANSLATED
            ),
            todo=conditional_sum(1, state__lt=STATE_TRANSLATED),
            todo_words=conditional_sum("num_words", state__lt=STATE_TRANSLATED),
            todo_chars=conditional_sum(Length("source"), state__lt=STATE_TRANSLATED),
            nottranslated=conditional_sum(1, state=STATE_EMPTY),
            nottranslated_words=conditional_sum("num_words", state=STATE_EMPTY),
            nottranslated_chars=conditional_sum(Length("source"), state=STATE_EMPTY),
            # Review workflow
            approved=conditional_sum(1, state=STATE_APPROVED),
            approved_words=conditional_sum("num_words", state=STATE_APPROVED),
            approved_chars=conditional_sum(Length("source"), state=STATE_APPROVED),
            # Labels
            unlabeled=conditional_sum(1, source_unit__labels__isnull=True),
            unlabeled_words=conditional_sum(
                "num_words", source_unit__labels__isnull=True
            ),
            unlabeled_chars=conditional_sum(
                Length("source"), source_unit__labels__isnull=True
            ),
            # Checks
            allchecks=conditional_sum(1, active_checks_count__gt=0),
            allchecks_words=conditional_sum("num_words", active_checks_count__gt=0),
            allchecks_chars=conditional_sum(
                Length("source"), active_checks_count__gt=0
            ),
            translated_checks=conditional_sum(
                1, state=STATE_TRANSLATED, active_checks_count__gt=0
            ),
            translated_checks_words=conditional_sum(
                "num_words", state=STATE_TRANSLATED, active_checks_count__gt=0
            ),
            translated_checks_chars=conditional_sum(
                Length("source"), state=STATE_TRANSLATED, active_checks_count__gt=0
            ),
            # Suggestions
            suggestions=conditional_sum(1, suggestion_count__gt=0),
            suggestions_words=conditional_sum("num_words", suggestion_count__gt=0),
            suggestions_chars=conditional_sum(Length("source"), suggestion_count__gt=0),
            nosuggestions=conditional_sum(1, suggestion_count=0),
            nosuggestions_words=conditional_sum("num_words", suggestion_count=0),
            nosuggestions_chars=conditional_sum(Length("source"), suggestion_count=0),
            approved_suggestions=conditional_sum(
                1, state__gte=STATE_APPROVED, suggestion_count__gt=0
            ),
            approved_suggestions_words=conditional_sum(
                "num_words", state__gte=STATE_APPROVED, suggestion_count__gt=0
            ),
            approved_suggestions_chars=conditional_sum(
                Length("source"), state__gte=STATE_APPROVED, suggestion_count__gt=0
            ),
            # Comments
            comments=conditional_sum(1, comment_count__gt=0),
            comments_words=conditional_sum("num_words", comment_count__gt=0),
            comments_chars=conditional_sum(Length("source"), comment_count__gt=0),
        )
        for key, value in stats.items():
            self.store(key, value)

        # Calculate some values
        self.store("languages", 1)

        # Calculate percents
        self.calculate_basic_percents()

        # Last change timestamp
        self.fetch_last_change()
Example #8
0
    def prefetch_basic(self):
        stats = self._object.unit_set.aggregate(
            all=Count("id"),
            all_words=Sum("num_words"),
            all_chars=Sum(Length("source")),
            fuzzy=conditional_sum(1, state=STATE_FUZZY),
            fuzzy_words=conditional_sum("num_words", state=STATE_FUZZY),
            fuzzy_chars=conditional_sum(Length("source"), state=STATE_FUZZY),
            translated=conditional_sum(1, state__gte=STATE_TRANSLATED),
            translated_words=conditional_sum("num_words", state__gte=STATE_TRANSLATED),
            translated_chars=conditional_sum(
                Length("source"), state__gte=STATE_TRANSLATED
            ),
            todo=conditional_sum(1, state__lt=STATE_TRANSLATED),
            todo_words=conditional_sum("num_words", state__lt=STATE_TRANSLATED),
            todo_chars=conditional_sum(Length("source"), state__lt=STATE_TRANSLATED),
            nottranslated=conditional_sum(1, state=STATE_EMPTY),
            nottranslated_words=conditional_sum("num_words", state=STATE_EMPTY),
            nottranslated_chars=conditional_sum(Length("source"), state=STATE_EMPTY),
            approved=conditional_sum(1, state__gte=STATE_APPROVED),
            approved_words=conditional_sum("num_words", state__gte=STATE_APPROVED),
            approved_chars=conditional_sum(Length("source"), state__gte=STATE_APPROVED),
            allchecks=conditional_sum(1, has_failing_check=True),
            allchecks_words=conditional_sum("num_words", has_failing_check=True),
            allchecks_chars=conditional_sum(Length("source"), has_failing_check=True),
            translated_checks=conditional_sum(
                1, has_failing_check=True, state=STATE_TRANSLATED
            ),
            translated_checks_words=conditional_sum(
                "num_words", has_failing_check=True, state=STATE_TRANSLATED
            ),
            translated_checks_chars=conditional_sum(
                Length("source"), has_failing_check=True, state=STATE_TRANSLATED
            ),
            suggestions=conditional_sum(1, has_suggestion=True),
            suggestions_words=conditional_sum("num_words", has_suggestion=True),
            suggestions_chars=conditional_sum(Length("source"), has_suggestion=True),
            comments=conditional_sum(1, has_comment=True),
            comments_words=conditional_sum("num_words", has_comment=True),
            comments_chars=conditional_sum(Length("source"), has_comment=True),
            approved_suggestions=conditional_sum(
                1, state__gte=STATE_APPROVED, has_suggestion=True
            ),
            approved_suggestions_words=conditional_sum(
                "num_words", state__gte=STATE_APPROVED, has_suggestion=True
            ),
            approved_suggestions_chars=conditional_sum(
                Length("source"), state__gte=STATE_APPROVED, has_suggestion=True
            ),
        )
        for key, value in stats.items():
            self.store(key, value)

        # Calculate some values
        self.store("languages", 1)

        # Calculate percents
        self.calculate_basic_percents()

        # Last change timestamp
        self.fetch_last_change()