{"action":"created","comment":{"url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/comments/86350865","pull_request_review_id":7013119,"id":86350865,"diff_hunk":"@@ -178,130 +50,79 @@ def validate(self, post_data):\n             # Not a validation location, so can't be valid\n             return False\n \n-    def update_node_answers(self, node):\n-        answer_dict = {}\n-        for answer in self.state.get_answers():\n-            answer_value = answer.other if answer.value == 'other' and answer.other else answer.value\n-            answer_dict[answer.id] = answer_value\n-        node.answers = answer_dict\n-\n     def validate_all_answers(self):\n-        node = self._first\n-        valid = True\n \n-        while node:\n-            self.build_state(node, node.answers)\n-            if self.state:\n-                self._conditional_display(self.state)\n-                is_valid = self.state.schema_item.validate(self.state)\n-                if not is_valid:\n-                    location = node.item_id\n-                    logger.debug(\"Failed validation with current location %s\", location)\n-                    # if one of the blocks isn't valid\n-                    # then move the current pointer to that block so that the user is redirected to that page\n-                    self.go_to_node(location)\n-                    break\n-\n-                logger.debug(\"Next node is %s\", node.item_id)\n-\n-            node = node.next\n-        return valid\n-\n-    def go_to(self, location):\n-        if self._current:\n-            logger.debug(\"Attempting to go to location %s with current location as %s\", location, self._current.item_id)\n-        if location == 'previous':\n-            location = self.navigator.get_previous_location(self.get_answers(), current_location_id=location)\n-        elif location == 'summary' and self._current.item_id != 'summary':\n-            metadata = get_metadata(current_user)\n-            if metadata:\n-                logger.warning(\"User with tx_id %s tried to submit in an invalid state\", metadata[\"tx_id\"])\n-            raise InvalidLocationException()\n-        self.go_to_node(location)\n-\n-    def is_known_node(self, location):\n-        node = self._tail\n-        while node:\n-            if node.item_id == location:\n-                return True\n-            node = node.previous\n-        return False\n+        for location in self.navigator.get_location_path(get_answers(current_user)):\n+            is_valid = self.validate(location, get_answers(current_user))\n+\n+            if not is_valid:\n+                logger.debug(\"Failed validation with current location %s\", location)\n+                return False, location\n \n-    def process_incoming_answers(self, location, post_data, replay=False):\n-        logger.debug(\"QuestionnaireManager first %s\", self._first)\n-        logger.debug(\"QuestionnaireManager current %s\", self._current)\n-        logger.debug(\"QuestionnaireManager tail %s\", self._tail)\n+        return True, None\n+\n+    def process_incoming_answers(self, location, post_data):\n         logger.debug(\"Processing post data for %s\", location)\n-        # ensure we're in the correct location\n-\n-        if self.is_known_node(location):\n-            self.go_to_node(location)\n-\n-            # process incoming post data\n-            user_action = self._get_user_action(post_data)\n-\n-            # updated node\n-            self.update_node(location, post_data)\n-            is_valid = self.validate(post_data)\n-            # run the validator to update the validation_store\n-            if is_valid:\n-\n-                # process the user action\n-                try:\n-                    user_action_processor = UserActionProcessor(self._schema, self)\n-                    user_action_processor.process_action(user_action)\n-\n-                    # do any routing\n-                    next_location = self.navigator.get_next_location(self.get_answers(), location)\n-                    logger.info(\"next location after routing is %s\", next_location)\n-\n-                    # go to that location\n-                    self.go_to_node(next_location)\n-                    logger.debug(\"Going to location %s\", next_location)\n-                except UserActionProcessorException as e:\n-                    logger.error(\"Error processing user actions\")\n-                    logger.exception(e)\n-            else:\n-                # bug fix for using back button which then fails validation\n-                self.go_to_node(self.get_current_location())\n \n-            # now return the location\n-            current_location = self.get_current_location()\n-            logger.debug(\"Returning location %s\", current_location)\n-            return is_valid\n-        else:\n-            raise InvalidLocationException()\n+        # process incoming post data\n+        user_action = self._get_user_action(post_data)\n+\n+        is_valid = self.validate(location, post_data)\n+        # run the validator to update the validation_store\n+        if is_valid:\n+\n+            # Store answers in QuestionnaireStore\n+            questionnaire_store = get_questionnaire_store(current_user.user_id, current_user.user_ik)\n+\n+            if location not in questionnaire_store.visited_blocks:\n+                questionnaire_store.visited_blocks.append(location)\n+\n+            questionnaire_store.save()\n+\n+            # process the user action\n+            try:\n+                user_action_processor = UserActionProcessor(self._schema, self)\n+                user_action_processor.process_action(user_action)\n+\n+            except UserActionProcessorException as e:\n+                logger.error(\"Error processing user actions\")\n+                logger.exception(e)\n+                return False, e.next_location\n+\n+        return is_valid, None\n \n     def get_rendering_context(self, location, is_valid=True):\n-        node = self._current\n-        state_items = []\n+\n         if is_valid:\n             if location == 'summary':\n                 return self.get_summary_rendering_context()\n             else:\n-                self.build_state(node, node.answers)\n+                # apply page answers?\n+                self.build_state(location, get_answers(current_user))\n \n         if self.state:\n             self._plumbing_preprocessing(self.state)\n             self._conditional_display(self.state)\n \n-        if self.state not in state_items:\n-            state_items.append(self.state)\n+        previous_location = self.navigator.get_previous_location(get_answers(current_user), location)\n \n         # look up the preprocessor and then build the view data\n-        return build_questionnaire_model(self._json, state_items)\n+        return build_questionnaire_model(self._json, [self.state], previous_location)","path":"app/questionnaire/questionnaire_manager.py","position":327,"original_position":327,"commit_id":"1a6cfa976d7ba45c1d4012f28df3d175a4f7d991","original_commit_id":"c76eb970e24af6af69f89733c6da7b909a11d0c3","user":{"login":"jonnyshaw89","id":7594012,"avatar_url":"https://avatars.githubusercontent.com/u/7594012?v=3","gravatar_id":"","url":"https://api.github.com/users/jonnyshaw89","html_url":"https://github.com/jonnyshaw89","followers_url":"https://api.github.com/users/jonnyshaw89/followers","following_url":"https://api.github.com/users/jonnyshaw89/following{/other_user}","gists_url":"https://api.github.com/users/jonnyshaw89/gists{/gist_id}","starred_url":"https://api.github.com/users/jonnyshaw89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonnyshaw89/subscriptions","organizations_url":"https://api.github.com/users/jonnyshaw89/orgs","repos_url":"https://api.github.com/users/jonnyshaw89/repos","events_url":"https://api.github.com/users/jonnyshaw89/events{/privacy}","received_events_url":"https://api.github.com/users/jonnyshaw89/received_events","type":"User","site_admin":false},"body":"Yes i can now. i left it like that as it was being used for summary, but now isn't so ill update that.","created_at":"2016-11-03T14:13:15Z","updated_at":"2016-11-03T14:13:15Z","html_url":"https://github.com/ONSdigital/eq-survey-runner/pull/534#discussion_r86350865","pull_request_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534","_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/comments/86350865"},"html":{"href":"https://github.com/ONSdigital/eq-survey-runner/pull/534#discussion_r86350865"},"pull_request":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534"}}},"pull_request":{"url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534","id":91770197,"html_url":"https://github.com/ONSdigital/eq-survey-runner/pull/534","diff_url":"https://github.com/ONSdigital/eq-survey-runner/pull/534.diff","patch_url":"https://github.com/ONSdigital/eq-survey-runner/pull/534.patch","issue_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/534","number":534,"state":"open","locked":false,"title":"Remove linked list from questionnaire manager","user":{"login":"jonnyshaw89","id":7594012,"avatar_url":"https://avatars.githubusercontent.com/u/7594012?v=3","gravatar_id":"","url":"https://api.github.com/users/jonnyshaw89","html_url":"https://github.com/jonnyshaw89","followers_url":"https://api.github.com/users/jonnyshaw89/followers","following_url":"https://api.github.com/users/jonnyshaw89/following{/other_user}","gists_url":"https://api.github.com/users/jonnyshaw89/gists{/gist_id}","starred_url":"https://api.github.com/users/jonnyshaw89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonnyshaw89/subscriptions","organizations_url":"https://api.github.com/users/jonnyshaw89/orgs","repos_url":"https://api.github.com/users/jonnyshaw89/repos","events_url":"https://api.github.com/users/jonnyshaw89/events{/privacy}","received_events_url":"https://api.github.com/users/jonnyshaw89/received_events","type":"User","site_admin":false},"body":"### What is the context of this PR?\r\nThis is the final change to remove the state storage and pickling from the system to enable more flexibility in software upgrades/changes and more robust data handling.\r\n\r\n### How to review \r\n - No reference to the linked list in the system anymore\r\n - JSON pickle is no longer a dependency\r\n - Answers are stored via QuestionnaireStore as simple JSON/text (not pickled).","created_at":"2016-11-01T11:46:51Z","updated_at":"2016-11-03T14:13:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b7c3075cc40481c41e69e3744c8b89b3d3e4af70","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534/commits","review_comments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534/comments","review_comment_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/534/comments","statuses_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/statuses/1a6cfa976d7ba45c1d4012f28df3d175a4f7d991","head":{"label":"ONSdigital:remove-linked-list-from-questionnaire-manager-2","ref":"remove-linked-list-from-questionnaire-manager-2","sha":"1a6cfa976d7ba45c1d4012f28df3d175a4f7d991","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":49205589,"name":"eq-survey-runner","full_name":"ONSdigital/eq-survey-runner","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/eq-survey-runner","description":"eQ Survey Runner","fork":false,"url":"https://api.github.com/repos/ONSdigital/eq-survey-runner","forks_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/forks","keys_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/teams","hooks_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/events","assignees_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/tags","blobs_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/subscription","commits_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/merges","archive_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/downloads","issues_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/deployments","created_at":"2016-01-07T13:15:26Z","updated_at":"2016-10-26T10:04:59Z","pushed_at":"2016-11-03T12:26:58Z","git_url":"git://github.com/ONSdigital/eq-survey-runner.git","ssh_url":"git@github.com:ONSdigital/eq-survey-runner.git","clone_url":"https://github.com/ONSdigital/eq-survey-runner.git","svn_url":"https://github.com/ONSdigital/eq-survey-runner","homepage":null,"size":7761,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":13,"forks":2,"open_issues":13,"watchers":4,"default_branch":"master"}},"base":{"label":"ONSdigital:master","ref":"master","sha":"9b17e8851f9a956c8137d697c67ae15f2a0c6b49","user":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"repo":{"id":49205589,"name":"eq-survey-runner","full_name":"ONSdigital/eq-survey-runner","owner":{"login":"ONSdigital","id":6865137,"avatar_url":"https://avatars.githubusercontent.com/u/6865137?v=3","gravatar_id":"","url":"https://api.github.com/users/ONSdigital","html_url":"https://github.com/ONSdigital","followers_url":"https://api.github.com/users/ONSdigital/followers","following_url":"https://api.github.com/users/ONSdigital/following{/other_user}","gists_url":"https://api.github.com/users/ONSdigital/gists{/gist_id}","starred_url":"https://api.github.com/users/ONSdigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ONSdigital/subscriptions","organizations_url":"https://api.github.com/users/ONSdigital/orgs","repos_url":"https://api.github.com/users/ONSdigital/repos","events_url":"https://api.github.com/users/ONSdigital/events{/privacy}","received_events_url":"https://api.github.com/users/ONSdigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ONSdigital/eq-survey-runner","description":"eQ Survey Runner","fork":false,"url":"https://api.github.com/repos/ONSdigital/eq-survey-runner","forks_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/forks","keys_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/teams","hooks_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/hooks","issue_events_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/events{/number}","events_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/events","assignees_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/assignees{/user}","branches_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/branches{/branch}","tags_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/tags","blobs_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/refs{/sha}","trees_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/statuses/{sha}","languages_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/languages","stargazers_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/stargazers","contributors_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/contributors","subscribers_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/subscribers","subscription_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/subscription","commits_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/commits{/sha}","git_commits_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/git/commits{/sha}","comments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/comments{/number}","issue_comment_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/comments{/number}","contents_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/contents/{+path}","compare_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/merges","archive_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/downloads","issues_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues{/number}","pulls_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls{/number}","milestones_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/milestones{/number}","notifications_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/labels{/name}","releases_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/releases{/id}","deployments_url":"https://api.github.com/repos/ONSdigital/eq-survey-runner/deployments","created_at":"2016-01-07T13:15:26Z","updated_at":"2016-10-26T10:04:59Z","pushed_at":"2016-11-03T12:26:58Z","git_url":"git://github.com/ONSdigital/eq-survey-runner.git","ssh_url":"git@github.com:ONSdigital/eq-survey-runner.git","clone_url":"https://github.com/ONSdigital/eq-survey-runner.git","svn_url":"https://github.com/ONSdigital/eq-survey-runner","homepage":null,"size":7761,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":13,"forks":2,"open_issues":13,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534"},"html":{"href":"https://github.com/ONSdigital/eq-survey-runner/pull/534"},"issue":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/534"},"comments":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/issues/534/comments"},"review_comments":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534/comments"},"review_comment":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/pulls/534/commits"},"statuses":{"href":"https://api.github.com/repos/ONSdigital/eq-survey-runner/statuses/1a6cfa976d7ba45c1d4012f28df3d175a4f7d991"}}}}
{"actor":{"display_login":"jonnyshaw89"}}