{"action":"created","comment":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/53792501","id":53792501,"diff_hunk":"@@ -0,0 +1,176 @@\n+from django.db.models import Q\n+from mezzanine.pages.page_processors import processor_for\n+from crispy_forms.layout import Layout, HTML\n+\n+from hs_core import page_processors\n+from hs_core.views import add_generic_context\n+from hs_core.views.utils import authorize\n+from hs_core.models import BaseResource\n+from hs_access_control.models import PrivilegeCodes\n+\n+from .models import CollectionResource\n+\n+@processor_for(CollectionResource)\n+def landing_page(request, page):\n+    content_model = page.get_content_model()\n+    edit_resource = page_processors.check_resource_mode(request)\n+\n+    user = request.user\n+    if user.is_authenticated():\n+        # get a list of resources with effective OWNER privilege\n+        owned_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.OWNER)\n+        # get a list of resources with effective CHANGE privilege\n+        editable_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.CHANGE)\n+        # get a list of resources with effective VIEW privilege\n+        viewable_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.VIEW)\n+\n+        owned_resources = list(owned_resources)\n+        editable_resources = list(editable_resources)\n+        viewable_resources = list(viewable_resources)\n+        discovered_resources = list(user.ulabels.my_resources)\n+\n+        user_all_accessible_resource_list = (owned_resources + editable_resources + \\\n+                                             viewable_resources + discovered_resources)\n+    else: # anonymous user\n+        user_all_accessible_resource_list = list(BaseResource.objects. \\\n+                                                 filter(Q(raccess__public=True) | Q(raccess__discoverable=True)).distinct())\n+\n+    collection_items_list = None\n+    collection_items_accessible = []\n+    collection_items_inaccessible = []\n+    if content_model.metadata.collection_items.first():\n+        collection_items_list = list(content_model.metadata.collection_items.first().collection_items.all())\n+        for res in collection_items_list:\n+            if res in user_all_accessible_resource_list or res.raccess.discoverable or res.raccess.public:\n+                collection_items_accessible.append(res)\n+            else:\n+                collection_items_inaccessible.append(res)\n+\n+    if not edit_resource:\n+        # get the context from hs_core\n+        context = page_processors.get_page_context(page, request.user,\n+                                                   resource_edit=edit_resource,\n+                                                   extended_metadata_layout=None,\n+                                                   request=request)\n+        extended_metadata_exists = False\n+\n+        collection_message = \"\"\n+        if collection_items_list is not None:\n+            collection_length = len(collection_items_list)\n+            collection_message = \"This collection holds {0} resource(s) in total. \".format(collection_length)\n+            hide_count = len(collection_items_inaccessible)\n+            if hide_count > 0:\n+                collection_message += \"You have NO permission to view the {} grey resource(s). \\\n+                You may request for permission by leaving a comment.\".format(hide_count)\n+\n+        if collection_items_list is not None:\n+            extended_metadata_exists = True\n+\n+            link_html = \"\"\n+            for res in collection_items_accessible:\n+                sharing_status = get_sharing_status_string(res)\n+                link_html += '<a style=\"color: blue\" href=\"/resource/' + res.short_id + '\" target=\"_blank\">' + \\\n+                             res.resource_type + ' : ' + res.title + ' : ' + sharing_status + ' : ' + \\\n+                             res.short_id + '</a><br/>'\n+            for res in collection_items_inaccessible:\n+                sharing_status = get_sharing_status_string(res)\n+                link_html += '<a style=\"color: grey\" href=\"/resource/' + res.short_id + '\" target=\"_blank\">' + \\","path":"hs_collection_resource/page_processors.py","position":77,"original_position":77,"commit_id":"7f3245a0a9e38862177c362d6a4919e5425c019d","original_commit_id":"7f3245a0a9e38862177c362d6a4919e5425c019d","user":{"login":"zhiyuli","id":10070599,"avatar_url":"https://avatars.githubusercontent.com/u/10070599?v=3","gravatar_id":"","url":"https://api.github.com/users/zhiyuli","html_url":"https://github.com/zhiyuli","followers_url":"https://api.github.com/users/zhiyuli/followers","following_url":"https://api.github.com/users/zhiyuli/following{/other_user}","gists_url":"https://api.github.com/users/zhiyuli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhiyuli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhiyuli/subscriptions","organizations_url":"https://api.github.com/users/zhiyuli/orgs","repos_url":"https://api.github.com/users/zhiyuli/repos","events_url":"https://api.github.com/users/zhiyuli/events{/privacy}","received_events_url":"https://api.github.com/users/zhiyuli/received_events","type":"User","site_admin":false},"body":"@pkdash  we have some unit tests, see hs_collection_resource/tests/test_collection.py. Will update them once we make major changes. thanks","created_at":"2016-02-23T15:11:23Z","updated_at":"2016-02-23T15:11:23Z","html_url":"https://github.com/hydroshare/hydroshare/pull/1000#discussion_r53792501","pull_request_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000","_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/53792501"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/1000#discussion_r53792501"},"pull_request":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000"}}},"pull_request":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000","id":60226071,"html_url":"https://github.com/hydroshare/hydroshare/pull/1000","diff_url":"https://github.com/hydroshare/hydroshare/pull/1000.diff","patch_url":"https://github.com/hydroshare/hydroshare/pull/1000.patch","issue_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000","number":1000,"state":"open","locked":false,"title":"[WIP] 839 collection resource type phase 1","user":{"login":"zhiyuli","id":10070599,"avatar_url":"https://avatars.githubusercontent.com/u/10070599?v=3","gravatar_id":"","url":"https://api.github.com/users/zhiyuli","html_url":"https://github.com/zhiyuli","followers_url":"https://api.github.com/users/zhiyuli/followers","following_url":"https://api.github.com/users/zhiyuli/following{/other_user}","gists_url":"https://api.github.com/users/zhiyuli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhiyuli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhiyuli/subscriptions","organizations_url":"https://api.github.com/users/zhiyuli/orgs","repos_url":"https://api.github.com/users/zhiyuli/repos","events_url":"https://api.github.com/users/zhiyuli/events{/privacy}","received_events_url":"https://api.github.com/users/zhiyuli/received_events","type":"User","site_admin":false},"body":"just sync'd with latest dev; fixed some conflicts due to recent changes to generic templates\r\n\r\n@alvacouch @danames @SarvaPulla \r\nI think we can start to simplify/refactor the collection. I will write some comments on current code explaining what it is doing. \r\n","created_at":"2016-02-22T19:25:14Z","updated_at":"2016-02-23T15:11:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6c4127598c084bba70e496918c40f9f983bd0a3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/commits","review_comments_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/comments","review_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000/comments","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/7f3245a0a9e38862177c362d6a4919e5425c019d","head":{"label":"hydroshare:839-collection-resource-type-phase-1","ref":"839-collection-resource-type-phase-1","sha":"7f3245a0a9e38862177c362d6a4919e5425c019d","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","deployments_url":"https://api.github.com/repos/hydroshare/hydroshare/deployments","created_at":"2014-10-02T02:19:41Z","updated_at":"2016-01-12T14:23:42Z","pushed_at":"2016-02-23T00:32:50Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":70444,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":218,"forks":2,"open_issues":218,"watchers":12,"default_branch":"develop"}},"base":{"label":"hydroshare:develop","ref":"develop","sha":"5677e9e272335206dad44ef8c32ad98c4fc2c524","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","deployments_url":"https://api.github.com/repos/hydroshare/hydroshare/deployments","created_at":"2014-10-02T02:19:41Z","updated_at":"2016-01-12T14:23:42Z","pushed_at":"2016-02-23T00:32:50Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":70444,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":218,"forks":2,"open_issues":218,"watchers":12,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/1000"},"issue":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000"},"comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000/comments"},"review_comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/comments"},"review_comment":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/commits"},"statuses":{"href":"https://api.github.com/repos/hydroshare/hydroshare/statuses/7f3245a0a9e38862177c362d6a4919e5425c019d"}}}}