How to use the weblate.trans.models.Unit.objects.filter function in weblate

To help you get started, we’ve selected a few weblate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeblateOrg / weblate / weblate / trans / models.py View on Github external
def get_matching_unit(self):
        '''
        Retrieves one (possibly out of several) unit matching
        this suggestion.
        '''
        return Unit.objects.filter(
            checksum=self.checksum,
            translation__subproject__project=self.project,
            translation__language=self.language,
        )[0]
github WeblateOrg / weblate / weblate / trans / models.py View on Github external
# unit in some formats (XLIFF), so let's skip those as well
                if not template_unit.istranslatable() or template_unit.isblank():
                    continue
                unit = store.findid(template_unit.getid())
                newunit, is_new = Unit.objects.update_from_unit(
                    self, unit, pos, template=template_unit
                )
                was_new = was_new or (is_new and not newunit.translated)
                pos += 1
                try:
                    oldunits.remove(newunit.id)
                except:
                    pass

        # Delete not used units
        units_to_delete = Unit.objects.filter(
            translation=self, id__in=oldunits
        )
        # We need to resolve this now as otherwise list will become empty after
        # delete
        deleted_checksums = units_to_delete.values_list('checksum', flat=True)
        deleted_checksums = list(deleted_checksums)
        units_to_delete.delete()

        # Cleanup checks for deleted units
        for checksum in deleted_checksums:
            units = Unit.objects.filter(
                translation__language=self.language,
                translation__subproject__project=self.subproject.project,
                checksum=checksum
            )
            if not units.exists():
github WeblateOrg / weblate / weblate / trans / models.py View on Github external
checksum=checksum
                ).delete()
                # Delete suggestons referencing this unit
                Suggestion.objects.filter(
                    project=self.subproject.project,
                    language=self.language,
                    checksum=checksum
                ).delete()
                # Delete translation comments referencing this unit
                Comment.objects.filter(
                    project=self.subproject.project,
                    language=self.language,
                    checksum=checksum
                ).delete()
                # Check for other units with same source
                other_units = Unit.objects.filter(
                    translation__subproject__project=self.subproject.project,
                    checksum=checksum
                )
                if not other_units.exists():
                    # Delete source comments as well if this was last reference
                    Comment.objects.filter(
                        project=self.subproject.project,
                        language=None,
                        checksum=checksum
                    ).delete()
                    # Delete source checks as well if this was last reference
                    Check.objects.filter(
                        project=self.subproject.project,
                        language=None,
                        checksum=checksum
                    ).delete()
github WeblateOrg / weblate / weblate / trans / views.py View on Github external
def show_check_subproject(request, name, project, subproject):
    '''
    Show checks failing in a subproject.
    '''
    subprj = get_object_or_404(SubProject, slug = subproject, project__slug = project)
    try:
        check = CHECKS[name]
    except KeyError:
        raise Http404('No check matches the given query.')
    units = Unit.objects.none()
    if check.target:
        langs = Check.objects.filter(check = name, project = subprj.project, ignore = False).values_list('language', flat = True).distinct()
        for lang in langs:
            checks = Check.objects.filter(check = name, project = subprj.project, language = lang, ignore = False).values_list('checksum', flat = True)
            res = Unit.objects.filter(translation__subproject = subprj, checksum__in = checks, translation__language = lang, translated = True).values('translation__language__code').annotate(count = Count('id'))
            units |= res
    source_checks = []
    if check.source:
        checks = Check.objects.filter(check = name, project = subprj.project, language = None, ignore = False).values_list('checksum', flat = True)
        lang = subprj.translation_set.all()[0].language
        res = Unit.objects.filter(translation__subproject = subprj, checksum__in = checks, translation__language = lang).count()
        if res > 0:
            source_checks.append(res)
    return render_to_response('check_subproject.html', RequestContext(request, {
        'checks': units,
        'source_checks': source_checks,
        'anychecks': len(units) + len(source_checks) > 0,
        'title': '%s/%s' % (subprj.__unicode__(), check.name),
        'check': check,
        'subproject': subprj,
    }))
github WeblateOrg / weblate / weblate / trans / views / js.py View on Github external
def get_unit_translations(request, unit_id):
    """Return unit's other translations."""
    unit = get_object_or_404(Unit, pk=int(unit_id))
    request.user.check_access(unit.translation.component.project)

    return render(
        request,
        'js/translations.html',
        {
            'units': sort_objects(
                Unit.objects.filter(
                    id_hash=unit.id_hash,
                    translation__component=unit.translation.component,
                ).exclude(
                    pk=unit.pk
                )
github WeblateOrg / weblate / weblate / trans / models.py View on Github external
except:
                    pass

        # Delete not used units
        units_to_delete = Unit.objects.filter(
            translation=self, id__in=oldunits
        )
        # We need to resolve this now as otherwise list will become empty after
        # delete
        deleted_checksums = units_to_delete.values_list('checksum', flat=True)
        deleted_checksums = list(deleted_checksums)
        units_to_delete.delete()

        # Cleanup checks for deleted units
        for checksum in deleted_checksums:
            units = Unit.objects.filter(
                translation__language=self.language,
                translation__subproject__project=self.subproject.project,
                checksum=checksum
            )
            if not units.exists():
                # Last unit referencing to these checks
                Check.objects.filter(
                    project=self.subproject.project,
                    language=self.language,
                    checksum=checksum
                ).delete()
                # Delete suggestons referencing this unit
                Suggestion.objects.filter(
                    project=self.subproject.project,
                    language=self.language,
                    checksum=checksum
github WeblateOrg / weblate / weblate / trans / views / guide.py View on Github external
def is_relevant(self):
        return Unit.objects.filter(
            translation__component=self.component, source__contains="