{"action":"created","comment":{"url":"https://api.github.com/repos/etalab/udata/pulls/comments/51277510","id":51277510,"diff_hunk":"@@ -0,0 +1,80 @@\n+# -*- coding: utf-8 -*-\n+from __future__ import unicode_literals\n+\n+from flask import current_app\n+\n+from udata import theme\n+from udata.api import api, API, output_json\n+from udata.models import db, Dataset, GeoZone\n+\n+oembeds_parser = api.parser()\n+oembeds_parser.add_argument(\n+    'references', help='References of the resources to embed.',\n+    location='args', required=True)\n+\n+\n+@api.route('/oembeds/', endpoint='oembeds')\n+class OEmbedsAPI(API):\n+\n+    @api.doc('oembeds', parser=oembeds_parser)\n+    def get(self):\n+        \"\"\" The returned payload is a list of OEmbed formatted responses.\n+\n+        See: http://oembed.com/\n+\n+        The `references` are composed by a keyword (`kind`) followed by\n+        the `id` each of those separated by commas.\n+        E.g: dataset-5369992aa3a729239d205183,territory-fr-town-75056-comptes\n+\n+        Only datasets and territories are supported for now.\n+        \"\"\"\n+        args = oembeds_parser.parse_args()\n+        references = args['references'].split(',')\n+        result = []\n+        for item_reference in references:\n+            try:\n+                item_kind, item_id = item_reference.split('-', 1)\n+            except ValueError:\n+                return api.abort(400, 'Invalid ID.')\n+            if item_kind == 'dataset':\n+                try:\n+                    item = Dataset.objects.get(id=item_id)\n+                except (db.ValidationError, Dataset.DoesNotExist):\n+                    return api.abort(400, 'Unknown dataset ID.')\n+                template = 'embed-dataset.html'\n+            elif (item_kind == 'territory'\n+                    and current_app.config.get('ACTIVATE_TERRITORIES')):\n+                from udata.models import TERRITORY_DATASETS\n+                try:\n+                    country, town, code, kind = item_id.split('-')\n+                except ValueError:\n+                    return api.abort(400, 'Invalid territory ID.')\n+                try:\n+                    geozone = GeoZone.objects.get(code=code)\n+                except GeoZone.DoesNotExist:\n+                    return api.abort(400, 'Unknown territory identifier.')\n+                if kind in TERRITORY_DATASETS:\n+                    item = TERRITORY_DATASETS[kind](geozone)\n+                else:\n+                    return api.abort(400, 'Unknown kind of territory.')\n+                template = 'embed-dataset.html'\n+            else:\n+                return api.abort(400, 'Invalid object type.')\n+            width = maxwidth = 1000\n+            height = maxheight = 200\n+            html = theme.render(template, **{\n+                'width': width,\n+                'height': height,\n+                'item': item,\n+                'item_reference': item_reference,\n+            })\n+            result.append({\n+                'type': 'rich',\n+                'version': '1.0',\n+                'html': html,\n+                'width': width,\n+                'height': height,\n+                'maxwidth': maxwidth,\n+                'maxheight': maxheight,\n+            })\n+        return output_json(result, 200)","path":"udata/features/oembed/api.py","position":80,"original_position":80,"commit_id":"df1d4b2fe7e94d59b361f452ada2d4e5a1d3941a","original_commit_id":"08489515a531d353a1ed2a56c2249807ae2e169a","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"body":"`marshal_with` also document. But it's not essential here, you are right.","created_at":"2016-01-29T16:01:31Z","updated_at":"2016-01-29T16:01:31Z","html_url":"https://github.com/etalab/udata/pull/285#discussion_r51277510","pull_request_url":"https://api.github.com/repos/etalab/udata/pulls/285","_links":{"self":{"href":"https://api.github.com/repos/etalab/udata/pulls/comments/51277510"},"html":{"href":"https://github.com/etalab/udata/pull/285#discussion_r51277510"},"pull_request":{"href":"https://api.github.com/repos/etalab/udata/pulls/285"}}},"pull_request":{"url":"https://api.github.com/repos/etalab/udata/pulls/285","id":53042968,"html_url":"https://github.com/etalab/udata/pull/285","diff_url":"https://github.com/etalab/udata/pull/285.diff","patch_url":"https://github.com/etalab/udata/pull/285.patch","issue_url":"https://api.github.com/repos/etalab/udata/issues/285","number":285,"state":"open","locked":false,"title":"Introduce territories, fix #284","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"body":"That PR is not ready for a review, it's only a way to document a POC for now.\r\n\r\nAs a citizen, I type my city name within the search field and now a new tab appears:\r\n\r\n![capture d ecran 2015-12-08 a 22 39 01](https://cloud.githubusercontent.com/assets/3556/11669355/93b1b89e-9dfc-11e5-86ea-ad7e4b58b56b.png)\r\n\r\nThe tab appears also on INSEE code and postal codes:\r\n\r\n![capture d ecran 2015-12-08 a 22 40 19](https://cloud.githubusercontent.com/assets/3556/11669379/b158c734-9dfc-11e5-9e96-6e94e891dc9b.png)\r\n\r\nOnce you click that tab, a dynamic page is displayed with a couple of auto-generated links to related data, each card redirecting to external pages/data:\r\n\r\n![capture d ecran 2015-12-11 a 15 34 48](https://cloud.githubusercontent.com/assets/3556/11746165/ea730b16-a01c-11e5-9866-47c07a23ebbf.png)\r\n\r\nNew iteration with typeahead + inclusion of related existing datasets within the displayed list, still completely auto-generated:\r\n\r\n![territoires](https://cloud.githubusercontent.com/assets/3556/11867973/f3254b6a-a4b4-11e5-8f48-394f9ec7a236.gif)\r\n\r\n\r\n","created_at":"2015-12-08T21:42:50Z","updated_at":"2016-01-29T16:01:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15fed68ec8a98788ab4d7c10504536f6f5f1d59b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/etalab/udata/pulls/285/commits","review_comments_url":"https://api.github.com/repos/etalab/udata/pulls/285/comments","review_comment_url":"https://api.github.com/repos/etalab/udata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/etalab/udata/issues/285/comments","statuses_url":"https://api.github.com/repos/etalab/udata/statuses/df1d4b2fe7e94d59b361f452ada2d4e5a1d3941a","head":{"label":"davidbgk:284-introduce-territories","ref":"284-introduce-territories","sha":"df1d4b2fe7e94d59b361f452ada2d4e5a1d3941a","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"repo":{"id":33595552,"name":"udata","full_name":"davidbgk/udata","owner":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidbgk/udata","description":"Social data platform","fork":true,"url":"https://api.github.com/repos/davidbgk/udata","forks_url":"https://api.github.com/repos/davidbgk/udata/forks","keys_url":"https://api.github.com/repos/davidbgk/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidbgk/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidbgk/udata/teams","hooks_url":"https://api.github.com/repos/davidbgk/udata/hooks","issue_events_url":"https://api.github.com/repos/davidbgk/udata/issues/events{/number}","events_url":"https://api.github.com/repos/davidbgk/udata/events","assignees_url":"https://api.github.com/repos/davidbgk/udata/assignees{/user}","branches_url":"https://api.github.com/repos/davidbgk/udata/branches{/branch}","tags_url":"https://api.github.com/repos/davidbgk/udata/tags","blobs_url":"https://api.github.com/repos/davidbgk/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidbgk/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidbgk/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidbgk/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidbgk/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/davidbgk/udata/languages","stargazers_url":"https://api.github.com/repos/davidbgk/udata/stargazers","contributors_url":"https://api.github.com/repos/davidbgk/udata/contributors","subscribers_url":"https://api.github.com/repos/davidbgk/udata/subscribers","subscription_url":"https://api.github.com/repos/davidbgk/udata/subscription","commits_url":"https://api.github.com/repos/davidbgk/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidbgk/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidbgk/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidbgk/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidbgk/udata/contents/{+path}","compare_url":"https://api.github.com/repos/davidbgk/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidbgk/udata/merges","archive_url":"https://api.github.com/repos/davidbgk/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidbgk/udata/downloads","issues_url":"https://api.github.com/repos/davidbgk/udata/issues{/number}","pulls_url":"https://api.github.com/repos/davidbgk/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/davidbgk/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/davidbgk/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidbgk/udata/labels{/name}","releases_url":"https://api.github.com/repos/davidbgk/udata/releases{/id}","deployments_url":"https://api.github.com/repos/davidbgk/udata/deployments","created_at":"2015-04-08T08:51:08Z","updated_at":"2016-01-21T22:06:38Z","pushed_at":"2016-01-29T11:04:31Z","git_url":"git://github.com/davidbgk/udata.git","ssh_url":"git@github.com:davidbgk/udata.git","clone_url":"https://github.com/davidbgk/udata.git","svn_url":"https://github.com/davidbgk/udata","homepage":null,"size":5076,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"etalab:dev","ref":"dev","sha":"967a6aff793fbe7be2c8420a9be54a21ea8e8ebe","user":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"repo":{"id":19141754,"name":"udata","full_name":"etalab/udata","owner":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/etalab/udata","description":"Social data platform","fork":false,"url":"https://api.github.com/repos/etalab/udata","forks_url":"https://api.github.com/repos/etalab/udata/forks","keys_url":"https://api.github.com/repos/etalab/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/etalab/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/etalab/udata/teams","hooks_url":"https://api.github.com/repos/etalab/udata/hooks","issue_events_url":"https://api.github.com/repos/etalab/udata/issues/events{/number}","events_url":"https://api.github.com/repos/etalab/udata/events","assignees_url":"https://api.github.com/repos/etalab/udata/assignees{/user}","branches_url":"https://api.github.com/repos/etalab/udata/branches{/branch}","tags_url":"https://api.github.com/repos/etalab/udata/tags","blobs_url":"https://api.github.com/repos/etalab/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/etalab/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/etalab/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/etalab/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/etalab/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/etalab/udata/languages","stargazers_url":"https://api.github.com/repos/etalab/udata/stargazers","contributors_url":"https://api.github.com/repos/etalab/udata/contributors","subscribers_url":"https://api.github.com/repos/etalab/udata/subscribers","subscription_url":"https://api.github.com/repos/etalab/udata/subscription","commits_url":"https://api.github.com/repos/etalab/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/etalab/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/etalab/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/etalab/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/etalab/udata/contents/{+path}","compare_url":"https://api.github.com/repos/etalab/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/etalab/udata/merges","archive_url":"https://api.github.com/repos/etalab/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/etalab/udata/downloads","issues_url":"https://api.github.com/repos/etalab/udata/issues{/number}","pulls_url":"https://api.github.com/repos/etalab/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/etalab/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/etalab/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/etalab/udata/labels{/name}","releases_url":"https://api.github.com/repos/etalab/udata/releases{/id}","deployments_url":"https://api.github.com/repos/etalab/udata/deployments","created_at":"2014-04-25T09:57:34Z","updated_at":"2016-01-28T19:41:40Z","pushed_at":"2016-01-29T11:04:31Z","git_url":"git://github.com/etalab/udata.git","ssh_url":"git@github.com:etalab/udata.git","clone_url":"https://github.com/etalab/udata.git","svn_url":"https://github.com/etalab/udata","homepage":null,"size":5104,"stargazers_count":25,"watchers_count":25,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":20,"forks":12,"open_issues":20,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/etalab/udata/pulls/285"},"html":{"href":"https://github.com/etalab/udata/pull/285"},"issue":{"href":"https://api.github.com/repos/etalab/udata/issues/285"},"comments":{"href":"https://api.github.com/repos/etalab/udata/issues/285/comments"},"review_comments":{"href":"https://api.github.com/repos/etalab/udata/pulls/285/comments"},"review_comment":{"href":"https://api.github.com/repos/etalab/udata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/etalab/udata/pulls/285/commits"},"statuses":{"href":"https://api.github.com/repos/etalab/udata/statuses/df1d4b2fe7e94d59b361f452ada2d4e5a1d3941a"}}}}