Exemple #1
0
def cleanup_deleted(sender, instance, **kwargs):
    """
    Removes stale checks/comments/suggestions for deleted units.
    """
    project = instance.translation.subproject.project
    language = instance.translation.language
    contentsum = instance.contentsum
    units = Unit.objects.filter(
        translation__language=language, translation__subproject__project=project, contentsum=contentsum
    )
    if units.exists():
        # There are other units as well, but some checks
        # (eg. consistency) needs update now
        for unit in units:
            unit.run_checks()
        return

    # Last unit referencing to these checks
    Check.objects.filter(project=project, language=language, contentsum=contentsum).delete()
    # Delete suggestons referencing this unit
    Suggestion.objects.filter(project=project, language=language, contentsum=contentsum).delete()
    # Delete translation comments referencing this unit
    Comment.objects.filter(project=project, language=language, contentsum=contentsum).delete()
    # Check for other units with same source
    other_units = Unit.objects.filter(translation__subproject__project=project, contentsum=contentsum)
    if not other_units.exists():
        # Delete source comments as well if this was last reference
        Comment.objects.filter(project=project, language=None, contentsum=contentsum).delete()
        # Delete source checks as well if this was last reference
        Check.objects.filter(project=project, language=None, contentsum=contentsum).delete()

    # Cleanup fulltext index
    clean_search_unit(instance.pk, language.code)
Exemple #2
0
 def cleanup_fulltext(self):
     """Remove stale units from fulltext"""
     languages = Language.objects.have_translation().values_list('code',
                                                                 flat=True)
     # We operate only on target indexes as they will have all IDs anyway
     for lang in languages:
         index = get_target_index(lang)
         try:
             fields = index.reader().all_stored_fields()
         except EmptyIndexError:
             continue
         for item in fields:
             if Unit.objects.filter(pk=item['pk']).exists():
                 continue
             clean_search_unit(item['pk'], lang)
Exemple #3
0
 def cleanup_fulltext(self):
     """Remove stale units from fulltext"""
     with transaction.atomic():
         languages = list(Language.objects.have_translation().values_list(
             'code', flat=True
         ))
     # We operate only on target indexes as they will have all IDs anyway
     for lang in languages:
         index = get_target_index(lang)
         try:
             fields = index.reader().all_stored_fields()
         except EmptyIndexError:
             continue
         for item in fields:
             if Unit.objects.filter(pk=item['pk']).exists():
                 continue
             clean_search_unit(item['pk'], lang)
Exemple #4
0
def cleanup_deleted(sender, instance, **kwargs):
    '''
    Removes stale checks/comments/suggestions for deleted units.
    '''
    project = instance.translation.subproject.project
    language = instance.translation.language
    contentsum = instance.contentsum
    units = Unit.objects.filter(translation__language=language,
                                translation__subproject__project=project,
                                contentsum=contentsum)
    if units.exists():
        # There are other units as well, but some checks
        # (eg. consistency) needs update now
        for unit in units:
            unit.run_checks()
        return

    # Last unit referencing to these checks
    Check.objects.filter(project=project,
                         language=language,
                         contentsum=contentsum).delete()
    # Delete suggestons referencing this unit
    Suggestion.objects.filter(project=project,
                              language=language,
                              contentsum=contentsum).delete()
    # Delete translation comments referencing this unit
    Comment.objects.filter(project=project,
                           language=language,
                           contentsum=contentsum).delete()
    # Check for other units with same source
    other_units = Unit.objects.filter(translation__subproject__project=project,
                                      contentsum=contentsum)
    if not other_units.exists():
        # Delete source comments as well if this was last reference
        Comment.objects.filter(project=project,
                               language=None,
                               contentsum=contentsum).delete()
        # Delete source checks as well if this was last reference
        Check.objects.filter(project=project,
                             language=None,
                             contentsum=contentsum).delete()

    # Cleanup fulltext index
    clean_search_unit(instance.pk, language.code)