Repository: fossasia/open-event-server

Issue:
Implement Sessions Section with more relevant table data 
In the relevant BaseURLs of sessions of specific events `/events/ID/sessions/` (e.g. https://open-event.herokuapp.com/events/59/sessions/) please implement the table as follows:
- [x] State
- [x] Title
- [x] Speaker
- [x] Track
- [x] Short Abstract
- [x] Submission Date
- [x] Last Changed Date
- [x] Options (View, Edit, Delete)
- [x] Accept or Reject Button



Discussion:

Resolving patch:
diff --git a/open_event/views/admin/models_views/session.py b/open_event/views/admin/models_views/session.py
--- a/open_event/views/admin/models_views/session.py
+++ b/open_event/views/admin/models_views/session.py
@@ -1,8 +1,8 @@
 from flask_admin import expose
 from flask_admin.contrib.sqla import ModelView
 from flask.ext import login
-from flask import request, url_for, redirect
-from ....helpers.data import DataManager, save_to_db
+from flask import request, url_for, redirect, flash
+from ....helpers.data import DataManager, save_to_db, delete_from_db
 from ....helpers.data_getter import DataGetter
 import json
 
@@ -20,15 +20,15 @@ def _handle_view(self, name, **kwargs):
     def index_view(self, event_id):
         sessions = DataGetter.get_sessions_by_event_id(event_id)
         event = DataGetter.get_event(event_id)
-        return self.render('/gentelella/admin/event/session/display.html',
+        return self.render('/gentelella/admin/event/session/base_session_table.html',
                            sessions=sessions, event_id=event_id, event=event)
 
-    @expose('/display/')
-    def display_view(self, event_id):
-        sessions = DataGetter.get_sessions_by_event_id(event_id)
+    @expose('/<int:session_id>/')
+    def session_display_view(self, event_id, session_id):
+        session = DataGetter.get_session(session_id)
         event = DataGetter.get_event(event_id)
         return self.render('/gentelella/admin/event/session/display.html',
-                           sessions=sessions, event_id=event_id, event=event)
+                           session=session, event_id=event_id, event=event)
 
     @expose('/create/', methods=('GET', 'POST'))
     def create_view(self, event_id):
@@ -40,7 +40,7 @@ def create_view(self, event_id):
             session_form = json.loads(elem.session_form)
         if request.method == 'POST':
             DataManager.add_session_to_event(request.form, event_id)
-            return redirect(url_for('session.index_view', event_id=event_id))
+            return redirect(url_for('.index_view', event_id=event_id))
         return self.render('/gentelella/admin/event/session/new/new.html',
                            speaker_form=speaker_form, session_form=session_form)
 
@@ -50,13 +50,12 @@ def new_view(self, event_id, user_id, hash):
         if invite and invite.hash == hash:
             if request.method == 'POST':
                 DataManager.add_session_to_event(request.form, event_id)
-                return redirect(url_for('session.index_view', event_id=event_id))
+                return redirect(url_for('.index_view', event_id=event_id))
             return self.render('/gentelella/admin/session/new/new.html')
 
     @expose('/<int:session_id>/invited/', methods=('GET', 'POST'))
     def invited_view(self, event_id, session_id):
         session = DataGetter.get_session(session_id)
-
         return self.render('/gentelella/admin/event/session/invited.html',
                            session=session, event_id=event_id)
 
@@ -66,7 +65,7 @@ def speaker_view(self, event_id, session_id):
         form_elems = DataGetter.get_custom_form_elements(event_id)
         if request.method == 'POST':
             DataManager.add_speaker_to_session(request.form, event_id, session_id)
-            return redirect(url_for('session.index_view', event_id=event_id))
+            return redirect(url_for('.index_view', event_id=event_id))
         return self.render('/gentelella/admin/event/session/speaker.html',
                            session=session, event_id=event_id, form_elems=form_elems)
 
@@ -77,24 +76,27 @@ def edit_view(self, event_id, session_id):
             return self.render('/gentelella/admin/session/edit.html', session=session)
         if request.method == 'POST':
             DataManager.edit_session(request.form, session)
-            return redirect(url_for('session.index_view', event_id=event_id))
+            return redirect(url_for('.index_view', event_id=event_id))
 
-    @expose('/<int:session_id>/accept_session', methods=('GET',))
+    @expose('/<int:session_id>/accept', methods=('GET',))
     def accept_session(self, event_id, session_id):
         session = DataGetter.get_session(session_id)
         session.state = 'accepted'
         save_to_db(session, 'Session Accepted')
-        return redirect(url_for('.display_view', event_id=event_id))
+        flash("The session has been accepted")
+        return redirect(url_for('.index_view', event_id=event_id))
 
-    @expose('/<int:session_id>/reject_session', methods=('GET',))
+    @expose('/<int:session_id>/reject', methods=('GET',))
     def reject_session(self, event_id, session_id):
         session = DataGetter.get_session(session_id)
         session.state = 'rejected'
         save_to_db(session, 'Session Rejected')
-        return redirect(url_for('.display_view', event_id=event_id))
-
-    @expose('/mysessions/', methods=('GET', 'POST'))
-    def user_sessions_view(self, event_id):
-        pass
-
+        flash("The session has been rejected")
+        return redirect(url_for('.index_view', event_id=event_id))
 
+    @expose('/<int:session_id>/delete', methods=('GET',))
+    def delete_session(self, event_id, session_id):
+        session = DataGetter.get_session(session_id)
+        delete_from_db(session, 'Session Rejected')
+        flash("The session has been deleted", "danger")
+        return redirect(url_for('.index_view', event_id=event_id))


Test patch:
diff --git a/tests/test_session.py b/tests/test_session.py
--- a/tests/test_session.py
+++ b/tests/test_session.py
@@ -16,6 +16,10 @@ class TestSessionApi(OpenEventTestCase):
     def setUp(self):
         self.app = Setup.create_app()
 
+    def login(self):
+        register(self.app, u'email2@gmail.com', u'test2')
+        login(self.app, 'email2@gmail.com', 'test2')
+
     def test_add_session_to_db(self):
         session = ObjectMother.get_session()
         with app.test_request_context():
@@ -36,9 +40,8 @@ def test_multiple_sessions_for_same_event(self):
 
     def test_session_accept(self):
         with app.test_request_context():
+            self.login()
             session = ObjectMother.get_session()
-            register(self.app, u'email2@gmail.com', u'test2')
-            login(self.app, 'email2@gmail.com', 'test2')
             save_to_db(session, "Session Saved")
             url = url_for('session.accept_session', event_id=1, session_id=1)
             rv = self.app.get(url, follow_redirects=True)
@@ -47,12 +50,32 @@ def test_session_accept(self):
     def test_session_reject(self):
         with app.test_request_context():
             session = ObjectMother.get_session()
-            register(self.app, u'email2@gmail.com', u'test2')
-            login(self.app, 'email2@gmail.com', 'test2')
+            self.login()
             save_to_db(session, "Session Saved")
             url = url_for('session.reject_session', event_id=1, session_id=1)
             rv = self.app.get(url, follow_redirects=True)
             self.assertTrue("rejected" in rv.data, msg=rv.data)
 
+    def test_session_delete(self):
+        with app.test_request_context():
+            self.login()
+            session = ObjectMother.get_session()
+            save_to_db(session, "Session Saved")
+            url = url_for('session.delete_session', event_id=1, session_id=1)
+            rv = self.app.get(url, follow_redirects=True)
+            self.assertTrue("deleted" in rv.data, msg=rv.data)
+
+    def test_session_view(self):
+        with app.test_request_context():
+            self.login()
+            event = ObjectMother.get_event()
+            save_to_db(event)
+            session = ObjectMother.get_session()
+            session.event_id = event.id
+            save_to_db(session, "Session Saved")
+            url = url_for('session.session_display_view', event_id=1, session_id=1)
+            rv = self.app.get(url, follow_redirects=True)
+            self.assertTrue("Short Abstract" in rv.data, msg=rv.data)
+
 if __name__ == '__main__':
     unittest.main()