def update_checks(self, check_names, translation_project=None): update_checks.send( TranslationProject, check_names=check_names, instance=translation_project, clear_unknown=True, update_data_after=True)
def test_data_store_critical_checks(store0): qc_qs = QualityCheck.objects qc_qs = (qc_qs.filter(unit__store=store0).filter( unit__state__gt=UNTRANSLATED).filter( category=Category.CRITICAL).exclude(false_positive=True)) check_count = qc_qs.count() assert (store0.data.critical_checks == check_count) unit = store0.units.exclude(qualitycheck__isnull=True, qualitycheck__name__in=["xmltags", "endpunc"]).first() unit.target = "<foo></bar>;" unit.save() unit_critical = unit.qualitycheck_set.filter( category=Category.CRITICAL).count() assert (store0.data.critical_checks == check_count + unit_critical) # lets make another unit false positive other_qc = unit.qualitycheck_set.exclude(name="xmltags").filter( category=Category.CRITICAL).first() other_qc.false_positive = True other_qc.save() # trigger refresh update_checks.send(unit.__class__, instance=unit, keep_false_positives=True) update_data.send(unit.store.__class__, instance=unit.store, keep_false_positives=True) assert (store0.data.critical_checks == check_count + unit_critical - 1)
def handle_unit_change(**kwargs): unit_change = kwargs["instance"] unit = unit_change.unit created = not unit._frozen.pk if not created: lifecycle.get(Unit)(unit).change() if not unit.source_updated and not unit.target_updated: return new_untranslated = (created and unit.state == UNTRANSLATED) if not new_untranslated: update_checks.send(unit.__class__, instance=unit) if unit.istranslated(): unit.update_tmserver()
def handle_unit_change(**kwargs): unit_change = kwargs["instance"] unit = unit_change.unit created = not unit._frozen.pk if not created: lifecycle.get(Unit)(unit).change() if not unit.source_updated and not unit.target_updated: return new_untranslated = (created and unit.state == UNTRANSLATED) if not new_untranslated: update_checks.send(unit.__class__, instance=unit) if unit.istranslated(): unit.update_tmserver()
def test_data_tp_qc_stats(tp0): units = Unit.objects.filter( state__gt=OBSOLETE, store__translation_project=tp0) qc_qs = QualityCheck.objects qc_qs = ( qc_qs.filter(unit__store__translation_project=tp0) .filter(unit__state__gt=UNTRANSLATED) .filter(category=Category.CRITICAL) .exclude(false_positive=True)) check_count = qc_qs.count() store_data = tp0.data_tool.updater.get_store_data() assert ( store_data["critical_checks"] == tp0.data.critical_checks == check_count) unit = units.exclude( qualitycheck__isnull=True, qualitycheck__name__in=["xmltags", "endpunc"]).first() unit.target = "<foo></bar>;" unit.save() unit_critical = unit.qualitycheck_set.filter( category=Category.CRITICAL).count() store_data = tp0.data_tool.updater.get_store_data() tp0.data.refresh_from_db() assert ( store_data["critical_checks"] == tp0.data.critical_checks == check_count + unit_critical) # lets make another unit false positive other_qc = unit.qualitycheck_set.exclude( name="xmltags").filter(category=Category.CRITICAL).first() other_qc.false_positive = True other_qc.save() # trigger refresh update_checks.send( unit.__class__, instance=unit, keep_false_positives=True) update_data.send( unit.store.__class__, instance=unit.store, keep_false_positives=True) store_data = tp0.data_tool.updater.get_store_data() tp0.data.refresh_from_db() assert ( store_data["critical_checks"] == tp0.data.critical_checks == check_count + unit_critical - 1)
def _handle_update_stores(sender, updated): @receiver(update_data, sender=sender.__class__) def update_tp_data_handler(**kwargs): updated.tp_data = True update_data.disconnect( update_tp_data_handler, sender=sender.__class__) @receiver(update_scores, sender=sender.__class__) def update_tp_scores_handler(**kwargs): updated.tp_scores = True update_scores.disconnect( update_tp_scores_handler, sender=sender.__class__) if updated.checks: with keep_data(suppress=(Store, ), signals=(update_data, )): @receiver(update_data, sender=Store) def extra_update_data_handler_(**kwargs): updated.data = updated.data or {} updated.data[kwargs["instance"].id] = kwargs["instance"] with bulk_operations(QualityCheck): for to_check in updated.checks.values(): store = to_check["store"] units = ( [unit for unit in to_check["units"]] if to_check["units"] else None) update_checks.send( store.__class__, instance=store, units=units) if updated.data: stores = updated.data.values() for store in stores: update_data.send( Store, instance=store) if updated.score_stores: for store in updated.score_stores.values(): update_scores.send( store.__class__, instance=store, users=updated.score_users)
def resurrect(self, is_fuzzy=False): if self.state > OBSOLETE: return if filter(None, self.target_f.strings): # when Unit toggles its OBSOLETE state the number of translated # words or fuzzy words also changes if is_fuzzy: self.state = FUZZY else: self.state = TRANSLATED else: self.state = UNTRANSLATED update_checks.send(self.__class__, instance=self, keep_false_positives=True) self.index = self.store.max_index() + 1
def resurrect(self, is_fuzzy=False): if self.state > OBSOLETE: return if filter(None, self.target_f.strings): # when Unit toggles its OBSOLETE state the number of translated # words or fuzzy words also changes if is_fuzzy: self.state = FUZZY else: self.state = TRANSLATED else: self.state = UNTRANSLATED update_checks.send(self.__class__, instance=self, keep_false_positives=True) self.index = self.store.max_index() + 1
def _callback_handler(sender, updated, **kwargs): bulk_pootle = bulk_operations( models=( get_user_model(), UserTPScore, UserStoreScore, TPData, TPChecksData, StoreData, StoreChecksData)) with keep_data(signals=(update_revisions, )): with bulk_pootle: @receiver(update_revisions) def handle_update_revisions(**kwargs): updated.revisions = True if updated.checks: update_checks.send( sender.__class__, instance=sender, units=updated.checks, **kwargs) if updated.data: update_data.send( sender.__class__, instance=sender, **kwargs) if updated.scores: update_scores.send( sender.__class__, instance=sender, users=updated.scores, **kwargs) if updated.revisions: update_revisions.send( sender.__class__, instance=sender, keys=["stats", "checks"])
def test_data_store_critical_checks(store0): qc_qs = QualityCheck.objects qc_qs = ( qc_qs.filter(unit__store=store0) .filter(unit__state__gt=UNTRANSLATED) .filter(category=Category.CRITICAL) .exclude(false_positive=True)) check_count = qc_qs.count() assert ( store0.data.critical_checks == check_count) unit = store0.units.exclude( qualitycheck__isnull=True, qualitycheck__name__in=["xmltags", "endpunc"]).first() unit.target = "<foo></bar>;" unit.save() unit_critical = unit.qualitycheck_set.filter( category=Category.CRITICAL).count() assert ( store0.data.critical_checks == check_count + unit_critical) # lets make another unit false positive other_qc = unit.qualitycheck_set.exclude( name="xmltags").filter(category=Category.CRITICAL).first() other_qc.false_positive = True other_qc.save() # trigger refresh update_checks.send( unit.__class__, instance=unit, keep_false_positives=True) update_data.send( unit.store.__class__, instance=unit.store, keep_false_positives=True) assert ( store0.data.critical_checks == check_count + unit_critical - 1)
def _handle_update_stores(sender, updated): @receiver(update_data, sender=sender.__class__) def update_tp_data_handler(**kwargs): updated.tp_data = True update_data.disconnect(update_tp_data_handler, sender=sender.__class__) @receiver(update_scores, sender=sender.__class__) def update_tp_scores_handler(**kwargs): updated.tp_scores = True update_scores.disconnect(update_tp_scores_handler, sender=sender.__class__) if updated.checks: with keep_data(suppress=(Store, ), signals=(update_data, )): @receiver(update_data, sender=Store) def extra_update_data_handler_(**kwargs): updated.data = updated.data or {} updated.data[kwargs["instance"].id] = kwargs["instance"] with bulk_operations(QualityCheck): for to_check in updated.checks.values(): store = to_check["store"] units = ([unit for unit in to_check["units"]] if to_check["units"] else None) update_checks.send(store.__class__, instance=store, units=units) if updated.data: stores = updated.data.values() for store in stores: update_data.send(Store, instance=store) if updated.score_stores: for store in updated.score_stores.values(): update_scores.send(store.__class__, instance=store, users=updated.score_users)