Repository: fossasia/open-event-server

Issue:
Session CSV Export: Missing fields and Incorrect Columns
Exporting session/speaker information does not show all collected columns. Specifically the information on session length is missing, but also a lot of other info collected.

Furthermore <SessionType 'Talks'> shows up on rows. Expected is just: Talks

![Screenshot from 2019-12-24 06-09-29](https://user-images.githubusercontent.com/1583873/71394935-0c8d2700-2614-11ea-9936-04b3f56c1335.png)



Discussion:
taking this up.

Resolving patch:
diff --git a/app/api/helpers/csv_jobs_util.py b/app/api/helpers/csv_jobs_util.py
--- a/app/api/helpers/csv_jobs_util.py
+++ b/app/api/helpers/csv_jobs_util.py
@@ -47,8 +47,9 @@ def export_attendees_csv(attendees):
 
 def export_sessions_csv(sessions):
     headers = ['Session Title', 'Session Speakers',
-               'Session Track', 'Session Abstract', 'Created At', 'Email Sent',
-               'Level', 'Status', 'Session Type', 'Talk Length']
+               'Session Track', 'Session Abstract Short', 'Session Abstract Long', 'Comment',
+               'Created At', 'Email Sent', 'Level', 'Status', 'Session Type', 'Talk Length',
+               'Language', 'Slides', 'Audio', 'Video']
     rows = [headers]
     for session in sessions:
         if not session.deleted_at:
@@ -63,20 +64,28 @@ def export_sessions_csv(sessions):
                 column.append('')
             column.append(session.track.name if session.track and session.track.name else '')
             column.append(strip_tags(session.short_abstract) if session.short_abstract else '')
+            column.append(strip_tags(session.long_abstract) if session.long_abstract else '')
+            column.append(strip_tags(session.comments) if session.comments else '')
             column.append(session.created_at if session.created_at else '')
             column.append('Yes' if session.is_mail_sent else 'No')
             column.append(session.level)
             column.append(session.state)
-            column.append(session.session_type if session.session_type else '')
-            column.append(len(session.long_abstract) if session.long_abstract else None)
+            column.append(session.session_type.name if session.session_type and session.session_type.name else '')
+            column.append(session.session_type.length if session.session_type and session.session_type.length else '')
+            column.append(session.language if session.language else '')
+            column.append(session.slides_url if session.slides_url else '')
+            column.append(session.audio_url if session.audio_url else '')
+            column.append(session.video_url if session.video_url else '')
             rows.append(column)
 
     return rows
 
 
 def export_speakers_csv(speakers):
-    headers = ['Speaker Name', 'Speaker Email', 'Speaker Session(s)',
-               'Speaker Mobile', 'Speaker Bio', 'Speaker Organisation', 'Speaker Position']
+    headers = ['Speaker Name', 'Speaker Email', 'Speaker Session(s)', 'Speaker Mobile',
+               'Speaker Bio', 'Speaker Organisation', 'Speaker Position', 'Speaker Experience',
+               'Speaker Sponsorship Required', 'Speaker City', 'Speaker Country',
+               'Speaker Website', 'Speaker Twitter', 'Speaker Facebook', 'Speaker Github', 'Speaker LinkedIn']
     rows = [headers]
     for speaker in speakers:
         column = [speaker.name if speaker.name else '', speaker.email if speaker.email else '']
@@ -92,6 +101,15 @@ def export_speakers_csv(speakers):
         column.append(speaker.short_biography if speaker.short_biography else '')
         column.append(speaker.organisation if speaker.organisation else '')
         column.append(speaker.position if speaker.position else '')
+        column.append(speaker.speaking_experience if speaker.speaking_experience else '')
+        column.append(speaker.sponsorship_required if speaker.sponsorship_required else '')
+        column.append(speaker.city if speaker.city else '')
+        column.append(speaker.country if speaker.country else '')
+        column.append(speaker.website if speaker.website else '')
+        column.append(speaker.twitter if speaker.twitter else '')
+        column.append(speaker.facebook if speaker.facebook else '')
+        column.append(speaker.github if speaker.github else '')
+        column.append(speaker.linkedin if speaker.linkedin else '')
         rows.append(column)
 
     return rows


Test patch:
diff --git a/tests/all/integration/api/helpers/test_csv_jobs_util.py b/tests/all/integration/api/helpers/test_csv_jobs_util.py
--- a/tests/all/integration/api/helpers/test_csv_jobs_util.py
+++ b/tests/all/integration/api/helpers/test_csv_jobs_util.py
@@ -43,14 +43,14 @@ def _test_export_session_csv(self, test_session=None):
             session_row = field_data[1]
 
             self.assertEqual(session_row[0], 'example (accepted)')
-            self.assertEqual(session_row[7], 'accepted')
+            self.assertEqual(session_row[9], 'accepted')
 
     def test_export_sessions_csv(self):
         """Method to check sessions data export"""
 
         with app.test_request_context():
             self._test_export_session_csv()
-    
+
     def test_export_sessions_none_csv(self):
         """Method to check sessions data export with no abstract"""
 
@@ -60,17 +60,61 @@ def test_export_sessions_none_csv(self):
             test_session.level = None
             self._test_export_session_csv(test_session)
 
+    def test_export_sessions_with_details_csv(self):
+        """Method to check that sessions details are correct"""
+
+        with app.test_request_context():
+            test_session = SessionFactory(short_abstract='short_abstract',
+                                          long_abstract='long_abstract', comments='comment',
+                                          level='level')
+            db.session.commit()
+            field_data = export_sessions_csv([test_session])
+            session_row = field_data[1]
+
+            self.assertEqual(session_row[0], 'example (accepted)')
+            self.assertEqual(session_row[1], '')
+            self.assertEqual(session_row[2], common.string_)
+            self.assertEqual(session_row[3], 'short_abstract')
+            self.assertEqual(session_row[4], 'long_abstract')
+            self.assertEqual(session_row[5], 'comment')
+            self.assertEqual(session_row[6], common.date_.astimezone())
+            self.assertEqual(session_row[7], 'Yes')
+            self.assertEqual(session_row[8], 'level')
+            self.assertEqual(session_row[9], 'accepted')
+            self.assertEqual(session_row[10], common.string_)
+            self.assertEqual(session_row[11], '00:30')
+            self.assertEqual(session_row[12], 'English')
+            self.assertEqual(session_row[13], common.url_)
+            self.assertEqual(session_row[14], common.url_)
+            self.assertEqual(session_row[15], common.url_)
+
     def test_export_speakers_csv(self):
         """Method to check speakers data export"""
 
         with app.test_request_context():
-            test_speaker = SpeakerFactory()
+            test_speaker = SpeakerFactory(name='Mario Behling', mobile='9004345009', short_biography='Speaker Bio',
+                                          organisation='FOSSASIA', position='position', speaking_experience='1',
+                                          sponsorship_required='No', city='Berlin', country='Germany')
             user = create_user(email='export@example.com', password='password')
             user.id = 2
             field_data = export_speakers_csv([test_speaker])
-            self.assertEqual(field_data[1][0], common.string_)
-            self.assertEqual(field_data[1][1], 'user0@example.com')
-
+            speaker_row = field_data[1]
+            self.assertEqual(speaker_row[0], 'Mario Behling')
+            self.assertEqual(speaker_row[1], 'user0@example.com')
+            self.assertEqual(speaker_row[2], '')
+            self.assertEqual(speaker_row[3], '9004345009')
+            self.assertEqual(speaker_row[4], 'Speaker Bio')
+            self.assertEqual(speaker_row[5], 'FOSSASIA')
+            self.assertEqual(speaker_row[6], 'position')
+            self.assertEqual(speaker_row[7], '1')
+            self.assertEqual(speaker_row[8], 'No')
+            self.assertEqual(speaker_row[9], 'Berlin')
+            self.assertEqual(speaker_row[10], 'Germany')
+            self.assertEqual(speaker_row[11], common.url_)
+            self.assertEqual(speaker_row[12], common.url_)
+            self.assertEqual(speaker_row[13], common.url_)
+            self.assertEqual(speaker_row[14], common.url_)
+            self.assertEqual(speaker_row[15], common.url_)
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()