Exemplo n.º 1
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"])
Exemplo n.º 2
0
def test_view_project_paths(project0, store0, client, request_users):
    user = request_users["user"]
    client.login(username=user.username, password=request_users["password"])
    url = reverse("pootle-project-paths",
                  kwargs=dict(project_code=project0.code))
    response = client.post(url,
                           data=dict(q="tore"),
                           HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    assert response.status_code == 200
    result = json.loads(response.content)
    path_form = PathsSearchForm(context=project0, data=dict(q="tore"))
    assert path_form.is_valid()
    assert result["items"] == path_form.search(show_all=user.is_superuser)
    assert "store0.po" in result["items"]["results"]

    stores = Store.objects.filter(name=store0.name)
    for store in stores:
        store.obsolete = True
        store.save()
        update_revisions.send(store.__class__, instance=store, keys=["stats"])
    response = client.post(url,
                           data=dict(q="tore"),
                           HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    assert response.status_code == 200
    result = json.loads(response.content)
    assert "store0.po" not in result["items"]["results"]
Exemplo n.º 3
0
def test_view_project_paths(project0, store0, client, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    url = reverse(
        "pootle-project-paths",
        kwargs=dict(project_code=project0.code))
    response = client.post(
        url,
        data=dict(q="tore"),
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    assert response.status_code == 200
    result = json.loads(response.content)
    path_form = PathsSearchForm(context=project0, data=dict(q="tore"))
    assert path_form.is_valid()
    assert result["items"] == path_form.search(show_all=user.is_superuser)
    assert "store0.po" in result["items"]["results"]

    stores = Store.objects.filter(name=store0.name)
    for store in stores:
        store.obsolete = True
        store.save()
        update_revisions.send(
            store.__class__,
            instance=store,
            keys=["stats"])
    response = client.post(
        url,
        data=dict(q="tore"),
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    assert response.status_code == 200
    result = json.loads(response.content)
    assert "store0.po" not in result["items"]["results"]
Exemplo n.º 4
0
    def purge(self):
        """Purges user from site reverting any changes that they have made.

        The following steps are taken:
        - Delete units created by user and without other submissions.
        - Revert units edited by user.
        - Revert reviews made by user.
        - Revert unit comments by user.
        - Revert unit state changes by user.
        - Delete any remaining submissions and suggestions.
        - Expire caches for relevant directories
        """

        stores = set()
        with keep_data():
            stores |= self.remove_units_created()
            stores |= self.revert_units_edited()
            stores |= self.revert_units_reviewed()
            stores |= self.revert_units_commented()
            stores |= self.revert_units_state_changed()

            # Delete remaining submissions.
            logger.debug("Deleting remaining submissions for: %s", self.user)
            self.user.submission_set.all().delete()

            # Delete remaining suggestions.
            logger.debug("Deleting remaining suggestions for: %s", self.user)
            self.user.suggestions.all().delete()
        for store in stores:
            update_data.send(store.__class__, instance=store)
        update_revisions.send(
            Directory,
            object_list=Directory.objects.filter(
                id__in=set(store.parent.id for store in stores)))
Exemplo n.º 5
0
def handle_directory_save(**kwargs):
    update_revisions.send(
        Directory,
        instance=(
            kwargs["instance"].parent
            if kwargs.get("created")
            else kwargs["instance"]),
        keys=["stats", "checks"])
Exemplo n.º 6
0
 def update_tps_and_revisions(self, stores):
     tps = {}
     for store in stores:
         if store.translation_project_id not in tps:
             tps[store.translation_project_id] = store.translation_project
         update_revisions.send(store.__class__,
                               instance=store,
                               keys=["stats", "checks"])
     for tp in tps.values():
         update_data.send(tp.__class__, instance=tp)
Exemplo n.º 7
0
 def update_tps_and_revisions(self, stores):
     tps = {}
     for store in stores:
         if store.translation_project_id not in tps:
             tps[store.translation_project_id] = store.translation_project
         update_revisions.send(
             store.__class__,
             instance=store,
             keys=["stats", "checks"])
     for tp in tps.values():
         update_data.send(
             tp.__class__,
             instance=tp)
Exemplo n.º 8
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"])
Exemplo n.º 9
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"])
Exemplo n.º 10
0
def handle_tp_delete(**kwargs):
    update_revisions.send(
        Directory,
        instance=kwargs["instance"].directory,
        keys=["stats", "checks"])
Exemplo n.º 11
0
def config_updated_handler(**kwargs):
    if kwargs["instance"] and kwargs["key"] == "pootle.core.lang_mapping":
        update_revisions.send(
            Project,
            instance=kwargs["instance"],
            keys=["stats"])
Exemplo n.º 12
0
def handle_project_save(**kwargs):
    update_revisions.send(Project,
                          instance=kwargs["instance"],
                          keys=["stats", "checks"])
Exemplo n.º 13
0
def handle_tp_delete(**kwargs):
    update_revisions.send(Directory,
                          instance=kwargs["instance"].directory,
                          keys=["stats", "checks"])
Exemplo n.º 14
0
def handle_directory_save(**kwargs):
    update_revisions.send(
        Directory,
        instance=(kwargs["instance"].parent
                  if kwargs.get("created") else kwargs["instance"]),
        keys=["stats", "checks"])
Exemplo n.º 15
0
def handle_storedata_save(**kwargs):
    update_revisions.send(Store,
                          instance=kwargs["instance"].store,
                          keys=["stats", "checks"])
Exemplo n.º 16
0
def handle_storedata_save(**kwargs):
    update_revisions.send(
        Store,
        instance=kwargs["instance"].store,
        keys=["stats", "checks"])
Exemplo n.º 17
0
def config_updated_handler(**kwargs):
    if kwargs["instance"] and kwargs["key"] == "pootle.core.lang_mapping":
        update_revisions.send(Project,
                              instance=kwargs["instance"],
                              keys=["stats"])