{"action":"created","comment":{"url":"https://api.github.com/repos/indico/indico/pulls/comments/43109376","id":43109376,"diff_hunk":"@@ -0,0 +1,66 @@\n+# This file is part of Indico.\n+# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).\n+#\n+# Indico is free software; you can redistribute it and/or\n+# modify it under the terms of the GNU General Public License as\n+# published by the Free Software Foundation; either version 3 of the\n+# License, or (at your option) any later version.\n+#\n+# Indico is distributed in the hope that it will be useful, but\n+# WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+# General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Indico; if not, see <http://www.gnu.org/licenses/>.\n+\n+from __future__ import unicode_literals\n+\n+from indico.core.db import db\n+from indico.core.db.sqlalchemy.util.models import get_simple_column_attrs\n+from indico.modules.events.registration.models.forms import RegistrationForm\n+from indico.modules.events.registration.models.form_fields import RegistrationFormFieldData\n+from indico.modules.events.registration.models.items import RegistrationFormItem, RegistrationFormSection\n+from indico.util.i18n import _\n+\n+from MaKaC.conference import EventCloner\n+\n+\n+class RegistrationFormCloner(EventCloner):\n+    def get_options(self):\n+        if self.event.getType() != 'conference':\n+            return {}\n+        return {'registration': (_('Registration'), True, False)}\n+\n+    def clone(self, new_event, options):\n+        if 'registration' not in options:\n+            return\n+        attrs = get_simple_column_attrs(RegistrationForm) - {'start_dt', 'end_dt'}\n+        for old_form in self._find_registration_forms():\n+            new_form = RegistrationForm(event_id=new_event.id, **{attr: getattr(old_form, attr) for attr in attrs})\n+            self._clone_form_items(old_form, new_form, new_event)\n+            db.session.add(new_form)\n+            db.session.flush()\n+\n+    def _find_registration_forms(self):\n+        return RegistrationForm.find(~RegistrationForm.is_deleted,\n+                                     RegistrationForm.event_id == int(self.event.id))\n+\n+    def _clone_form_items(self, old_form, new_form, event_new):\n+        old_sections = RegistrationFormSection.find(RegistrationFormSection.registration_form_id == old_form.id,\n+                                                    ~RegistrationFormSection.is_deleted)\n+        section_attrs = get_simple_column_attrs(RegistrationFormSection) - {'registration_form_id'}\n+        for old_section in old_sections:\n+            new_section = RegistrationFormSection(registration_form=new_form, **{attr: getattr(old_section, attr)\n+                                                                                 for attr in section_attrs})\n+            old_section_items = RegistrationFormItem.find(~RegistrationFormItem.is_deleted, parent=old_section)\n+            items_attrs = get_simple_column_attrs(RegistrationFormItem) | {'parent_id'}\n+            for old_item in old_section_items:\n+                new_item = RegistrationFormItem(parent=new_section, registration_form=new_form,\n+                                                **{attr: getattr(old_item, attr) for attr in items_attrs})\n+                field_data = RegistrationFormFieldData(field=new_item, **{attr: getattr(old_item, attr)\n+                                                                          for attr in {'versioned_data'}})","path":"indico/modules/events/registration/clone.py","position":62,"original_position":62,"commit_id":"b6e33e0f592306cefe561785f498af5d01855d9f","original_commit_id":"b6e33e0f592306cefe561785f498af5d01855d9f","user":{"login":"mic4ael","id":3616940,"avatar_url":"https://avatars.githubusercontent.com/u/3616940?v=3","gravatar_id":"","url":"https://api.github.com/users/mic4ael","html_url":"https://github.com/mic4ael","followers_url":"https://api.github.com/users/mic4ael/followers","following_url":"https://api.github.com/users/mic4ael/following{/other_user}","gists_url":"https://api.github.com/users/mic4ael/gists{/gist_id}","starred_url":"https://api.github.com/users/mic4ael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mic4ael/subscriptions","organizations_url":"https://api.github.com/users/mic4ael/orgs","repos_url":"https://api.github.com/users/mic4ael/repos","events_url":"https://api.github.com/users/mic4ael/events{/privacy}","received_events_url":"https://api.github.com/users/mic4ael/received_events","type":"User","site_admin":false},"body":"Haha, :-1: for me.","created_at":"2015-10-27T11:24:10Z","updated_at":"2015-10-27T11:24:10Z","html_url":"https://github.com/indico/indico/pull/2112#discussion_r43109376","pull_request_url":"https://api.github.com/repos/indico/indico/pulls/2112","_links":{"self":{"href":"https://api.github.com/repos/indico/indico/pulls/comments/43109376"},"html":{"href":"https://github.com/indico/indico/pull/2112#discussion_r43109376"},"pull_request":{"href":"https://api.github.com/repos/indico/indico/pulls/2112"}}},"pull_request":{"url":"https://api.github.com/repos/indico/indico/pulls/2112","id":48716424,"html_url":"https://github.com/indico/indico/pull/2112","diff_url":"https://github.com/indico/indico/pull/2112.diff","patch_url":"https://github.com/indico/indico/pull/2112.patch","issue_url":"https://api.github.com/repos/indico/indico/issues/2112","number":2112,"state":"open","locked":false,"title":"RegistrationForm - sender address & places left","user":{"login":"mic4ael","id":3616940,"avatar_url":"https://avatars.githubusercontent.com/u/3616940?v=3","gravatar_id":"","url":"https://api.github.com/users/mic4ael","html_url":"https://github.com/mic4ael","followers_url":"https://api.github.com/users/mic4ael/followers","following_url":"https://api.github.com/users/mic4ael/following{/other_user}","gists_url":"https://api.github.com/users/mic4ael/gists{/gist_id}","starred_url":"https://api.github.com/users/mic4ael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mic4ael/subscriptions","organizations_url":"https://api.github.com/users/mic4ael/orgs","repos_url":"https://api.github.com/users/mic4ael/repos","events_url":"https://api.github.com/users/mic4ael/events{/privacy}","received_events_url":"https://api.github.com/users/mic4ael/received_events","type":"User","site_admin":false},"body":"* display number of places left if field defines limits\r\n* add sender email setting to the RegistrationForm","created_at":"2015-10-26T09:26:29Z","updated_at":"2015-10-27T11:24:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"97aee95cf646e0ac27f72d14c5eebe24e03fdd18","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/indico/indico/pulls/2112/commits","review_comments_url":"https://api.github.com/repos/indico/indico/pulls/2112/comments","review_comment_url":"https://api.github.com/repos/indico/indico/pulls/comments{/number}","comments_url":"https://api.github.com/repos/indico/indico/issues/2112/comments","statuses_url":"https://api.github.com/repos/indico/indico/statuses/b6e33e0f592306cefe561785f498af5d01855d9f","head":{"label":"mic4ael:wip/registration","ref":"wip/registration","sha":"b6e33e0f592306cefe561785f498af5d01855d9f","user":{"login":"mic4ael","id":3616940,"avatar_url":"https://avatars.githubusercontent.com/u/3616940?v=3","gravatar_id":"","url":"https://api.github.com/users/mic4ael","html_url":"https://github.com/mic4ael","followers_url":"https://api.github.com/users/mic4ael/followers","following_url":"https://api.github.com/users/mic4ael/following{/other_user}","gists_url":"https://api.github.com/users/mic4ael/gists{/gist_id}","starred_url":"https://api.github.com/users/mic4ael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mic4ael/subscriptions","organizations_url":"https://api.github.com/users/mic4ael/orgs","repos_url":"https://api.github.com/users/mic4ael/repos","events_url":"https://api.github.com/users/mic4ael/events{/privacy}","received_events_url":"https://api.github.com/users/mic4ael/received_events","type":"User","site_admin":false},"repo":{"id":36723985,"name":"indico","full_name":"mic4ael/indico","owner":{"login":"mic4ael","id":3616940,"avatar_url":"https://avatars.githubusercontent.com/u/3616940?v=3","gravatar_id":"","url":"https://api.github.com/users/mic4ael","html_url":"https://github.com/mic4ael","followers_url":"https://api.github.com/users/mic4ael/followers","following_url":"https://api.github.com/users/mic4ael/following{/other_user}","gists_url":"https://api.github.com/users/mic4ael/gists{/gist_id}","starred_url":"https://api.github.com/users/mic4ael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mic4ael/subscriptions","organizations_url":"https://api.github.com/users/mic4ael/orgs","repos_url":"https://api.github.com/users/mic4ael/repos","events_url":"https://api.github.com/users/mic4ael/events{/privacy}","received_events_url":"https://api.github.com/users/mic4ael/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mic4ael/indico","description":"The Indico Project","fork":true,"url":"https://api.github.com/repos/mic4ael/indico","forks_url":"https://api.github.com/repos/mic4ael/indico/forks","keys_url":"https://api.github.com/repos/mic4ael/indico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mic4ael/indico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mic4ael/indico/teams","hooks_url":"https://api.github.com/repos/mic4ael/indico/hooks","issue_events_url":"https://api.github.com/repos/mic4ael/indico/issues/events{/number}","events_url":"https://api.github.com/repos/mic4ael/indico/events","assignees_url":"https://api.github.com/repos/mic4ael/indico/assignees{/user}","branches_url":"https://api.github.com/repos/mic4ael/indico/branches{/branch}","tags_url":"https://api.github.com/repos/mic4ael/indico/tags","blobs_url":"https://api.github.com/repos/mic4ael/indico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mic4ael/indico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mic4ael/indico/git/refs{/sha}","trees_url":"https://api.github.com/repos/mic4ael/indico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mic4ael/indico/statuses/{sha}","languages_url":"https://api.github.com/repos/mic4ael/indico/languages","stargazers_url":"https://api.github.com/repos/mic4ael/indico/stargazers","contributors_url":"https://api.github.com/repos/mic4ael/indico/contributors","subscribers_url":"https://api.github.com/repos/mic4ael/indico/subscribers","subscription_url":"https://api.github.com/repos/mic4ael/indico/subscription","commits_url":"https://api.github.com/repos/mic4ael/indico/commits{/sha}","git_commits_url":"https://api.github.com/repos/mic4ael/indico/git/commits{/sha}","comments_url":"https://api.github.com/repos/mic4ael/indico/comments{/number}","issue_comment_url":"https://api.github.com/repos/mic4ael/indico/issues/comments{/number}","contents_url":"https://api.github.com/repos/mic4ael/indico/contents/{+path}","compare_url":"https://api.github.com/repos/mic4ael/indico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mic4ael/indico/merges","archive_url":"https://api.github.com/repos/mic4ael/indico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mic4ael/indico/downloads","issues_url":"https://api.github.com/repos/mic4ael/indico/issues{/number}","pulls_url":"https://api.github.com/repos/mic4ael/indico/pulls{/number}","milestones_url":"https://api.github.com/repos/mic4ael/indico/milestones{/number}","notifications_url":"https://api.github.com/repos/mic4ael/indico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mic4ael/indico/labels{/name}","releases_url":"https://api.github.com/repos/mic4ael/indico/releases{/id}","created_at":"2015-06-02T09:51:56Z","updated_at":"2015-06-02T09:52:02Z","pushed_at":"2015-10-27T11:02:13Z","git_url":"git://github.com/mic4ael/indico.git","ssh_url":"git@github.com:mic4ael/indico.git","clone_url":"https://github.com/mic4ael/indico.git","svn_url":"https://github.com/mic4ael/indico","homepage":"http://indico-software.org","size":187336,"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":"indico:wip/registration","ref":"wip/registration","sha":"d0b85dbabef92421a97a8a1c73a2581c101393d6","user":{"login":"indico","id":715236,"avatar_url":"https://avatars.githubusercontent.com/u/715236?v=3","gravatar_id":"","url":"https://api.github.com/users/indico","html_url":"https://github.com/indico","followers_url":"https://api.github.com/users/indico/followers","following_url":"https://api.github.com/users/indico/following{/other_user}","gists_url":"https://api.github.com/users/indico/gists{/gist_id}","starred_url":"https://api.github.com/users/indico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indico/subscriptions","organizations_url":"https://api.github.com/users/indico/orgs","repos_url":"https://api.github.com/users/indico/repos","events_url":"https://api.github.com/users/indico/events{/privacy}","received_events_url":"https://api.github.com/users/indico/received_events","type":"Organization","site_admin":false},"repo":{"id":2113067,"name":"indico","full_name":"indico/indico","owner":{"login":"indico","id":715236,"avatar_url":"https://avatars.githubusercontent.com/u/715236?v=3","gravatar_id":"","url":"https://api.github.com/users/indico","html_url":"https://github.com/indico","followers_url":"https://api.github.com/users/indico/followers","following_url":"https://api.github.com/users/indico/following{/other_user}","gists_url":"https://api.github.com/users/indico/gists{/gist_id}","starred_url":"https://api.github.com/users/indico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indico/subscriptions","organizations_url":"https://api.github.com/users/indico/orgs","repos_url":"https://api.github.com/users/indico/repos","events_url":"https://api.github.com/users/indico/events{/privacy}","received_events_url":"https://api.github.com/users/indico/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/indico/indico","description":"The Indico Project","fork":false,"url":"https://api.github.com/repos/indico/indico","forks_url":"https://api.github.com/repos/indico/indico/forks","keys_url":"https://api.github.com/repos/indico/indico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/indico/indico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/indico/indico/teams","hooks_url":"https://api.github.com/repos/indico/indico/hooks","issue_events_url":"https://api.github.com/repos/indico/indico/issues/events{/number}","events_url":"https://api.github.com/repos/indico/indico/events","assignees_url":"https://api.github.com/repos/indico/indico/assignees{/user}","branches_url":"https://api.github.com/repos/indico/indico/branches{/branch}","tags_url":"https://api.github.com/repos/indico/indico/tags","blobs_url":"https://api.github.com/repos/indico/indico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/indico/indico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/indico/indico/git/refs{/sha}","trees_url":"https://api.github.com/repos/indico/indico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/indico/indico/statuses/{sha}","languages_url":"https://api.github.com/repos/indico/indico/languages","stargazers_url":"https://api.github.com/repos/indico/indico/stargazers","contributors_url":"https://api.github.com/repos/indico/indico/contributors","subscribers_url":"https://api.github.com/repos/indico/indico/subscribers","subscription_url":"https://api.github.com/repos/indico/indico/subscription","commits_url":"https://api.github.com/repos/indico/indico/commits{/sha}","git_commits_url":"https://api.github.com/repos/indico/indico/git/commits{/sha}","comments_url":"https://api.github.com/repos/indico/indico/comments{/number}","issue_comment_url":"https://api.github.com/repos/indico/indico/issues/comments{/number}","contents_url":"https://api.github.com/repos/indico/indico/contents/{+path}","compare_url":"https://api.github.com/repos/indico/indico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/indico/indico/merges","archive_url":"https://api.github.com/repos/indico/indico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/indico/indico/downloads","issues_url":"https://api.github.com/repos/indico/indico/issues{/number}","pulls_url":"https://api.github.com/repos/indico/indico/pulls{/number}","milestones_url":"https://api.github.com/repos/indico/indico/milestones{/number}","notifications_url":"https://api.github.com/repos/indico/indico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/indico/indico/labels{/name}","releases_url":"https://api.github.com/repos/indico/indico/releases{/id}","created_at":"2011-07-27T13:56:30Z","updated_at":"2015-10-21T12:06:47Z","pushed_at":"2015-10-27T11:02:39Z","git_url":"git://github.com/indico/indico.git","ssh_url":"git@github.com:indico/indico.git","clone_url":"https://github.com/indico/indico.git","svn_url":"https://github.com/indico/indico","homepage":"http://indico-software.org","size":213315,"stargazers_count":108,"watchers_count":108,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":62,"mirror_url":null,"open_issues_count":542,"forks":62,"open_issues":542,"watchers":108,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/indico/indico/pulls/2112"},"html":{"href":"https://github.com/indico/indico/pull/2112"},"issue":{"href":"https://api.github.com/repos/indico/indico/issues/2112"},"comments":{"href":"https://api.github.com/repos/indico/indico/issues/2112/comments"},"review_comments":{"href":"https://api.github.com/repos/indico/indico/pulls/2112/comments"},"review_comment":{"href":"https://api.github.com/repos/indico/indico/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/indico/indico/pulls/2112/commits"},"statuses":{"href":"https://api.github.com/repos/indico/indico/statuses/b6e33e0f592306cefe561785f498af5d01855d9f"}}}}