{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/comments/25883822","id":25883822,"diff_hunk":"@@ -0,0 +1,66 @@\n+import yaml\n+import inflection\n+import re\n+\n+\n+class Content_loader():\n+\n+    def __init__(self, manifest, content_directory):\n+\n+        section_order = yaml.load(open(manifest, \"r\"))\n+\n+        self.directory = content_directory\n+        self.__question_cache__ = {}\n+        self.sections = [\n+            self.__populate_section__(s) for s in section_order\n+        ]\n+\n+    def get_section(self, requested_section):\n+\n+        for section in self.sections:\n+            if section[\"id\"] == requested_section:\n+                return section\n+\n+    def get_question(self, question):\n+\n+        if question not in self.__question_cache__:\n+\n+            question_content = yaml.load(\n+                open(str(self.directory) + str(question) + \".yml\", \"r\")\n+            )\n+\n+            question_content[\"id\"] = question\n+\n+            # wrong way to do it? question should be shown by default.\n+            question_content[\"depends_on_lots\"] = (\n+                self.__get_dependent_lots__(question_content[\"dependsOnLots\"])\n+            ) if \"dependsOnLots\" in question_content else (\n+                [\"saas\", \"paas\", \"iaas\", \"scs\"]\n+            )","path":"app/main/helpers/content.py","position":39,"original_position":39,"commit_id":"20f5e98df5021281d30a45eebe5c261e86ee7d61","original_commit_id":"20f5e98df5021281d30a45eebe5c261e86ee7d61","user":{"login":"allait","id":246664,"avatar_url":"https://avatars.githubusercontent.com/u/246664?v=3","gravatar_id":"","url":"https://api.github.com/users/allait","html_url":"https://github.com/allait","followers_url":"https://api.github.com/users/allait/followers","following_url":"https://api.github.com/users/allait/following{/other_user}","gists_url":"https://api.github.com/users/allait/gists{/gist_id}","starred_url":"https://api.github.com/users/allait/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allait/subscriptions","organizations_url":"https://api.github.com/users/allait/orgs","repos_url":"https://api.github.com/users/allait/repos","events_url":"https://api.github.com/users/allait/events{/privacy}","received_events_url":"https://api.github.com/users/allait/received_events","type":"User","site_admin":false},"body":"`self._question_cache`","created_at":"2015-03-05T17:40:17Z","updated_at":"2015-03-05T17:40:17Z","html_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7#discussion_r25883822","pull_request_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/comments/25883822"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7#discussion_r25883822"},"pull_request":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7","id":30176605,"html_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7","diff_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7.diff","patch_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7.patch","issue_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/7","number":7,"state":"open","locked":false,"title":"Configuration driven admin app","user":{"login":"quis","id":355079,"avatar_url":"https://avatars.githubusercontent.com/u/355079?v=3","gravatar_id":"","url":"https://api.github.com/users/quis","html_url":"https://github.com/quis","followers_url":"https://api.github.com/users/quis/followers","following_url":"https://api.github.com/users/quis/following{/other_user}","gists_url":"https://api.github.com/users/quis/gists{/gist_id}","starred_url":"https://api.github.com/users/quis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quis/subscriptions","organizations_url":"https://api.github.com/users/quis/orgs","repos_url":"https://api.github.com/users/quis/repos","events_url":"https://api.github.com/users/quis/events{/privacy}","received_events_url":"https://api.github.com/users/quis/received_events","type":"User","site_admin":false},"body":"**TL;DR This handles uploading of documents, but it will let us a build an admin tool that can quickly extend to edit more than documents**\r\n\r\nIt turns this… | …into this | …and this\r\n---|---|---\r\n![image](https://cloud.githubusercontent.com/assets/355079/6415574/d1184a1c-be97-11e4-8bc7-0cdd66980ca2.png) | ![image](https://cloud.githubusercontent.com/assets/355079/6415600/fa44cf64-be97-11e4-8ce8-d4d8fcce0183.png) | ![image](https://cloud.githubusercontent.com/assets/355079/6415606/042bda72-be98-11e4-967e-c1e4df241925.png)\r\n\r\nIn the final screenshot the only hard coded piece of content in the body of the page is the link that says \"Admin home\". Everything else either comes from the [content](https://github.com/alphagov/digital-marketplace-ssp-content) or the [API](https://github.com/alphagov/digitalmarketplace-api).\r\n\r\n## File handling\r\nAt the files are stored to `./temp` when `post`ed to the same endpoint as the editing page.\r\n\r\nIt treats the process of uploading a file as a _validation_, much like checking if a user has inputted service title under 100 characters, or a percentage as just a number.\r\n\r\nIf the validation fails (eg no file is provided or file can't be stored for some reason) then it passes a message to the template on the `errors` object.\r\n\r\nThis is built in such a way that a dictionary of validations is provided in the content, eg:\r\n```yaml\r\nvalidations\r\n  -\r\n    name: is_acceptable_file_size\r\n    message: Your file is too big\r\n  -\r\n    name: is_open_document\r\n    message: That's not an open document format\r\n```\r\n…and then it's up to the app to implement a function called `is_open_document` which returns `True` or `False` when provided `post`ed data.\r\n\r\n## Work in progress\r\n- [x] Render service summary page from YAML file\r\n- [x] Render edit section page from YAML file\r\n- [x] Accept file upload(s)\r\n- [x] Validate file format/size\r\n- [x] Render validation errors back onto the form\r\n- [x] Don't error if a file exists but no new one is uploaded\r\n- [x] Save previous file with timestamp\r\n- [x] Deal with optional questions (e.g. SFIA rate card)\r\n- [x] Don't show a section in the summary if none of the questions are relevant\r\n- [x] Make the tests pass on Python 2 and 3\r\n\r\n## Out of scope\r\n- Rename files with correct supplier/service ID\r\n- Save files to S3, rather than locally\r\n- Add authentication","created_at":"2015-02-27T15:55:00Z","updated_at":"2015-03-05T17:40:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"181caaaf6312c3eee8af70e91f4768d053951726","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7/commits","review_comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7/comments","review_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/7/comments","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/statuses/20f5e98df5021281d30a45eebe5c261e86ee7d61","head":{"label":"alphagov:configuration-driven","ref":"configuration-driven","sha":"20f5e98df5021281d30a45eebe5c261e86ee7d61","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":31009853,"name":"digitalmarketplace-admin-frontend","full_name":"alphagov/digitalmarketplace-admin-frontend","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend","description":"Frontend administration application for the digital marketplace","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/releases{/id}","created_at":"2015-02-19T10:09:45Z","updated_at":"2015-03-05T09:33:27Z","pushed_at":"2015-03-05T17:27:18Z","git_url":"git://github.com/alphagov/digitalmarketplace-admin-frontend.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-admin-frontend.git","clone_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend.git","svn_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend","homepage":"","size":408,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"bddfb9a712dfa21dc143408e3b5499cfb58f3f3e","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":31009853,"name":"digitalmarketplace-admin-frontend","full_name":"alphagov/digitalmarketplace-admin-frontend","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend","description":"Frontend administration application for the digital marketplace","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/releases{/id}","created_at":"2015-02-19T10:09:45Z","updated_at":"2015-03-05T09:33:27Z","pushed_at":"2015-03-05T17:27:18Z","git_url":"git://github.com/alphagov/digitalmarketplace-admin-frontend.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-admin-frontend.git","clone_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend.git","svn_url":"https://github.com/alphagov/digitalmarketplace-admin-frontend","homepage":"","size":408,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-admin-frontend/pull/7"},"issue":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/7"},"comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-admin-frontend/statuses/20f5e98df5021281d30a45eebe5c261e86ee7d61"}}}}