Repository: fossasia/open-event-server

Issue:
Make state field in Event API a ChoiceField
It should accept only one of the following values - 

```
Draft, Published, Completed, Call for papers
```

Default value should be "Draft".



Discussion:

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -22,7 +22,7 @@
 from .helpers.utils import Resource, ETAG_HEADER_DEFN
 from .helpers import custom_fields as fields
 from helpers.special_fields import EventTypeField, EventTopicField, \
-    EventPrivacyField, EventSubTopicField
+    EventPrivacyField, EventSubTopicField, EventStateField
 
 api = Namespace('events', description='Events')
 
@@ -83,7 +83,7 @@
     'searchable_location_name': fields.String(),
     'organizer_name': fields.String(),
     'organizer_description': fields.String(),
-    'state': fields.String(),
+    'state': EventStateField(default='Draft'),
     'closing_datetime': fields.DateTime(),
     'type': EventTypeField(),
     'topic': EventTopicField(),
diff --git a/app/api/helpers/special_fields.py b/app/api/helpers/special_fields.py
--- a/app/api/helpers/special_fields.py
+++ b/app/api/helpers/special_fields.py
@@ -50,6 +50,16 @@ def __init__(self, **kwargs):
         )
 
 
+class EventStateField(fields.ChoiceString):
+    __schema_example__ = 'Draft'
+
+    def __init__(self, **kwargs):
+        super(EventStateField, self).__init__(
+            choice_list=['Draft', 'Published', 'Completed'],
+            **kwargs
+        )
+
+
 class SessionLanguageField(fields.ChoiceString):
     __schema_example__ = DataGetter.get_language_list()[51]
 
diff --git a/app/helpers/data_getter.py b/app/helpers/data_getter.py
--- a/app/helpers/data_getter.py
+++ b/app/helpers/data_getter.py
@@ -384,7 +384,7 @@ def get_call_for_speakers_events(include_private=False):
     @staticmethod
     def get_published_events():
         events = Event.query.join(Event.roles, aliased=True).filter_by(user_id=login.current_user.id) \
-            .filter(Event.state == 'Call for papers')
+            .filter(Event.state == 'Published')
         return events
 
     @staticmethod
@@ -408,7 +408,7 @@ def get_draft_events():
     def get_past_events():
         return Event.query.join(Event.roles, aliased=True).filter_by(user_id=login.current_user.id) \
             .filter(Event.end_time <= datetime.datetime.now()).filter(
-            or_(Event.state == 'completed', Event.state == 'Published'))
+            or_(Event.state == 'Completed', Event.state == 'Published'))
 
     @staticmethod
     def get_all_live_events():


Test patch:
diff --git a/tests/api/test_post_api_validation.py b/tests/api/test_post_api_validation.py
--- a/tests/api/test_post_api_validation.py
+++ b/tests/api/test_post_api_validation.py
@@ -19,7 +19,7 @@ def test_event_api(self):
             'event',
             POST_EVENT_DATA,
             ['email', 'logo', 'event_url', 'background_url',
-                'type', 'topic', 'privacy', 'sub_topic']
+                'type', 'topic', 'privacy', 'sub_topic', 'state']
         )
 
     def test_speaker_api(self):
diff --git a/tests/api/utils_post_data.py b/tests/api/utils_post_data.py
--- a/tests/api/utils_post_data.py
+++ b/tests/api/utils_post_data.py
@@ -19,7 +19,7 @@
     "closing_datetime": "2016-05-22T12:12:43",
     "organizer_name": "FOSSASIA",
     "organizer_description": "Promoting Open Source culture around the world",
-    "state": "pending",
+    "state": "Draft",
     "type": "Conference",
     "topic": "Science & Technology",
     "sub_topic": "Other",