Beispiel #1
0
 def save_subs(self, subs):
     if not subs:
         return
     self.unit.submission_set.bulk_create(subs)
     update_scores.send(self.unit.store.__class__,
                        instance=self.unit.store,
                        users=[sub.submitter_id for sub in subs])
Beispiel #2
0
def handle_store_score_updated(**kwargs):
    tp = kwargs["instance"].store.translation_project
    update_scores.send(
        tp.__class__,
        instance=tp,
        users=[kwargs["instance"].user_id],
        date=kwargs["instance"].date)
Beispiel #3
0
 def update(self, users=None):
     updated = super(StoreScoreUpdater, self).update(users=users)
     if updated:
         update_scores.send(self.store.translation_project.__class__,
                            instance=self.store.translation_project,
                            users=set([x.user_id for x in updated]))
     return updated
Beispiel #4
0
def _callback_handler(sender, updated, **kwargs):

    bulk_tps = bulk_operations(models=(get_user_model(), UserTPScore, TPData,
                                       TPChecksData))
    with keep_data(signals=(update_revisions, )):

        @receiver(update_revisions)
        def update_revisions_handler(**kwargs):
            if updated.revisions is None:
                updated.revisions = set()
            instance = kwargs.get("instance")
            if isinstance(instance, Store):
                updated.revisions.add(kwargs["instance"].parent.pootle_path)
            elif isinstance(instance, Directory):
                updated.revisions.add(kwargs["instance"].pootle_path)

        with bulk_tps:
            _update_stores(sender, updated)

            if updated.tp_data:
                update_data.send(sender.__class__, instance=sender)
            if updated.tp_scores:
                update_scores.send(sender.__class__,
                                   instance=sender,
                                   users=updated.score_users)
    if updated.revisions:
        update_revisions.send(Directory,
                              paths=updated.revisions,
                              keys=["stats", "checks"])
Beispiel #5
0
 def update_scores(self, objects):
     users = (
         set(user
             for user
             in objects.values_list("user_id", flat=True))
         if not isinstance(objects, list)
         else set(x.user_id for x in objects))
     update_scores.send(
         get_user_model(),
         users=users)
Beispiel #6
0
def handle_submission_added(**kwargs):
    submission = kwargs["instance"]
    is_system_user = (
        submission.submitter
        == get_user_model().objects.get_system_user())
    if is_system_user:
        return
    update_scores.send(
        submission.unit.store.__class__,
        instance=submission.unit.store)
Beispiel #7
0
def handle_submission_added(**kwargs):
    submission = kwargs["instance"]
    is_system_user = (
        submission.submitter == get_user_model().objects.get_system_user())
    if is_system_user:
        return
    update_scores.send(submission.unit.store.__class__,
                       instance=submission.unit.store,
                       users=[submission.submitter_id],
                       date=localdate(submission.creation_time))
Beispiel #8
0
def handle_suggestion_change(**kwargs):
    suggestion = kwargs["instance"]
    is_system_user = (
        (suggestion.state.name == "pending"
         and (suggestion.user
              == get_user_model().objects.get_system_user()))
        or (suggestion.state.name != "pending"
            and (suggestion.reviewer
                 == get_user_model().objects.get_system_user())))
    if is_system_user:
        return
    update_scores.send(
        suggestion.unit.store.__class__,
        instance=suggestion.unit.store)
Beispiel #9
0
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)
Beispiel #10
0
 def update_scores(self, objects):
     users = set()
     stores = {}
     tps = {}
     for score in objects:
         users.add(score.user_id)
         if score.store_id not in stores:
             stores[score.store_id] = score.store
     for store in stores.values():
         if store.translation_project_id not in tps:
             tps[store.translation_project_id] = store.translation_project
             tp = store.translation_project
             update_scores.send(tp.__class__,
                                instance=tp,
                                stores=stores.values(),
                                users=users)
Beispiel #11
0
 def update_scores(self, objects):
     users = set()
     stores = {}
     tps = {}
     for score in objects:
         users.add(score.user_id)
         if score.store_id not in stores:
             stores[score.store_id] = score.store
     for store in stores.values():
         if store.translation_project_id not in tps:
             tps[store.translation_project_id] = store.translation_project
             tp = store.translation_project
             update_scores.send(
                 tp.__class__,
                 instance=tp,
                 stores=stores.values(),
                 users=users)
Beispiel #12
0
 def update_scores(self, objects):
     tps = {}
     if not isinstance(objects, list):
         scores = objects.select_related("user", "store",
                                         "store__translation_project")
     else:
         scores = objects
     for score in scores:
         tp = score.store.translation_project
         tps[tp.id] = tps.get(tp.id, dict(tp=tp, stores=[], users=[]))
         tps[tp.id]["stores"].append(score.store)
         tps[tp.id]["users"].append(score.user)
     for tp in tps.values():
         update_scores.send(tp["tp"].__class__,
                            instance=tp["tp"],
                            stores=tp["stores"],
                            users=tp["users"])
Beispiel #13
0
 def handle(self, **options):
     users = (list(get_user_model().objects.filter(
         username__in=options["users"]).values_list("pk", flat=True))
              if options["users"] else None)
     if options["reset"]:
         score_updater.get(get_user_model())(users=users).clear()
         return
     for tp in TranslationProject.objects.all():
         data_update = update_data_after(tp,
                                         signals=(update_scores, ),
                                         suppress=(tp.__class__, ),
                                         kwargs=dict(users=users))
         with data_update:
             for store in tp.stores.all():
                 update_scores.send(store.__class__,
                                    instance=store,
                                    users=users)
Beispiel #14
0
def handle_suggestion_change(**kwargs):
    suggestion = kwargs["instance"]
    is_system_user = (
        (suggestion.state.name == "pending"
         and (suggestion.user
              == get_user_model().objects.get_system_user()))
        or (suggestion.state.name != "pending"
            and (suggestion.reviewer
                 == get_user_model().objects.get_system_user())))
    if is_system_user:
        return
    update_scores.send(
        suggestion.unit.store.__class__,
        instance=suggestion.unit.store,
        users=[
            suggestion.user.id
            if suggestion.state.name == "pending"
            else suggestion.reviewer_id])
Beispiel #15
0
 def update_scores(self, objects):
     tps = {}
     if not isinstance(objects, list):
         scores = objects.select_related(
             "user", "store", "store__translation_project")
     else:
         scores = objects
     for score in scores:
         tp = score.store.translation_project
         tps[tp.id] = tps.get(tp.id, dict(tp=tp, stores=[], users=[]))
         tps[tp.id]["stores"].append(score.store)
         tps[tp.id]["users"].append(score.user)
     for tp in tps.values():
         update_scores.send(
             tp["tp"].__class__,
             instance=tp["tp"],
             stores=tp["stores"],
             users=tp["users"])
Beispiel #16
0
def handle_suggestion_change(**kwargs):
    suggestion = kwargs["instance"]
    is_system_user = (
        (suggestion.is_pending and
         (suggestion.user_id == get_user_model().objects.get_system_user().id))
        or (not suggestion.is_pending and
            (suggestion.reviewer_id
             == get_user_model().objects.get_system_user().id)))
    if is_system_user:
        return
    change_date = (suggestion.review_time
                   if not suggestion.is_pending else suggestion.creation_time)
    update_scores.send(suggestion.unit.store.__class__,
                       instance=suggestion.unit.store,
                       users=[
                           suggestion.user_id
                           if suggestion.is_pending else suggestion.reviewer_id
                       ],
                       date=localdate(change_date))
Beispiel #17
0
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"])
Beispiel #18
0
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)
Beispiel #19
0
def handle_suggestion_change(**kwargs):
    suggestion = kwargs["instance"]
    is_system_user = (
        (suggestion.is_pending
         and (suggestion.user_id
              == get_user_model().objects.get_system_user().id))
        or (not suggestion.is_pending
            and (suggestion.reviewer_id
                 == get_user_model().objects.get_system_user().id)))
    if is_system_user:
        return
    change_date = (
        suggestion.review_time.date()
        if not suggestion.is_pending
        else suggestion.creation_time.date())
    update_scores.send(
        suggestion.unit.store.__class__,
        instance=suggestion.unit.store,
        users=[
            suggestion.user_id
            if suggestion.is_pending
            else suggestion.reviewer_id],
        date=change_date)
Beispiel #20
0
def scan_languages(**kwargs):
    instance = kwargs["instance"]
    created = kwargs.get("created", False)
    raw = kwargs.get("raw", False)

    if not created or raw or instance.disabled:
        return

    if not instance.filetypes.all().exists():
        instance.filetypes.add(Format.objects.get(name="po"))

    if instance.treestyle == 'pootle_fs':
        return

    for language in Language.objects.iterator():
        with keep_data():
            tp = create_translation_project(language, instance)
        if tp is not None:
            with keep_data(tp, suppress=(tp.__class__, )):
                result = tp.update_from_disk()
                if result:
                    update_data.send(tp.__class__, instance=tp)
                    update_scores.send(tp.__class__, instance=tp)
Beispiel #21
0
def _callback_handler(sender, updated, **kwargs):

    bulk_tps = bulk_operations(
        models=(
            get_user_model(),
            UserTPScore,
            TPData,
            TPChecksData))
    with keep_data(signals=(update_revisions, )):

        @receiver(update_revisions)
        def update_revisions_handler(**kwargs):
            if updated.revisions is None:
                updated.revisions = set()
            instance = kwargs.get("instance")
            if isinstance(instance, Store):
                updated.revisions.add(kwargs["instance"].parent.pootle_path)
            elif isinstance(instance, Directory):
                updated.revisions.add(kwargs["instance"].pootle_path)

        with bulk_tps:
            _update_stores(sender, updated)

            if updated.tp_data:
                update_data.send(
                    sender.__class__,
                    instance=sender)
            if updated.tp_scores:
                update_scores.send(
                    sender.__class__,
                    instance=sender,
                    users=updated.score_users)
    if updated.revisions:
        update_revisions.send(
            Directory,
            paths=updated.revisions,
            keys=["stats", "checks"])
Beispiel #22
0
 def update(self, users=None):
     updated = super(TPScoreUpdater, self).update(users=users)
     if updated:
         update_scores.send(get_user_model(),
                            users=set([x.user_id for x in updated]))
     return updated
Beispiel #23
0
 def update(self):
     super(StoreScoreUpdater, self).update()
     update_scores.send(
         self.store.translation_project.__class__,
         instance=self.store.translation_project)
Beispiel #24
0
 def update_scores(self, objects):
     update_scores.send(get_user_model(),
                        users=set(score.user_id for score in objects))
Beispiel #25
0
 def update_scores(self, objects):
     update_scores.send(
         get_user_model(),
         users=set(score.user_id for score in objects))
Beispiel #26
0
def handle_store_score_updated(**kwargs):
    tp = kwargs["instance"].store.translation_project
    update_scores.send(tp.__class__,
                       instance=tp,
                       users=[kwargs["instance"].user_id],
                       date=kwargs["instance"].date)