{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/140603317","pull_request_review_id":64706801,"id":140603317,"diff_hunk":"@@ -0,0 +1,129 @@\n+# coding=utf-8\n+\n+from dimagi.ext.couchdbkit import *\n+from corehq.apps.app_manager.models.common import FormActionCondition, IndexedSchema\n+\n+\n+class SchedulePhaseForm(IndexedSchema):\n+    \"\"\"\n+    A reference to a form in a schedule phase.\n+    \"\"\"\n+    from corehq.apps.app_manager.models.common import FormIdProperty\n+    form_id = FormIdProperty(\"modules[*].schedule_phases[*].forms[*].form_id\")\n+\n+\n+class SchedulePhase(IndexedSchema):\n+    \"\"\"\n+    SchedulePhases are attached to a module.\n+    A Schedule Phase is a grouping of forms that occur within a period and share an anchor\n+    A module should not have more than one SchedulePhase with the same anchor\n+\n+    anchor:                     Case property containing a date after which this phase becomes active\n+    forms: \t\t\tThe forms that are to be filled out within this phase\n+    \"\"\"\n+    anchor = StringProperty()\n+    forms = SchemaListProperty(SchedulePhaseForm)\n+\n+    @property\n+    def id(self):\n+        \"\"\" A Schedule Phase is 1-indexed \"\"\"\n+        _id = super(SchedulePhase, self).id\n+        return _id + 1\n+\n+    @property\n+    def phase_id(self):\n+        return \"{}_{}\".format(self.anchor, self.id)\n+\n+    def get_module(self):\n+        return self._parent\n+\n+    _get_forms = IndexedSchema.Getter('forms')\n+\n+    def get_forms(self):\n+        \"\"\"Returns the actual form objects related to this phase\"\"\"\n+        module = self.get_module()\n+        return (module.get_form_by_unique_id(form.form_id) for form in self._get_forms())\n+\n+    def get_form(self, desired_form):\n+        return next((form for form in self.get_forms() if form.unique_id == desired_form.unique_id), None)\n+\n+    def get_phase_form_index(self, form):\n+        \"\"\"\n+        Returns the index of the form with respect to the phase\n+\n+        schedule_phase.forms = [a,b,c]\n+        schedule_phase.get_phase_form_index(b)\n+        => 1\n+        schedule_phase.get_phase_form_index(c)\n+        => 2\n+        \"\"\"\n+        return next((phase_form.id for phase_form in self._get_forms() if phase_form.form_id == form.unique_id),\n+                    None)\n+\n+    def remove_form(self, form):\n+        \"\"\"Remove a form from the phase\"\"\"\n+        idx = self.get_phase_form_index(form)\n+        if idx is None:\n+            raise ScheduleError(\"That form doesn't exist in the phase\")\n+\n+        self.forms.remove(self.forms[idx])\n+\n+    def add_form(self, form):\n+        \"\"\"Adds a form to this phase, removing it from other phases\"\"\"\n+        old_phase = form.get_phase()\n+        if old_phase is not None and old_phase.anchor != self.anchor:\n+            old_phase.remove_form(form)\n+\n+        if self.get_form(form) is None:\n+            self.forms.append(SchedulePhaseForm(form_id=form.unique_id))\n+\n+    def change_anchor(self, new_anchor):\n+        if new_anchor is None or new_anchor.strip() == '':\n+            raise ScheduleError(_(\"You can't create a phase without an anchor property\"))\n+\n+        self.anchor = new_anchor\n+\n+        if self.get_module().phase_anchors.count(new_anchor) > 1:\n+            raise ScheduleError(_(\"You can't have more than one phase with the anchor {}\").format(new_anchor))\n+\n+class ScheduleVisit(IndexedSchema):\n+    \"\"\"\n+    due:         Days after the anchor date that this visit is due\n+    starts:      Days before the due date that this visit is valid from\n+    expires:     Days after the due date that this visit is valid until (optional)\n+\n+    repeats:     Whether this is a repeat visit (one per form allowed)\n+    increment:   Days after the last visit that the repeat visit occurs\n+    \"\"\"\n+    due = IntegerProperty()\n+    starts = IntegerProperty()\n+    expires = IntegerProperty()\n+    repeats = BooleanProperty(default=False)\n+    increment = IntegerProperty()\n+\n+    @property\n+    def id(self):\n+        \"\"\"Visits are 1-based indexed\"\"\"\n+        _id = super(ScheduleVisit, self).id\n+        return _id + 1\n+\n+\n+class FormSchedule(DocumentSchema):","path":"corehq/apps/app_manager/models/schedules.py","position":111,"original_position":111,"commit_id":"15ffd36761f4d7e42fa4eb58a5aa265bd90b4803","original_commit_id":"15ffd36761f4d7e42fa4eb58a5aa265bd90b4803","user":{"login":"stickler-ci","id":16011037,"avatar_url":"https://avatars3.githubusercontent.com/u/16011037?v=4","gravatar_id":"","url":"https://api.github.com/users/stickler-ci","html_url":"https://github.com/stickler-ci","followers_url":"https://api.github.com/users/stickler-ci/followers","following_url":"https://api.github.com/users/stickler-ci/following{/other_user}","gists_url":"https://api.github.com/users/stickler-ci/gists{/gist_id}","starred_url":"https://api.github.com/users/stickler-ci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stickler-ci/subscriptions","organizations_url":"https://api.github.com/users/stickler-ci/orgs","repos_url":"https://api.github.com/users/stickler-ci/repos","events_url":"https://api.github.com/users/stickler-ci/events{/privacy}","received_events_url":"https://api.github.com/users/stickler-ci/received_events","type":"User","site_admin":false},"body":"F405 'DocumentSchema' may be undefined, or defined from star imports: dimagi.ext.couchdbkit","created_at":"2017-09-22T21:44:47Z","updated_at":"2017-09-22T21:44:47Z","html_url":"https://github.com/dimagi/commcare-hq/pull/17933#discussion_r140603317","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/140603317"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/17933#discussion_r140603317"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933","id":142675727,"html_url":"https://github.com/dimagi/commcare-hq/pull/17933","diff_url":"https://github.com/dimagi/commcare-hq/pull/17933.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/17933.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/17933","number":17933,"state":"open","locked":false,"title":"split app manager models","user":{"login":"orangejenny","id":1486591,"avatar_url":"https://avatars1.githubusercontent.com/u/1486591?v=4","gravatar_id":"","url":"https://api.github.com/users/orangejenny","html_url":"https://github.com/orangejenny","followers_url":"https://api.github.com/users/orangejenny/followers","following_url":"https://api.github.com/users/orangejenny/following{/other_user}","gists_url":"https://api.github.com/users/orangejenny/gists{/gist_id}","starred_url":"https://api.github.com/users/orangejenny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orangejenny/subscriptions","organizations_url":"https://api.github.com/users/orangejenny/orgs","repos_url":"https://api.github.com/users/orangejenny/repos","events_url":"https://api.github.com/users/orangejenny/events{/privacy}","received_events_url":"https://api.github.com/users/orangejenny/received_events","type":"User","site_admin":false},"body":"experimental, ignore","created_at":"2017-09-22T21:44:03Z","updated_at":"2017-09-22T21:44:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7a7ede4779bcc87452d43e00ad5ab15e3458d013","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/17933/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/15ffd36761f4d7e42fa4eb58a5aa265bd90b4803","head":{"label":"dimagi:jls/split-app-manager-models","ref":"jls/split-app-manager-models","sha":"15ffd36761f4d7e42fa4eb58a5aa265bd90b4803","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","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":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","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/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2017-09-08T11:11:20Z","pushed_at":"2017-09-22T21:44:03Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"https://www.commcarehq.org","size":422950,"stargazers_count":79,"watchers_count":79,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":56,"forks":94,"open_issues":56,"watchers":79,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"9ecc67303f7ed1d3854ecf38ada31b9594233f38","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","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":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","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/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2017-09-08T11:11:20Z","pushed_at":"2017-09-22T21:44:03Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"https://www.commcarehq.org","size":422950,"stargazers_count":79,"watchers_count":79,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":56,"forks":94,"open_issues":56,"watchers":79,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/17933"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/17933"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/17933/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/17933/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/15ffd36761f4d7e42fa4eb58a5aa265bd90b4803"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"stickler-ci"}}