{"action":"created","comment":{"url":"https://api.github.com/repos/translate/pootle/pulls/comments/46845522","id":46845522,"diff_hunk":"@@ -0,0 +1,133 @@\n+# -*- coding: utf-8 -*-\n+#\n+# Copyright (C) Pootle contributors.\n+#\n+# This file is a part of the Pootle project. It is distributed under the GPL3\n+# or later license. See the LICENSE file for a copy of the license and the\n+# AUTHORS file for copyright and authorship information.\n+\n+from django.db.models.signals import post_save, pre_save\n+from django.dispatch import receiver\n+\n+from pootle_store.models import Unit\n+from pootle_store.util import OBSOLETE\n+\n+from .models import VirtualFolder, VirtualFolderTreeItem\n+from .signals import vfolder_post_save\n+\n+\n+def update_vfolder_tree(vf, store):\n+    # Create missing VirtualFolderTreeItem tree structure after\n+    # adding this new unit.\n+    vfolder_treeitem, created = (\n+        VirtualFolderTreeItem.objects.get_or_create(\n+            directory=store.parent, vfolder=vf))\n+\n+    if not created:\n+        # The VirtualFolderTreeItem already existed, so\n+        # calculate again the stats up to the root.\n+        vfolder_treeitem.update_all_cache()\n+\n+\n+def add_unit_to_vfolders(unit):\n+    pootle_path = unit.store.pootle_path\n+\n+    for vf in VirtualFolder.objects.iterator():\n+        unit_added = False\n+        for location in vf.all_locations:\n+            if not pootle_path.startswith(location):\n+                continue\n+\n+            for filename in vf.filter_rules.split(\",\"):\n+                if pootle_path == \"\".join([location, filename]):\n+                    vf.units.add(unit)\n+                    unit_added = True\n+                    break\n+\n+            if unit_added:\n+                break\n+\n+        if unit_added:\n+            update_vfolder_tree(vf, unit.store)\n+\n+\n+@receiver(pre_save, sender=VirtualFolder)\n+def vfolder_unit_priority_presave_handler(sender, instance, **kwargs):\n+\n+    if instance.id is None:\n+        return\n+\n+    original = VirtualFolder.objects.get(pk=instance.pk)\n+\n+    original_locations = set()\n+    new_locations = set()\n+\n+    for location in original.all_locations:\n+        for filename in original.filter_rules.split(\",\"):\n+            original_locations.add(\"\".join([location, filename]))\n+\n+    for location in instance.all_locations:\n+        for filename in instance.filter_rules.split(\",\"):\n+            new_locations.add(\"\".join([location, filename]))\n+\n+    removed_locations = original_locations - new_locations\n+\n+    stores_affected = set()\n+    for location in removed_locations:\n+        # reindex these units without this vfolder\n+        removed_units = (\n+            Unit.objects.filter(store__pootle_path__startswith=location,\n+                                vfolders=original))\n+        for unit in removed_units.iterator():\n+            unit.vfolders.remove(original)\n+            unit.set_priority()\n+            stores_affected.add(unit.store)\n+\n+    for store in stores_affected:\n+        update_vfolder_tree(original, store)\n+\n+\n+@receiver(vfolder_post_save, sender=VirtualFolder)\n+def vfolder_unit_priority_handler(sender, instance, **kwargs):\n+\n+    for unit in instance.units.all():\n+        unit.set_priority()\n+\n+\n+@receiver(pre_save, sender=Unit)\n+def vfolder_unit_unobsoleted(sender, instance, created=False, **kwargs):\n+    if instance.state == OBSOLETE:","path":"pootle/apps/virtualfolder/receivers.py","position":99,"original_position":99,"commit_id":"1c92a6fd6b0040362b76afcad426c594542195b1","original_commit_id":"1c92a6fd6b0040362b76afcad426c594542195b1","user":{"login":"ta2-1","id":682845,"avatar_url":"https://avatars.githubusercontent.com/u/682845?v=3","gravatar_id":"","url":"https://api.github.com/users/ta2-1","html_url":"https://github.com/ta2-1","followers_url":"https://api.github.com/users/ta2-1/followers","following_url":"https://api.github.com/users/ta2-1/following{/other_user}","gists_url":"https://api.github.com/users/ta2-1/gists{/gist_id}","starred_url":"https://api.github.com/users/ta2-1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ta2-1/subscriptions","organizations_url":"https://api.github.com/users/ta2-1/orgs","repos_url":"https://api.github.com/users/ta2-1/repos","events_url":"https://api.github.com/users/ta2-1/events{/privacy}","received_events_url":"https://api.github.com/users/ta2-1/received_events","type":"User","site_admin":false},"body":"Can we run signal for obsolete unit? Or is it just security check?","created_at":"2015-12-07T16:58:06Z","updated_at":"2015-12-07T16:58:06Z","html_url":"https://github.com/translate/pootle/pull/4264#discussion_r46845522","pull_request_url":"https://api.github.com/repos/translate/pootle/pulls/4264","_links":{"self":{"href":"https://api.github.com/repos/translate/pootle/pulls/comments/46845522"},"html":{"href":"https://github.com/translate/pootle/pull/4264#discussion_r46845522"},"pull_request":{"href":"https://api.github.com/repos/translate/pootle/pulls/4264"}}},"pull_request":{"url":"https://api.github.com/repos/translate/pootle/pulls/4264","id":52443759,"html_url":"https://github.com/translate/pootle/pull/4264","diff_url":"https://github.com/translate/pootle/pull/4264.diff","patch_url":"https://github.com/translate/pootle/pull/4264.patch","issue_url":"https://api.github.com/repos/translate/pootle/issues/4264","number":4264,"state":"open","locked":false,"title":"Add Unit priority field and some fixes/tests for VirtualFolders","user":{"login":"phlax","id":454682,"avatar_url":"https://avatars.githubusercontent.com/u/454682?v=3","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-02T19:41:12Z","updated_at":"2015-12-07T16:58:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aeca7aab2b20185fd93cfdb2886f1ad2be64f3a4","assignee":{"login":"phlax","id":454682,"avatar_url":"https://avatars.githubusercontent.com/u/454682?v=3","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/translate/pootle/milestones/25","html_url":"https://github.com/translate/pootle/milestones/2.7.3-final","labels_url":"https://api.github.com/repos/translate/pootle/milestones/25/labels","id":1436949,"number":25,"title":"2.7.3-final","description":"","creator":{"login":"phlax","id":454682,"avatar_url":"https://avatars.githubusercontent.com/u/454682?v=3","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":13,"state":"open","created_at":"2015-12-01T09:07:40Z","updated_at":"2015-12-07T09:31:01Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/translate/pootle/pulls/4264/commits","review_comments_url":"https://api.github.com/repos/translate/pootle/pulls/4264/comments","review_comment_url":"https://api.github.com/repos/translate/pootle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/translate/pootle/issues/4264/comments","statuses_url":"https://api.github.com/repos/translate/pootle/statuses/1c92a6fd6b0040362b76afcad426c594542195b1","head":{"label":"phlax:unit_priority","ref":"unit_priority","sha":"1c92a6fd6b0040362b76afcad426c594542195b1","user":{"login":"phlax","id":454682,"avatar_url":"https://avatars.githubusercontent.com/u/454682?v=3","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"repo":{"id":39886550,"name":"pootle","full_name":"phlax/pootle","owner":{"login":"phlax","id":454682,"avatar_url":"https://avatars.githubusercontent.com/u/454682?v=3","gravatar_id":"","url":"https://api.github.com/users/phlax","html_url":"https://github.com/phlax","followers_url":"https://api.github.com/users/phlax/followers","following_url":"https://api.github.com/users/phlax/following{/other_user}","gists_url":"https://api.github.com/users/phlax/gists{/gist_id}","starred_url":"https://api.github.com/users/phlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phlax/subscriptions","organizations_url":"https://api.github.com/users/phlax/orgs","repos_url":"https://api.github.com/users/phlax/repos","events_url":"https://api.github.com/users/phlax/events{/privacy}","received_events_url":"https://api.github.com/users/phlax/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phlax/pootle","description":"Online translation tool","fork":true,"url":"https://api.github.com/repos/phlax/pootle","forks_url":"https://api.github.com/repos/phlax/pootle/forks","keys_url":"https://api.github.com/repos/phlax/pootle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phlax/pootle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phlax/pootle/teams","hooks_url":"https://api.github.com/repos/phlax/pootle/hooks","issue_events_url":"https://api.github.com/repos/phlax/pootle/issues/events{/number}","events_url":"https://api.github.com/repos/phlax/pootle/events","assignees_url":"https://api.github.com/repos/phlax/pootle/assignees{/user}","branches_url":"https://api.github.com/repos/phlax/pootle/branches{/branch}","tags_url":"https://api.github.com/repos/phlax/pootle/tags","blobs_url":"https://api.github.com/repos/phlax/pootle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phlax/pootle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phlax/pootle/git/refs{/sha}","trees_url":"https://api.github.com/repos/phlax/pootle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phlax/pootle/statuses/{sha}","languages_url":"https://api.github.com/repos/phlax/pootle/languages","stargazers_url":"https://api.github.com/repos/phlax/pootle/stargazers","contributors_url":"https://api.github.com/repos/phlax/pootle/contributors","subscribers_url":"https://api.github.com/repos/phlax/pootle/subscribers","subscription_url":"https://api.github.com/repos/phlax/pootle/subscription","commits_url":"https://api.github.com/repos/phlax/pootle/commits{/sha}","git_commits_url":"https://api.github.com/repos/phlax/pootle/git/commits{/sha}","comments_url":"https://api.github.com/repos/phlax/pootle/comments{/number}","issue_comment_url":"https://api.github.com/repos/phlax/pootle/issues/comments{/number}","contents_url":"https://api.github.com/repos/phlax/pootle/contents/{+path}","compare_url":"https://api.github.com/repos/phlax/pootle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phlax/pootle/merges","archive_url":"https://api.github.com/repos/phlax/pootle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phlax/pootle/downloads","issues_url":"https://api.github.com/repos/phlax/pootle/issues{/number}","pulls_url":"https://api.github.com/repos/phlax/pootle/pulls{/number}","milestones_url":"https://api.github.com/repos/phlax/pootle/milestones{/number}","notifications_url":"https://api.github.com/repos/phlax/pootle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phlax/pootle/labels{/name}","releases_url":"https://api.github.com/repos/phlax/pootle/releases{/id}","created_at":"2015-07-29T10:00:35Z","updated_at":"2015-07-29T10:00:39Z","pushed_at":"2015-12-07T01:24:26Z","git_url":"git://github.com/phlax/pootle.git","ssh_url":"git@github.com:phlax/pootle.git","clone_url":"https://github.com/phlax/pootle.git","svn_url":"https://github.com/phlax/pootle","homepage":"http://pootle.translatehouse.org","size":81558,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"translate:master","ref":"master","sha":"e23878d2de24385f4135e9d8d8b1e65663b175ab","user":{"login":"translate","id":1538178,"avatar_url":"https://avatars.githubusercontent.com/u/1538178?v=3","gravatar_id":"","url":"https://api.github.com/users/translate","html_url":"https://github.com/translate","followers_url":"https://api.github.com/users/translate/followers","following_url":"https://api.github.com/users/translate/following{/other_user}","gists_url":"https://api.github.com/users/translate/gists{/gist_id}","starred_url":"https://api.github.com/users/translate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/translate/subscriptions","organizations_url":"https://api.github.com/users/translate/orgs","repos_url":"https://api.github.com/users/translate/repos","events_url":"https://api.github.com/users/translate/events{/privacy}","received_events_url":"https://api.github.com/users/translate/received_events","type":"Organization","site_admin":false},"repo":{"id":3769702,"name":"pootle","full_name":"translate/pootle","owner":{"login":"translate","id":1538178,"avatar_url":"https://avatars.githubusercontent.com/u/1538178?v=3","gravatar_id":"","url":"https://api.github.com/users/translate","html_url":"https://github.com/translate","followers_url":"https://api.github.com/users/translate/followers","following_url":"https://api.github.com/users/translate/following{/other_user}","gists_url":"https://api.github.com/users/translate/gists{/gist_id}","starred_url":"https://api.github.com/users/translate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/translate/subscriptions","organizations_url":"https://api.github.com/users/translate/orgs","repos_url":"https://api.github.com/users/translate/repos","events_url":"https://api.github.com/users/translate/events{/privacy}","received_events_url":"https://api.github.com/users/translate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/translate/pootle","description":"Online translation tool","fork":false,"url":"https://api.github.com/repos/translate/pootle","forks_url":"https://api.github.com/repos/translate/pootle/forks","keys_url":"https://api.github.com/repos/translate/pootle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/translate/pootle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/translate/pootle/teams","hooks_url":"https://api.github.com/repos/translate/pootle/hooks","issue_events_url":"https://api.github.com/repos/translate/pootle/issues/events{/number}","events_url":"https://api.github.com/repos/translate/pootle/events","assignees_url":"https://api.github.com/repos/translate/pootle/assignees{/user}","branches_url":"https://api.github.com/repos/translate/pootle/branches{/branch}","tags_url":"https://api.github.com/repos/translate/pootle/tags","blobs_url":"https://api.github.com/repos/translate/pootle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/translate/pootle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/translate/pootle/git/refs{/sha}","trees_url":"https://api.github.com/repos/translate/pootle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/translate/pootle/statuses/{sha}","languages_url":"https://api.github.com/repos/translate/pootle/languages","stargazers_url":"https://api.github.com/repos/translate/pootle/stargazers","contributors_url":"https://api.github.com/repos/translate/pootle/contributors","subscribers_url":"https://api.github.com/repos/translate/pootle/subscribers","subscription_url":"https://api.github.com/repos/translate/pootle/subscription","commits_url":"https://api.github.com/repos/translate/pootle/commits{/sha}","git_commits_url":"https://api.github.com/repos/translate/pootle/git/commits{/sha}","comments_url":"https://api.github.com/repos/translate/pootle/comments{/number}","issue_comment_url":"https://api.github.com/repos/translate/pootle/issues/comments{/number}","contents_url":"https://api.github.com/repos/translate/pootle/contents/{+path}","compare_url":"https://api.github.com/repos/translate/pootle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/translate/pootle/merges","archive_url":"https://api.github.com/repos/translate/pootle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/translate/pootle/downloads","issues_url":"https://api.github.com/repos/translate/pootle/issues{/number}","pulls_url":"https://api.github.com/repos/translate/pootle/pulls{/number}","milestones_url":"https://api.github.com/repos/translate/pootle/milestones{/number}","notifications_url":"https://api.github.com/repos/translate/pootle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/translate/pootle/labels{/name}","releases_url":"https://api.github.com/repos/translate/pootle/releases{/id}","created_at":"2012-03-19T23:06:03Z","updated_at":"2015-12-07T12:10:52Z","pushed_at":"2015-12-07T15:26:04Z","git_url":"git://github.com/translate/pootle.git","ssh_url":"git@github.com:translate/pootle.git","clone_url":"https://github.com/translate/pootle.git","svn_url":"https://github.com/translate/pootle","homepage":"http://pootle.translatehouse.org","size":83138,"stargazers_count":553,"watchers_count":553,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":165,"mirror_url":null,"open_issues_count":262,"forks":165,"open_issues":262,"watchers":553,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/translate/pootle/pulls/4264"},"html":{"href":"https://github.com/translate/pootle/pull/4264"},"issue":{"href":"https://api.github.com/repos/translate/pootle/issues/4264"},"comments":{"href":"https://api.github.com/repos/translate/pootle/issues/4264/comments"},"review_comments":{"href":"https://api.github.com/repos/translate/pootle/pulls/4264/comments"},"review_comment":{"href":"https://api.github.com/repos/translate/pootle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/translate/pootle/pulls/4264/commits"},"statuses":{"href":"https://api.github.com/repos/translate/pootle/statuses/1c92a6fd6b0040362b76afcad426c594542195b1"}}}}