Repository: fossasia/open-event-server

Issue:
Show information only if available
Show information which are available only in `/e/ID/`

For example in http://open-event-dev.herokuapp.com/e/61/#organizer , there is no organizer information but the option for organizer is still shown.



Discussion:

Resolving patch:
diff --git a/open_event/views/public/event_detail.py b/open_event/views/public/event_detail.py
--- a/open_event/views/public/event_detail.py
+++ b/open_event/views/public/event_detail.py
@@ -53,20 +53,25 @@ def display_event_sessions(self, event_id):
         call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
         event = get_published_event_or_abort(event_id)
         tracks = DataGetter.get_tracks(event_id)
-        return self.render('/gentelella/guest/event/sessions.html', event=event, tracks=tracks, call_for_speakers=call_for_speakers)
+        accepted_sessions = DataGetter.get_sessions(event_id)
+        if not accepted_sessions:
+            abort(404)
+        return self.render('/gentelella/guest/event/sessions.html', event=event, accepted_sessions=accepted_sessions, tracks=tracks, call_for_speakers=call_for_speakers)
 
     @expose('/<int:event_id>/schedule/')
     def display_event_schedule(self, event_id):
         call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
         event = get_published_event_or_abort(event_id)
+        accepted_sessions = DataGetter.get_sessions(event_id)
         if not event.schedule_published_on:
             abort(404)
-        return self.render('/gentelella/guest/event/schedule.html', event=event, call_for_speakers=call_for_speakers)
+        return self.render('/gentelella/guest/event/schedule.html', event=event, accepted_sessions=accepted_sessions, call_for_speakers=call_for_speakers)
 
     @expose('/<int:event_id>/cfs/', methods=('GET',))
     def display_event_cfs(self, event_id):
         event = get_published_event_or_abort(event_id)
         call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
+        accepted_sessions = DataGetter.get_sessions(event_id)
 
         if not call_for_speakers:
             abort(404)
@@ -82,7 +87,7 @@ def display_event_cfs(self, event_id):
         elif call_for_speakers.start_date > now:
             sate = "future"
         speakers = DataGetter.get_speakers(event_id).all()
-        return self.render('/gentelella/guest/event/cfs.html', event=event, speaker_form=speaker_form,
+        return self.render('/gentelella/guest/event/cfs.html', event=event, accepted_sessions=accepted_sessions, speaker_form=speaker_form,
                            session_form=session_form, call_for_speakers=call_for_speakers, state=state, speakers=speakers)
 
     @expose('/<int:event_id>/cfs/', methods=('POST',))
@@ -99,7 +104,10 @@ def process_event_cfs(self, event_id):
     @expose('/<int:event_id>/coc/', methods=('GET',))
     def display_event_coc(self, event_id):
         event = get_published_event_or_abort(event_id)
-        return self.render('/gentelella/guest/event/code_of_conduct.html', event=event)
+        accepted_sessions = DataGetter.get_sessions(event_id)
+        if not (event.code_of_conduct and event.code_of_conduct != '' and event.code_of_conduct != ' '):
+            abort(404)
+        return self.render('/gentelella/guest/event/code_of_conduct.html', event=event, accepted_sessions=accepted_sessions)
 
     # SLUGGED PATHS
 


Test patch:
diff --git a/tests/views/guest/test_guest_event_page.py b/tests/views/guest/test_guest_event_page.py
--- a/tests/views/guest/test_guest_event_page.py
+++ b/tests/views/guest/test_guest_event_page.py
@@ -24,11 +24,21 @@ def test_published_event_view_coc(self):
         with app.test_request_context():
             event = ObjectMother.get_event()
             event.state = 'Published'
+            event.code_of_conduct = 'Test Code of Conduct'
             save_to_db(event, "Event Saved")
             rv = self.app.get(url_for('event_detail.display_event_coc', event_id=event.id),
                               follow_redirects=True)
             self.assertTrue("Code of Conduct" in rv.data, msg=rv.data)
 
+    def test_unpublished_event_view_coc(self):
+        with app.test_request_context():
+            event = ObjectMother.get_event()
+            event.state = 'Published'
+            save_to_db(event, "Event Saved")
+            rv = self.app.get(url_for('event_detail.display_event_coc', event_id=event.id),
+                              follow_redirects=True)
+            self.assertEqual(rv.status_code, 404)
+
     def test_unpublished_event_view_attempt(self):
         with app.test_request_context():
             event = ObjectMother.get_event()