We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Make privacy field in Event API accept only public/private as values
Currently privacy field in Event API accepts any string . It should be limited to "public" and "private" and should have "public" as default value. 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `open_event/api/events.py`
Content:
```
1 from flask.ext.restplus import Resource, Namespace, reqparse
2 from flask import g
3 
4 from open_event.models.event import Event as EventModel
5 from open_event.models.social_link import SocialLink as SocialLinkModel
6 from open_event.models.users_events_roles import UsersEventsRoles
7 from open_event.models.role import Role
8 from open_event.models.user import ORGANIZER
9 from open_event.helpers.data import save_to_db, update_version, record_activity
10 
11 from .helpers.helpers import get_paginated_list, requires_auth, parse_args
12 from .helpers.utils import PAGINATED_MODEL, PaginatedResourceBase, \
13     PAGE_PARAMS, POST_RESPONSES, PUT_RESPONSES, BaseDAO, ServiceDAO
14 from .helpers import custom_fields as fields
15 from helpers.special_fields import EventTypeField, EventTopicField
16 
17 
18 api = Namespace('events', description='Events')
19 
20 EVENT_CREATOR = api.model('EventCreator', {
21     'id': fields.Integer(),
22     'email': fields.Email()
23 })
24 
25 EVENT_SOCIAL = api.model('EventSocial', {
26     'id': fields.Integer(),
27     'name': fields.String(),
28     'link': fields.String()
29 })
30 
31 EVENT = api.model('Event', {
32     'id': fields.Integer(required=True),
33     'name': fields.String(required=True),
34     'email': fields.Email(),
35     'color': fields.Color(),
36     'logo': fields.ImageUri(),
37     'start_time': fields.DateTime(required=True),
38     'end_time': fields.DateTime(required=True),
39     'timezone': fields.String(),
40     'latitude': fields.Float(),
41     'longitude': fields.Float(),
42     'event_url': fields.Uri(),
43     'background_url': fields.ImageUri(),
44     'description': fields.String(),
45     'location_name': fields.String(),
46     'organizer_name': fields.String(),
47     'organizer_description': fields.String(),
48     'state': fields.String(),
49     'closing_datetime': fields.DateTime(),
50     'type': EventTypeField(),
51     'topic': EventTopicField(),
52     'privacy': fields.String(),
53     'ticket_url': fields.Uri(),
54     'creator': fields.Nested(EVENT_CREATOR, allow_null=True),
55     'schedule_published_on': fields.DateTime(),
56     'code_of_conduct': fields.String(),
57     'social_links': fields.List(fields.Nested(EVENT_SOCIAL), attribute='social_link')
58 })
59 
60 EVENT_PAGINATED = api.clone('EventPaginated', PAGINATED_MODEL, {
61     'results': fields.List(fields.Nested(EVENT))
62 })
63 
64 EVENT_POST = api.clone('EventPost', EVENT)
65 SOCIAL_LINK_POST = api.clone('SocialLinkPost', EVENT_SOCIAL)
66 
67 del EVENT_POST['id']
68 del EVENT_POST['creator']
69 del EVENT_POST['social_links']
70 
71 del SOCIAL_LINK_POST['id']
72 
73 # ###################
74 # Data Access Objects
75 # ###################
76 
77 
78 class SocialLinkDAO(ServiceDAO):
79     """
80     Social Link DAO
81     """
82     pass
83 
84 
85 class EventDAO(BaseDAO):
86     """
87     Event DAO
88     """
89     def fix_payload(self, data):
90         """
91         Fixes the payload data.
92         Here converts string time from datetime obj
93         """
94         data['start_time'] = EVENT_POST['start_time'].from_str(data['start_time'])
95         data['end_time'] = EVENT_POST['end_time'].from_str(data['end_time'])
96         data['closing_datetime'] = EVENT_POST['closing_datetime'].from_str(
97             data['closing_datetime'])
98         data['schedule_published_on'] = EVENT_POST['schedule_published_on'].from_str(
99             data['schedule_published_on'])
100         return data
101 
102     def create(self, data, url):
103         data = self.validate(data)
104         payload = self.fix_payload(data)
105         new_event = self.model(**payload)
106         new_event.creator = g.user
107         save_to_db(new_event, "Event saved")
108         # set organizer
109         role = Role.query.filter_by(name=ORGANIZER).first()
110         uer = UsersEventsRoles(g.user, new_event, role)
111         save_to_db(uer, 'UER saved')
112         update_version(
113             event_id=new_event.id,
114             is_created=True,
115             column_to_increment="event_ver"
116         )
117         # Return created resource with a 201 status code and its Location
118         # (url) in the header.
119         resource_location = url + '/' + str(new_event.id)
120         return self.get(new_event.id), 201, {'Location': resource_location}
121 
122     def update(self, event_id, data):
123         data = self.validate(data)
124         payload = self.fix_payload(data)
125         return BaseDAO.update(self, event_id, payload, validate=False)
126 
127 
128 LinkDAO = SocialLinkDAO(SocialLinkModel, SOCIAL_LINK_POST)
129 DAO = EventDAO(EventModel, EVENT_POST)
130 
131 
132 # DEFINE PARAMS
133 
134 EVENT_PARAMS = {
135     'location': {
136         'type': str
137     },
138     'contains': {
139         'description': 'Contains the string in name and description',
140         'type': str
141     },
142     'state': {
143         'type': str
144     },
145     'privacy': {
146         'type': str
147     },
148     'type': {
149         'type': str
150     },
151     'topic': {
152         'type': str
153     },
154     'start_time_gt': {},
155     'start_time_lt': {},
156     'end_time_gt': {},
157     'end_time_lt': {}
158 }
159 
160 # DEFINE RESOURCES
161 
162 
163 class EventResource():
164     """
165     Event Resource Base class
166     """
167     event_parser = reqparse.RequestParser()
168     event_parser.add_argument('location', type=str, dest='__event_location')
169     event_parser.add_argument('contains', type=str, dest='__event_contains')
170     event_parser.add_argument('state', type=str)
171     event_parser.add_argument('privacy', type=str)
172     event_parser.add_argument('type', type=str)
173     event_parser.add_argument('topic', type=str)
174     event_parser.add_argument('start_time_gt', dest='__event_start_time_gt')
175     event_parser.add_argument('start_time_lt', dest='__event_start_time_lt')
176     event_parser.add_argument('end_time_gt', dest='__event_end_time_gt')
177     event_parser.add_argument('end_time_lt', dest='__event_end_time_lt')
178 
179 
180 @api.route('/<int:event_id>')
181 @api.param('event_id')
182 @api.response(404, 'Event not found')
183 class Event(Resource):
184     @api.doc('get_event')
185     @api.marshal_with(EVENT)
186     def get(self, event_id):
187         """Fetch an event given its id"""
188         return DAO.get(event_id)
189 
190     @requires_auth
191     @api.doc('delete_event')
192     @api.marshal_with(EVENT)
193     def delete(self, event_id):
194         """Delete an event given its id"""
195         event = DAO.delete(event_id)
196         record_activity('delete_event', event_id=event_id)
197         return event
198 
199     @requires_auth
200     @api.doc('update_event', responses=PUT_RESPONSES)
201     @api.marshal_with(EVENT)
202     @api.expect(EVENT_POST)
203     def put(self, event_id):
204         """Update a event given its id"""
205         event = DAO.update(event_id, self.api.payload)
206         record_activity('update_event', event_id=event_id)
207         return event
208 
209 
210 @api.route('')
211 class EventList(Resource, EventResource):
212     @api.doc('list_events', params=EVENT_PARAMS)
213     @api.marshal_list_with(EVENT)
214     def get(self):
215         """List all events"""
216         return DAO.list(**parse_args(self.event_parser))
217 
218     @requires_auth
219     @api.doc('create_event', responses=POST_RESPONSES)
220     @api.marshal_with(EVENT)
221     @api.expect(EVENT_POST)
222     def post(self):
223         """Create an event"""
224         item = DAO.create(self.api.payload, self.api.url_for(self))
225         record_activity('create_event', event_id=item[0].id)
226         return item
227 
228 
229 @api.route('/page')
230 class EventListPaginated(Resource, PaginatedResourceBase, EventResource):
231     @api.doc('list_events_paginated', params=PAGE_PARAMS)
232     @api.doc(params=EVENT_PARAMS)
233     @api.marshal_with(EVENT_PAGINATED)
234     def get(self):
235         """List events in a paginated manner"""
236         args = self.parser.parse_args()
237         url = self.api.url_for(self)  # WARN: undocumented way
238         return get_paginated_list(
239             EventModel, url, args=args,
240             **parse_args(self.event_parser)
241         )
242
```

Path: `open_event/api/helpers/special_fields.py`
Content:
```
1 from open_event.helpers.data_getter import DataGetter
2 
3 import custom_fields as fields
4 
5 
6 class EventTypeField(fields.ChoiceString):
7     __schema_example__ = DataGetter.get_event_types()[0]
8 
9     def __init__(self, **kwargs):
10         super(EventTypeField, self).__init__(
11             choice_list=DataGetter.get_event_types(),
12             **kwargs)
13 
14 
15 class EventTopicField(fields.ChoiceString):
16     __schema_example__ = DataGetter.get_event_topics()[0]
17 
18     def __init__(self, **kwargs):
19         super(EventTopicField, self).__init__(
20             choice_list=DataGetter.get_event_topics(),
21             **kwargs)
22 
23 
24 class SessionLanguageField(fields.ChoiceString):
25     __schema_example__ = DataGetter.get_language_list()[51]
26 
27     def __init__(self, **kwargs):
28         super(SessionLanguageField, self).__init__(
29             choice_list=DataGetter.get_language_list(),
30             **kwargs)
31 
32 
33 class SessionStateField(fields.ChoiceString):
34     __schema_example__ = 'pending'
35 
36     def __init__(self, **kwargs):
37         super(SessionStateField, self).__init__(
38             choice_list=['pending', 'accepted', 'rejected'],
39             **kwargs)
40
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/open_event/api/events.py b/open_event/api/events.py
--- a/open_event/api/events.py
+++ b/open_event/api/events.py
@@ -12,7 +12,8 @@
 from .helpers.utils import PAGINATED_MODEL, PaginatedResourceBase, \
     PAGE_PARAMS, POST_RESPONSES, PUT_RESPONSES, BaseDAO, ServiceDAO
 from .helpers import custom_fields as fields
-from helpers.special_fields import EventTypeField, EventTopicField
+from helpers.special_fields import EventTypeField, EventTopicField, \
+    EventPrivacyField
 
 
 api = Namespace('events', description='Events')
@@ -49,7 +50,7 @@
     'closing_datetime': fields.DateTime(),
     'type': EventTypeField(),
     'topic': EventTopicField(),
-    'privacy': fields.String(),
+    'privacy': EventPrivacyField(),
     'ticket_url': fields.Uri(),
     'creator': fields.Nested(EVENT_CREATOR, allow_null=True),
     'schedule_published_on': fields.DateTime(),
diff --git a/open_event/api/helpers/special_fields.py b/open_event/api/helpers/special_fields.py
--- a/open_event/api/helpers/special_fields.py
+++ b/open_event/api/helpers/special_fields.py
@@ -21,6 +21,16 @@
             **kwargs)
 
 
+class EventPrivacyField(fields.ChoiceString):
+    __schema_example__ = 'public'
+
+    def __init__(self, **kwargs):
+        super(EventPrivacyField, self).__init__(
+            choice_list=['public', 'private'],
+            **kwargs
+        )
+
+
 class SessionLanguageField(fields.ChoiceString):
     __schema_example__ = DataGetter.get_language_list()[51]

{"golden_diff": "diff --git a/open_event/api/events.py b/open_event/api/events.py\n--- a/open_event/api/events.py\n+++ b/open_event/api/events.py\n@@ -12,7 +12,8 @@\n from .helpers.utils import PAGINATED_MODEL, PaginatedResourceBase, \\\n     PAGE_PARAMS, POST_RESPONSES, PUT_RESPONSES, BaseDAO, ServiceDAO\n from .helpers import custom_fields as fields\n-from helpers.special_fields import EventTypeField, EventTopicField\n+from helpers.special_fields import EventTypeField, EventTopicField, \\\n+    EventPrivacyField\n \n \n api = Namespace('events', description='Events')\n@@ -49,7 +50,7 @@\n     'closing_datetime': fields.DateTime(),\n     'type': EventTypeField(),\n     'topic': EventTopicField(),\n-    'privacy': fields.String(),\n+    'privacy': EventPrivacyField(),\n     'ticket_url': fields.Uri(),\n     'creator': fields.Nested(EVENT_CREATOR, allow_null=True),\n     'schedule_published_on': fields.DateTime(),\ndiff --git a/open_event/api/helpers/special_fields.py b/open_event/api/helpers/special_fields.py\n--- a/open_event/api/helpers/special_fields.py\n+++ b/open_event/api/helpers/special_fields.py\n@@ -21,6 +21,16 @@\n             **kwargs)\n \n \n+class EventPrivacyField(fields.ChoiceString):\n+    __schema_example__ = 'public'\n+\n+    def __init__(self, **kwargs):\n+        super(EventPrivacyField, self).__init__(\n+            choice_list=['public', 'private'],\n+            **kwargs\n+        )\n+\n+\n class SessionLanguageField(fields.ChoiceString):\n     __schema_example__ = DataGetter.get_language_list()[51]\n", "issue": "Make privacy field in Event API accept only public/private as values\nCurrently privacy field in Event API accepts any string . It should be limited to \"public\" and \"private\" and should have \"public\" as default value. \n\n", "before_files": [{"content": "from flask.ext.restplus import Resource, Namespace, reqparse\nfrom flask import g\n\nfrom open_event.models.event import Event as EventModel\nfrom open_event.models.social_link import SocialLink as SocialLinkModel\nfrom open_event.models.users_events_roles import UsersEventsRoles\nfrom open_event.models.role import Role\nfrom open_event.models.user import ORGANIZER\nfrom open_event.helpers.data import save_to_db, update_version, record_activity\n\nfrom .helpers.helpers import get_paginated_list, requires_auth, parse_args\nfrom .helpers.utils import PAGINATED_MODEL, PaginatedResourceBase, \\\n    PAGE_PARAMS, POST_RESPONSES, PUT_RESPONSES, BaseDAO, ServiceDAO\nfrom .helpers import custom_fields as fields\nfrom helpers.special_fields import EventTypeField, EventTopicField\n\n\napi = Namespace('events', description='Events')\n\nEVENT_CREATOR = api.model('EventCreator', {\n    'id': fields.Integer(),\n    'email': fields.Email()\n})\n\nEVENT_SOCIAL = api.model('EventSocial', {\n    'id': fields.Integer(),\n    'name': fields.String(),\n    'link': fields.String()\n})\n\nEVENT = api.model('Event', {\n    'id': fields.Integer(required=True),\n    'name': fields.String(required=True),\n    'email': fields.Email(),\n    'color': fields.Color(),\n    'logo': fields.ImageUri(),\n    'start_time': fields.DateTime(required=True),\n    'end_time': fields.DateTime(required=True),\n    'timezone': fields.String(),\n    'latitude': fields.Float(),\n    'longitude': fields.Float(),\n    'event_url': fields.Uri(),\n    'background_url': fields.ImageUri(),\n    'description': fields.String(),\n    'location_name': fields.String(),\n    'organizer_name': fields.String(),\n    'organizer_description': fields.String(),\n    'state': fields.String(),\n    'closing_datetime': fields.DateTime(),\n    'type': EventTypeField(),\n    'topic': EventTopicField(),\n    'privacy': fields.String(),\n    'ticket_url': fields.Uri(),\n    'creator': fields.Nested(EVENT_CREATOR, allow_null=True),\n    'schedule_published_on': fields.DateTime(),\n    'code_of_conduct': fields.String(),\n    'social_links': fields.List(fields.Nested(EVENT_SOCIAL), attribute='social_link')\n})\n\nEVENT_PAGINATED = api.clone('EventPaginated', PAGINATED_MODEL, {\n    'results': fields.List(fields.Nested(EVENT))\n})\n\nEVENT_POST = api.clone('EventPost', EVENT)\nSOCIAL_LINK_POST = api.clone('SocialLinkPost', EVENT_SOCIAL)\n\ndel EVENT_POST['id']\ndel EVENT_POST['creator']\ndel EVENT_POST['social_links']\n\ndel SOCIAL_LINK_POST['id']\n\n# ###################\n# Data Access Objects\n# ###################\n\n\nclass SocialLinkDAO(ServiceDAO):\n    \"\"\"\n    Social Link DAO\n    \"\"\"\n    pass\n\n\nclass EventDAO(BaseDAO):\n    \"\"\"\n    Event DAO\n    \"\"\"\n    def fix_payload(self, data):\n        \"\"\"\n        Fixes the payload data.\n        Here converts string time from datetime obj\n        \"\"\"\n        data['start_time'] = EVENT_POST['start_time'].from_str(data['start_time'])\n        data['end_time'] = EVENT_POST['end_time'].from_str(data['end_time'])\n        data['closing_datetime'] = EVENT_POST['closing_datetime'].from_str(\n            data['closing_datetime'])\n        data['schedule_published_on'] = EVENT_POST['schedule_published_on'].from_str(\n            data['schedule_published_on'])\n        return data\n\n    def create(self, data, url):\n        data = self.validate(data)\n        payload = self.fix_payload(data)\n        new_event = self.model(**payload)\n        new_event.creator = g.user\n        save_to_db(new_event, \"Event saved\")\n        # set organizer\n        role = Role.query.filter_by(name=ORGANIZER).first()\n        uer = UsersEventsRoles(g.user, new_event, role)\n        save_to_db(uer, 'UER saved')\n        update_version(\n            event_id=new_event.id,\n            is_created=True,\n            column_to_increment=\"event_ver\"\n        )\n        # Return created resource with a 201 status code and its Location\n        # (url) in the header.\n        resource_location = url + '/' + str(new_event.id)\n        return self.get(new_event.id), 201, {'Location': resource_location}\n\n    def update(self, event_id, data):\n        data = self.validate(data)\n        payload = self.fix_payload(data)\n        return BaseDAO.update(self, event_id, payload, validate=False)\n\n\nLinkDAO = SocialLinkDAO(SocialLinkModel, SOCIAL_LINK_POST)\nDAO = EventDAO(EventModel, EVENT_POST)\n\n\n# DEFINE PARAMS\n\nEVENT_PARAMS = {\n    'location': {\n        'type': str\n    },\n    'contains': {\n        'description': 'Contains the string in name and description',\n        'type': str\n    },\n    'state': {\n        'type': str\n    },\n    'privacy': {\n        'type': str\n    },\n    'type': {\n        'type': str\n    },\n    'topic': {\n        'type': str\n    },\n    'start_time_gt': {},\n    'start_time_lt': {},\n    'end_time_gt': {},\n    'end_time_lt': {}\n}\n\n# DEFINE RESOURCES\n\n\nclass EventResource():\n    \"\"\"\n    Event Resource Base class\n    \"\"\"\n    event_parser = reqparse.RequestParser()\n    event_parser.add_argument('location', type=str, dest='__event_location')\n    event_parser.add_argument('contains', type=str, dest='__event_contains')\n    event_parser.add_argument('state', type=str)\n    event_parser.add_argument('privacy', type=str)\n    event_parser.add_argument('type', type=str)\n    event_parser.add_argument('topic', type=str)\n    event_parser.add_argument('start_time_gt', dest='__event_start_time_gt')\n    event_parser.add_argument('start_time_lt', dest='__event_start_time_lt')\n    event_parser.add_argument('end_time_gt', dest='__event_end_time_gt')\n    event_parser.add_argument('end_time_lt', dest='__event_end_time_lt')\n\n\n@api.route('/<int:event_id>')\n@api.param('event_id')\n@api.response(404, 'Event not found')\nclass Event(Resource):\n    @api.doc('get_event')\n    @api.marshal_with(EVENT)\n    def get(self, event_id):\n        \"\"\"Fetch an event given its id\"\"\"\n        return DAO.get(event_id)\n\n    @requires_auth\n    @api.doc('delete_event')\n    @api.marshal_with(EVENT)\n    def delete(self, event_id):\n        \"\"\"Delete an event given its id\"\"\"\n        event = DAO.delete(event_id)\n        record_activity('delete_event', event_id=event_id)\n        return event\n\n    @requires_auth\n    @api.doc('update_event', responses=PUT_RESPONSES)\n    @api.marshal_with(EVENT)\n    @api.expect(EVENT_POST)\n    def put(self, event_id):\n        \"\"\"Update a event given its id\"\"\"\n        event = DAO.update(event_id, self.api.payload)\n        record_activity('update_event', event_id=event_id)\n        return event\n\n\n@api.route('')\nclass EventList(Resource, EventResource):\n    @api.doc('list_events', params=EVENT_PARAMS)\n    @api.marshal_list_with(EVENT)\n    def get(self):\n        \"\"\"List all events\"\"\"\n        return DAO.list(**parse_args(self.event_parser))\n\n    @requires_auth\n    @api.doc('create_event', responses=POST_RESPONSES)\n    @api.marshal_with(EVENT)\n    @api.expect(EVENT_POST)\n    def post(self):\n        \"\"\"Create an event\"\"\"\n        item = DAO.create(self.api.payload, self.api.url_for(self))\n        record_activity('create_event', event_id=item[0].id)\n        return item\n\n\n@api.route('/page')\nclass EventListPaginated(Resource, PaginatedResourceBase, EventResource):\n    @api.doc('list_events_paginated', params=PAGE_PARAMS)\n    @api.doc(params=EVENT_PARAMS)\n    @api.marshal_with(EVENT_PAGINATED)\n    def get(self):\n        \"\"\"List events in a paginated manner\"\"\"\n        args = self.parser.parse_args()\n        url = self.api.url_for(self)  # WARN: undocumented way\n        return get_paginated_list(\n            EventModel, url, args=args,\n            **parse_args(self.event_parser)\n        )\n", "path": "open_event/api/events.py"}, {"content": "from open_event.helpers.data_getter import DataGetter\n\nimport custom_fields as fields\n\n\nclass EventTypeField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_event_types()[0]\n\n    def __init__(self, **kwargs):\n        super(EventTypeField, self).__init__(\n            choice_list=DataGetter.get_event_types(),\n            **kwargs)\n\n\nclass EventTopicField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_event_topics()[0]\n\n    def __init__(self, **kwargs):\n        super(EventTopicField, self).__init__(\n            choice_list=DataGetter.get_event_topics(),\n            **kwargs)\n\n\nclass SessionLanguageField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_language_list()[51]\n\n    def __init__(self, **kwargs):\n        super(SessionLanguageField, self).__init__(\n            choice_list=DataGetter.get_language_list(),\n            **kwargs)\n\n\nclass SessionStateField(fields.ChoiceString):\n    __schema_example__ = 'pending'\n\n    def __init__(self, **kwargs):\n        super(SessionStateField, self).__init__(\n            choice_list=['pending', 'accepted', 'rejected'],\n            **kwargs)\n", "path": "open_event/api/helpers/special_fields.py"}], "after_files": [{"content": "from flask.ext.restplus import Resource, Namespace, reqparse\nfrom flask import g\n\nfrom open_event.models.event import Event as EventModel\nfrom open_event.models.social_link import SocialLink as SocialLinkModel\nfrom open_event.models.users_events_roles import UsersEventsRoles\nfrom open_event.models.role import Role\nfrom open_event.models.user import ORGANIZER\nfrom open_event.helpers.data import save_to_db, update_version, record_activity\n\nfrom .helpers.helpers import get_paginated_list, requires_auth, parse_args\nfrom .helpers.utils import PAGINATED_MODEL, PaginatedResourceBase, \\\n    PAGE_PARAMS, POST_RESPONSES, PUT_RESPONSES, BaseDAO, ServiceDAO\nfrom .helpers import custom_fields as fields\nfrom helpers.special_fields import EventTypeField, EventTopicField, \\\n    EventPrivacyField\n\n\napi = Namespace('events', description='Events')\n\nEVENT_CREATOR = api.model('EventCreator', {\n    'id': fields.Integer(),\n    'email': fields.Email()\n})\n\nEVENT_SOCIAL = api.model('EventSocial', {\n    'id': fields.Integer(),\n    'name': fields.String(),\n    'link': fields.String()\n})\n\nEVENT = api.model('Event', {\n    'id': fields.Integer(required=True),\n    'name': fields.String(required=True),\n    'email': fields.Email(),\n    'color': fields.Color(),\n    'logo': fields.ImageUri(),\n    'start_time': fields.DateTime(required=True),\n    'end_time': fields.DateTime(required=True),\n    'timezone': fields.String(),\n    'latitude': fields.Float(),\n    'longitude': fields.Float(),\n    'event_url': fields.Uri(),\n    'background_url': fields.ImageUri(),\n    'description': fields.String(),\n    'location_name': fields.String(),\n    'organizer_name': fields.String(),\n    'organizer_description': fields.String(),\n    'state': fields.String(),\n    'closing_datetime': fields.DateTime(),\n    'type': EventTypeField(),\n    'topic': EventTopicField(),\n    'privacy': EventPrivacyField(),\n    'ticket_url': fields.Uri(),\n    'creator': fields.Nested(EVENT_CREATOR, allow_null=True),\n    'schedule_published_on': fields.DateTime(),\n    'code_of_conduct': fields.String(),\n    'social_links': fields.List(fields.Nested(EVENT_SOCIAL), attribute='social_link')\n})\n\nEVENT_PAGINATED = api.clone('EventPaginated', PAGINATED_MODEL, {\n    'results': fields.List(fields.Nested(EVENT))\n})\n\nEVENT_POST = api.clone('EventPost', EVENT)\nSOCIAL_LINK_POST = api.clone('SocialLinkPost', EVENT_SOCIAL)\n\ndel EVENT_POST['id']\ndel EVENT_POST['creator']\ndel EVENT_POST['social_links']\n\ndel SOCIAL_LINK_POST['id']\n\n# ###################\n# Data Access Objects\n# ###################\n\n\nclass SocialLinkDAO(ServiceDAO):\n    \"\"\"\n    Social Link DAO\n    \"\"\"\n    pass\n\n\nclass EventDAO(BaseDAO):\n    \"\"\"\n    Event DAO\n    \"\"\"\n    def fix_payload(self, data):\n        \"\"\"\n        Fixes the payload data.\n        Here converts string time from datetime obj\n        \"\"\"\n        data['start_time'] = EVENT_POST['start_time'].from_str(data['start_time'])\n        data['end_time'] = EVENT_POST['end_time'].from_str(data['end_time'])\n        data['closing_datetime'] = EVENT_POST['closing_datetime'].from_str(\n            data['closing_datetime'])\n        data['schedule_published_on'] = EVENT_POST['schedule_published_on'].from_str(\n            data['schedule_published_on'])\n        return data\n\n    def create(self, data, url):\n        data = self.validate(data)\n        payload = self.fix_payload(data)\n        new_event = self.model(**payload)\n        new_event.creator = g.user\n        save_to_db(new_event, \"Event saved\")\n        # set organizer\n        role = Role.query.filter_by(name=ORGANIZER).first()\n        uer = UsersEventsRoles(g.user, new_event, role)\n        save_to_db(uer, 'UER saved')\n        update_version(\n            event_id=new_event.id,\n            is_created=True,\n            column_to_increment=\"event_ver\"\n        )\n        # Return created resource with a 201 status code and its Location\n        # (url) in the header.\n        resource_location = url + '/' + str(new_event.id)\n        return self.get(new_event.id), 201, {'Location': resource_location}\n\n    def update(self, event_id, data):\n        data = self.validate(data)\n        payload = self.fix_payload(data)\n        return BaseDAO.update(self, event_id, payload, validate=False)\n\n\nLinkDAO = SocialLinkDAO(SocialLinkModel, SOCIAL_LINK_POST)\nDAO = EventDAO(EventModel, EVENT_POST)\n\n\n# DEFINE PARAMS\n\nEVENT_PARAMS = {\n    'location': {\n        'type': str\n    },\n    'contains': {\n        'description': 'Contains the string in name and description',\n        'type': str\n    },\n    'state': {\n        'type': str\n    },\n    'privacy': {\n        'type': str\n    },\n    'type': {\n        'type': str\n    },\n    'topic': {\n        'type': str\n    },\n    'start_time_gt': {},\n    'start_time_lt': {},\n    'end_time_gt': {},\n    'end_time_lt': {}\n}\n\n# DEFINE RESOURCES\n\n\nclass EventResource():\n    \"\"\"\n    Event Resource Base class\n    \"\"\"\n    event_parser = reqparse.RequestParser()\n    event_parser.add_argument('location', type=str, dest='__event_location')\n    event_parser.add_argument('contains', type=str, dest='__event_contains')\n    event_parser.add_argument('state', type=str)\n    event_parser.add_argument('privacy', type=str)\n    event_parser.add_argument('type', type=str)\n    event_parser.add_argument('topic', type=str)\n    event_parser.add_argument('start_time_gt', dest='__event_start_time_gt')\n    event_parser.add_argument('start_time_lt', dest='__event_start_time_lt')\n    event_parser.add_argument('end_time_gt', dest='__event_end_time_gt')\n    event_parser.add_argument('end_time_lt', dest='__event_end_time_lt')\n\n\n@api.route('/<int:event_id>')\n@api.param('event_id')\n@api.response(404, 'Event not found')\nclass Event(Resource):\n    @api.doc('get_event')\n    @api.marshal_with(EVENT)\n    def get(self, event_id):\n        \"\"\"Fetch an event given its id\"\"\"\n        return DAO.get(event_id)\n\n    @requires_auth\n    @api.doc('delete_event')\n    @api.marshal_with(EVENT)\n    def delete(self, event_id):\n        \"\"\"Delete an event given its id\"\"\"\n        event = DAO.delete(event_id)\n        record_activity('delete_event', event_id=event_id)\n        return event\n\n    @requires_auth\n    @api.doc('update_event', responses=PUT_RESPONSES)\n    @api.marshal_with(EVENT)\n    @api.expect(EVENT_POST)\n    def put(self, event_id):\n        \"\"\"Update a event given its id\"\"\"\n        event = DAO.update(event_id, self.api.payload)\n        record_activity('update_event', event_id=event_id)\n        return event\n\n\n@api.route('')\nclass EventList(Resource, EventResource):\n    @api.doc('list_events', params=EVENT_PARAMS)\n    @api.marshal_list_with(EVENT)\n    def get(self):\n        \"\"\"List all events\"\"\"\n        return DAO.list(**parse_args(self.event_parser))\n\n    @requires_auth\n    @api.doc('create_event', responses=POST_RESPONSES)\n    @api.marshal_with(EVENT)\n    @api.expect(EVENT_POST)\n    def post(self):\n        \"\"\"Create an event\"\"\"\n        item = DAO.create(self.api.payload, self.api.url_for(self))\n        record_activity('create_event', event_id=item[0].id)\n        return item\n\n\n@api.route('/page')\nclass EventListPaginated(Resource, PaginatedResourceBase, EventResource):\n    @api.doc('list_events_paginated', params=PAGE_PARAMS)\n    @api.doc(params=EVENT_PARAMS)\n    @api.marshal_with(EVENT_PAGINATED)\n    def get(self):\n        \"\"\"List events in a paginated manner\"\"\"\n        args = self.parser.parse_args()\n        url = self.api.url_for(self)  # WARN: undocumented way\n        return get_paginated_list(\n            EventModel, url, args=args,\n            **parse_args(self.event_parser)\n        )\n", "path": "open_event/api/events.py"}, {"content": "from open_event.helpers.data_getter import DataGetter\n\nimport custom_fields as fields\n\n\nclass EventTypeField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_event_types()[0]\n\n    def __init__(self, **kwargs):\n        super(EventTypeField, self).__init__(\n            choice_list=DataGetter.get_event_types(),\n            **kwargs)\n\n\nclass EventTopicField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_event_topics()[0]\n\n    def __init__(self, **kwargs):\n        super(EventTopicField, self).__init__(\n            choice_list=DataGetter.get_event_topics(),\n            **kwargs)\n\n\nclass EventPrivacyField(fields.ChoiceString):\n    __schema_example__ = 'public'\n\n    def __init__(self, **kwargs):\n        super(EventPrivacyField, self).__init__(\n            choice_list=['public', 'private'],\n            **kwargs\n        )\n\n\nclass SessionLanguageField(fields.ChoiceString):\n    __schema_example__ = DataGetter.get_language_list()[51]\n\n    def __init__(self, **kwargs):\n        super(SessionLanguageField, self).__init__(\n            choice_list=DataGetter.get_language_list(),\n            **kwargs)\n\n\nclass SessionStateField(fields.ChoiceString):\n    __schema_example__ = 'pending'\n\n    def __init__(self, **kwargs):\n        super(SessionStateField, self).__init__(\n            choice_list=['pending', 'accepted', 'rejected'],\n            **kwargs)\n", "path": "open_event/api/helpers/special_fields.py"}]}