{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/touchforms/pulls/comments/38210841","id":38210841,"diff_hunk":"@@ -31,6 +36,171 @@\n logger = logging.getLogger('formplayer.touchcare')\n \n \n+def get_restore_url(criteria=None):\n+    query_url = '%s?%s' % (settings.RESTORE_URL, urllib.urlencode(criteria))\n+    return query_url\n+\n+\n+class CCInstances(InstanceInitializationFactory):\n+\n+    def __init__(self, sessionvars, auth, restore=None, force_sync=False, form_context=None):\n+        self.vars = sessionvars\n+        self.auth = auth\n+\n+        if settings.USES_SQLITE:\n+            self.username = sessionvars['username']\n+            self.sandbox = SqlSandboxUtils.getStaticStorage(self.username)\n+            self.host = sessionvars['host']\n+            self.domain = sessionvars['domain']\n+            self.query_func = query_factory(self.host, self.domain, self.auth, 'raw')\n+            self.query_url = get_restore_url({'as': self.username + '@' + self.domain, 'version': '2.0'})\n+\n+            if force_sync or self.needs_sync():\n+                self.perform_ota_restore(restore)\n+        else:\n+            self.fixtures = {}\n+            self.form_context = form_context or {}\n+\n+    def clear_tables(self):\n+        db_name = self.username + \".db\"\n+        os.remove(db_name)\n+        self.sandbox = SqlSandboxUtils.getStaticStorage(self.username)\n+\n+    def perform_ota_restore(self, restore=None):\n+        self.clear_tables()\n+        if not restore:\n+            restore_xml = self.get_restore_xml()\n+            ParseUtils.parseXMLIntoSandbox(restore_xml, self.sandbox)\n+        else:\n+            restore_file = restore\n+            ParseUtils.parseFileIntoSandbox(File(restore_file), self.sandbox)\n+        persistence.postgres_set_sqlite(self.username, 1)","path":"touchforms/backend/touchcare.py","position":74,"original_position":73,"commit_id":"ad20d2f612236a6f9545a12560316dc9fa8a7d40","original_commit_id":"85a58c21fafe82f2aeade51062042e088c161d63","user":{"login":"wpride","id":2293064,"avatar_url":"https://avatars.githubusercontent.com/u/2293064?v=3","gravatar_id":"","url":"https://api.github.com/users/wpride","html_url":"https://github.com/wpride","followers_url":"https://api.github.com/users/wpride/followers","following_url":"https://api.github.com/users/wpride/following{/other_user}","gists_url":"https://api.github.com/users/wpride/gists{/gist_id}","starred_url":"https://api.github.com/users/wpride/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpride/subscriptions","organizations_url":"https://api.github.com/users/wpride/orgs","repos_url":"https://api.github.com/users/wpride/repos","events_url":"https://api.github.com/users/wpride/events{/privacy}","received_events_url":"https://api.github.com/users/wpride/received_events","type":"User","site_admin":false},"body":"We're not doing app restores yet so this isn't being used (there is no app version), put the field in for future iterations, but maybe should just remove? ","created_at":"2015-08-28T15:18:54Z","updated_at":"2015-08-28T15:18:54Z","html_url":"https://github.com/dimagi/touchforms/pull/142#discussion_r38210841","pull_request_url":"https://api.github.com/repos/dimagi/touchforms/pulls/142","_links":{"self":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/comments/38210841"},"html":{"href":"https://github.com/dimagi/touchforms/pull/142#discussion_r38210841"},"pull_request":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/142"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/touchforms/pulls/142","id":39971477,"html_url":"https://github.com/dimagi/touchforms/pull/142","diff_url":"https://github.com/dimagi/touchforms/pull/142.diff","patch_url":"https://github.com/dimagi/touchforms/pull/142.patch","issue_url":"https://api.github.com/repos/dimagi/touchforms/issues/142","number":142,"state":"open","locked":false,"title":"Sqlite backend","user":{"login":"wpride","id":2293064,"avatar_url":"https://avatars.githubusercontent.com/u/2293064?v=3","gravatar_id":"","url":"https://api.github.com/users/wpride","html_url":"https://github.com/wpride","followers_url":"https://api.github.com/users/wpride/followers","following_url":"https://api.github.com/users/wpride/following{/other_user}","gists_url":"https://api.github.com/users/wpride/gists{/gist_id}","starred_url":"https://api.github.com/users/wpride/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpride/subscriptions","organizations_url":"https://api.github.com/users/wpride/orgs","repos_url":"https://api.github.com/users/wpride/repos","events_url":"https://api.github.com/users/wpride/events{/privacy}","received_events_url":"https://api.github.com/users/wpride/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-14T22:44:57Z","updated_at":"2015-08-28T15:18:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30d56f27a727461702da0fc55b8a75ad4795ac8f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/touchforms/pulls/142/commits","review_comments_url":"https://api.github.com/repos/dimagi/touchforms/pulls/142/comments","review_comment_url":"https://api.github.com/repos/dimagi/touchforms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/touchforms/issues/142/comments","statuses_url":"https://api.github.com/repos/dimagi/touchforms/statuses/ad20d2f612236a6f9545a12560316dc9fa8a7d40","head":{"label":"dimagi:sqlite-backend","ref":"sqlite-backend","sha":"ad20d2f612236a6f9545a12560316dc9fa8a7d40","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":1330256,"name":"touchforms","full_name":"dimagi/touchforms","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/touchforms","description":"web-based javarosa xforms player built for touchscreen kiosks","fork":false,"url":"https://api.github.com/repos/dimagi/touchforms","forks_url":"https://api.github.com/repos/dimagi/touchforms/forks","keys_url":"https://api.github.com/repos/dimagi/touchforms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/touchforms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/touchforms/teams","hooks_url":"https://api.github.com/repos/dimagi/touchforms/hooks","issue_events_url":"https://api.github.com/repos/dimagi/touchforms/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/touchforms/events","assignees_url":"https://api.github.com/repos/dimagi/touchforms/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/touchforms/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/touchforms/tags","blobs_url":"https://api.github.com/repos/dimagi/touchforms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/touchforms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/touchforms/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/touchforms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/touchforms/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/touchforms/languages","stargazers_url":"https://api.github.com/repos/dimagi/touchforms/stargazers","contributors_url":"https://api.github.com/repos/dimagi/touchforms/contributors","subscribers_url":"https://api.github.com/repos/dimagi/touchforms/subscribers","subscription_url":"https://api.github.com/repos/dimagi/touchforms/subscription","commits_url":"https://api.github.com/repos/dimagi/touchforms/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/touchforms/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/touchforms/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/touchforms/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/touchforms/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/touchforms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/touchforms/merges","archive_url":"https://api.github.com/repos/dimagi/touchforms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/touchforms/downloads","issues_url":"https://api.github.com/repos/dimagi/touchforms/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/touchforms/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/touchforms/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/touchforms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/touchforms/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/touchforms/releases{/id}","created_at":"2011-02-05T01:25:38Z","updated_at":"2015-05-08T15:14:19Z","pushed_at":"2015-08-28T14:49:25Z","git_url":"git://github.com/dimagi/touchforms.git","ssh_url":"git@github.com:dimagi/touchforms.git","clone_url":"https://github.com/dimagi/touchforms.git","svn_url":"https://github.com/dimagi/touchforms","homepage":"","size":34358,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":5,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"5f62b1463d9c50cbc1d3e8dd54f21e32a9145be5","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":1330256,"name":"touchforms","full_name":"dimagi/touchforms","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/touchforms","description":"web-based javarosa xforms player built for touchscreen kiosks","fork":false,"url":"https://api.github.com/repos/dimagi/touchforms","forks_url":"https://api.github.com/repos/dimagi/touchforms/forks","keys_url":"https://api.github.com/repos/dimagi/touchforms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/touchforms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/touchforms/teams","hooks_url":"https://api.github.com/repos/dimagi/touchforms/hooks","issue_events_url":"https://api.github.com/repos/dimagi/touchforms/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/touchforms/events","assignees_url":"https://api.github.com/repos/dimagi/touchforms/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/touchforms/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/touchforms/tags","blobs_url":"https://api.github.com/repos/dimagi/touchforms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/touchforms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/touchforms/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/touchforms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/touchforms/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/touchforms/languages","stargazers_url":"https://api.github.com/repos/dimagi/touchforms/stargazers","contributors_url":"https://api.github.com/repos/dimagi/touchforms/contributors","subscribers_url":"https://api.github.com/repos/dimagi/touchforms/subscribers","subscription_url":"https://api.github.com/repos/dimagi/touchforms/subscription","commits_url":"https://api.github.com/repos/dimagi/touchforms/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/touchforms/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/touchforms/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/touchforms/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/touchforms/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/touchforms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/touchforms/merges","archive_url":"https://api.github.com/repos/dimagi/touchforms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/touchforms/downloads","issues_url":"https://api.github.com/repos/dimagi/touchforms/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/touchforms/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/touchforms/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/touchforms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/touchforms/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/touchforms/releases{/id}","created_at":"2011-02-05T01:25:38Z","updated_at":"2015-05-08T15:14:19Z","pushed_at":"2015-08-28T14:49:25Z","git_url":"git://github.com/dimagi/touchforms.git","ssh_url":"git@github.com:dimagi/touchforms.git","clone_url":"https://github.com/dimagi/touchforms.git","svn_url":"https://github.com/dimagi/touchforms","homepage":"","size":34358,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/142"},"html":{"href":"https://github.com/dimagi/touchforms/pull/142"},"issue":{"href":"https://api.github.com/repos/dimagi/touchforms/issues/142"},"comments":{"href":"https://api.github.com/repos/dimagi/touchforms/issues/142/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/142/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/touchforms/pulls/142/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/touchforms/statuses/ad20d2f612236a6f9545a12560316dc9fa8a7d40"}}}}