Repository: fossasia/open-event-server

Issue:
CfS: Draft/Submit not being reflected in My Sessions. My Sessions edit form not correct,
- Irrespective of what the user selects (Draft or Submit), both show up as `submitted` in My Sessions. 
- The edit proposal form in My Sessions is primitive and not the same form that is shown when creating sessions.



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -259,13 +259,38 @@ def create_speaker_session_relation(session_id, speaker_id, event_id):
         save_to_db(session, "Session Speaker saved")
 
     @staticmethod
-    def edit_session(form, session):
-        session.title = form['title']
-        session.subtitle = form['subtitle']
-        session.description = form['description']
-        session.start_time = form['start_time']
-        session.end_time = form['end_time']
-        session.abstract = form['abstract']
+    def edit_session(form, session, slide_file, audio_file, video_file):
+
+        event_id = session.event_id
+
+        form_state = form.get('state', 'draft')
+
+        if slide_file != "":
+            slide_url = upload(slide_file,
+                               'events/%d/session/%d/slide' % (int(event_id), int(session.id)))
+            session.slides = slide_url
+
+        if audio_file != "":
+            audio_url = upload(audio_file,
+                               'events/%d/session/%d/audio' % (int(event_id), int(session.id)))
+            session.audio = audio_url
+        if video_file != "":
+            video_url = upload(video_file,
+                               'events/%d/session/%d/video' % (int(event_id), int(session.id)))
+            session.video = video_url
+
+        if form_state == 'pending' and session.state != 'pending' and session.state != 'accepted' and session.state != 'rejected':
+            link = url_for('event_sessions.session_display_view',
+                           event_id=event_id, session_id=session.id, _external=True)
+            organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer')
+            for organizer in organizers:
+                send_new_session_organizer(organizer.user.email, session.event.name, link)
+            session.state = form_state
+
+        session.title = form.get('title', '')
+        session.subtitle = form.get('subtitle', '')
+        session.long_abstract = form.get('long_abstract', '')
+        session.short_abstract = form.get('short_abstract', '')
 
         save_to_db(session, 'Session Updated')
 
diff --git a/open_event/views/admin/models_views/my_sessions.py b/open_event/views/admin/models_views/my_sessions.py
--- a/open_event/views/admin/models_views/my_sessions.py
+++ b/open_event/views/admin/models_views/my_sessions.py
@@ -1,9 +1,15 @@
+import json
+
 import flask_login
+from flask import flash, redirect, url_for, request
 from flask.ext.restplus import abort
 from flask_admin import BaseView, expose
+
+from open_event.helpers.data import DataManager
 from ....helpers.data_getter import DataGetter
 
 class MySessionView(BaseView):
+
     @expose('/')
     @flask_login.login_required
     def display_my_sessions_view(self):
@@ -16,10 +22,41 @@ def display_my_sessions_view(self):
                            upcoming_events_sessions=upcoming_events_sessions, past_events_sessions=past_events_sessions,
                            page_content=page_content)
 
-    @expose('/<int:session_id>/')
+    @expose('/<int:session_id>/', methods=('GET',))
     @flask_login.login_required
     def display_session_view(self, session_id):
         session = DataGetter.get_sessions_of_user_by_id(session_id)
         if not session:
             abort(404)
-        return self.render('/gentelella/admin/mysessions/mysession_detail.html', session=session)
+        form_elems = DataGetter.get_custom_form_elements(session.event_id).first()
+        if not form_elems:
+            flash("Speaker and Session forms have been incorrectly configured for this event."
+                  " Session creation has been disabled", "danger")
+            return redirect(url_for('.display_my_sessions_view', event_id=session.event_id))
+        speaker_form = json.loads(form_elems.speaker_form)
+        session_form = json.loads(form_elems.session_form)
+        event = DataGetter.get_event(session.event_id)
+
+        return self.render('/gentelella/admin/mysessions/mysession_detail.html', session=session,
+                           speaker_form=speaker_form, session_form=session_form, event=event)
+
+    @expose('/<int:session_id>/', methods=('POST',))
+    @flask_login.login_required
+    def process_session_view(self, session_id):
+        session = DataGetter.get_sessions_of_user_by_id(session_id)
+        speaker_img_file = ""
+        slide_file = ""
+        video_file = ""
+        audio_file = ""
+        if 'slides' in request.files and request.files['slides'].filename != '':
+            slide_file = request.files['slides']
+        if 'video' in request.files and request.files['video'].filename != '':
+            video_file = request.files['video']
+        if 'audio' in request.files and request.files['audio'].filename != '':
+            audio_file = request.files['audio']
+        if 'photo' in request.files and request.files['photo'].filename != '':
+            speaker_img_file = request.files['photo']
+
+        DataManager.edit_session(request.form, session, slide_file, audio_file, video_file)
+        flash("The session has been updated successfully", "success")
+        return redirect(url_for('.display_session_view', event_id=session.event_id, session_id=session_id))


Test patch:
diff --git a/tests/test_my_session.py b/tests/test_my_session.py
--- a/tests/test_my_session.py
+++ b/tests/test_my_session.py
@@ -38,7 +38,7 @@ def test_my_session_detail(self):
             login(self.app, 'email2@gmail.com', 'test2')
             rv = self.app.get('events/mysessions/' + str(session.id), follow_redirects=True)
             logout(self.app)
-            self.assertTrue("Long Abstract" in rv.data, msg=rv.data)
+            self.assertTrue("mysessions" in rv.data, msg=rv.data)
 
     def test_my_session_unauthorized_access(self):
         with app.test_request_context():