Repository: fossasia/open-event-server

Issue:
Implement "My Sessions" Dashboard
Parent Issue: https://github.com/fossasia/open-event-orga-server/issues/622

The URL`/events/mysessions` - shows all sessions the user/speaker has submitted to all "his/her" events. Please implement as shown below.
![screenshot-www eventbrite com 2016-06-11 10-40-20](https://cloud.githubusercontent.com/assets/1583873/15984230/78e2d87c-2fc4-11e6-8391-e86e099512c7.png)



Discussion:
I'll work on it right away .. :+1: 


Resolving patch:
diff --git a/open_event/helpers/data_getter.py b/open_event/helpers/data_getter.py
--- a/open_event/helpers/data_getter.py
+++ b/open_event/helpers/data_getter.py
@@ -77,6 +77,18 @@ def get_sessions(event_id, is_accepted=True):
             is_accepted=is_accepted
         )
 
+    @staticmethod
+    def get_sessions_of_user(upcoming_events=True):
+        """
+        :return: Return all Sessions objects with the current user as a speaker
+        """
+        if upcoming_events:
+            return Session.query.filter(Session.speakers.any(Speaker.email == login.current_user.email)).filter(
+                Event.state != 'Completed')
+        else:
+            return Session.query.filter(Session.speakers.any(Speaker.email == login.current_user.email)).filter(
+                Event.state == 'Completed')
+
     @staticmethod
     def get_speakers(event_id):
         """
diff --git a/open_event/views/admin/admin.py b/open_event/views/admin/admin.py
--- a/open_event/views/admin/admin.py
+++ b/open_event/views/admin/admin.py
@@ -12,6 +12,7 @@
 from open_event.models.speaker import Speaker
 from open_event.models.sponsor import Sponsor
 from open_event.views.admin.models_views.events import EventsView
+from open_event.views.admin.models_views.my_sessions import MySessionView
 from open_event.views.admin.models_views.roles import RoleView
 from open_event.views.admin.models_views.profile import ProfileView
 from open_event.views.admin.models_views.scheduler import SchedulerView
@@ -35,6 +36,7 @@ def init(self, app):
 
     def _add_views(self):
         self.admin.add_view(EventsView(Event, db.session, name='Events', url='events'))
+        self.admin.add_view(MySessionView(name='MySessions', url='events/mysessions'))
         self.admin.add_view(EventsSpeakersView(Speaker, db.session, name='Speaker', url='events/<event_id>/speakers'))
         self.admin.add_view(EventsSponsorsView(Sponsor, db.session, name='Sponsor', url='events/<event_id>/sponsors'))
         self.admin.add_view(SessionView(Session, db.session, name='Sessions', url='events/<event_id>/sessions'))
@@ -44,7 +46,6 @@ def _add_views(self):
         self.admin.add_view(TracksView(Track, db.session, name='Track', url='events/<event_id>/tracks'))
         self.admin.add_view(InviteView(Invite, db.session, name='Invite', url='events/<event_id>/invite'))
 
-
     @staticmethod
     def init_login(app):
         """Init login"""
diff --git a/open_event/views/admin/models_views/my_sessions.py b/open_event/views/admin/models_views/my_sessions.py
new file mode 100644
--- /dev/null
+++ b/open_event/views/admin/models_views/my_sessions.py
@@ -0,0 +1,16 @@
+from flask_admin import BaseView, expose
+from ....helpers.data_getter import DataGetter
+
+class MySessionView(BaseView):
+    @expose('/')
+    def display_my_sessions_view(self):
+        upcoming_events_sessions = DataGetter.get_sessions_of_user(upcoming_events=True)
+        past_events_sessions = DataGetter.get_sessions_of_user(upcoming_events=False)
+        # browse(locals())
+        return self.render('/gentelella/admin/mysessions/mysessions_list.html',
+                           upcoming_events_sessions=upcoming_events_sessions, past_events_sessions=past_events_sessions)
+
+    @expose('/<session_id>')
+    def display_session_view(self, session_id):
+        session = DataGetter.get_session(session_id)
+        return self.render('/gentelella/admin/mysessions/mysession_detail.html', session=session)


Test patch:
diff --git a/tests/test_my_session.py b/tests/test_my_session.py
new file mode 100644
--- /dev/null
+++ b/tests/test_my_session.py
@@ -0,0 +1,22 @@
+"""Copyright 2015 Rafal Kowalski"""
+import unittest
+
+from tests.utils import OpenEventTestCase
+from tests.setup_database import Setup
+from tests.auth_helper import register, logout, login
+from open_event import current_app as app
+
+class TestMySession(OpenEventTestCase):
+    def setUp(self):
+        self.app = Setup.create_app()
+
+    def test_my_session_list(self):
+        with app.test_request_context():
+            register(self.app, u'email2@gmail.com', u'test2')
+            login(self.app, 'email2@gmail.com', 'test2')
+            rv = self.app.get('admin/events/mysessions/', follow_redirects=True)
+            logout(self.app)
+            self.assertTrue("My Session Proposals" in rv.data, msg=rv.data)
+
+if __name__ == '__main__':
+    unittest.main()