Repository: fossasia/open-event-server

Issue:
Adding image to speakers form erroneous
1. There is a setting "max 1MB" which does not show an error message when a larger photo is chosen. Expected: Show error message "Please choose a photo that is maximum 1MB large."

2. Trying to add a photo is not always possible. Expected: It should work like in wizard step 1.

![screenshot from 2016-11-12 14 17 40](https://cloud.githubusercontent.com/assets/1583873/20236093/0b0f2cb8-a8e3-11e6-8bab-3a4b373025b1.png)



Discussion:
It seems like some form interaction takes place "behind" the lightbox overlay.

> There is a setting "max 1MB" which does not show an error message when a larger photo is chosen. Expected: Show error message "Please choose a photo that is maximum 1MB large."

I will look into this.

> Trying to add a photo is not always possible. Expected: It should work like in wizard step 1.

I didn't get what do you mean by not always possible.

> It seems like some form interaction takes place "behind" the lightbox overlay.

Yes. The image is first uploaded temporarily so that a preview can be shown.

> > Expected: It should work like in wizard step 1.
> 
> I didn't get what do you mean by not always possible.

Sometimes it works, sometimes not. In most cases it does not work for me. There should be a scaling function and flow like the photo upload in the event wizard.

> > It seems like some form interaction takes place "behind" the lightbox overlay.
> 
> Yes. The image is first uploaded temporarily so that a preview can be shown.

The photo is behind the lighbox - it is hidden. The user cannot see it. The dialogs also happen behind the box - invisible.

@mariobehling I will check this out.

@mariobehling the problem is happening because of nested modals for the cropping feature. If we remove the cropping feature the bug would be solved. I think we can remove the cropping feature for the time...

@SaptakS Thanks for the explanation. Unfortunately the cropping feature is kind of basic here. Speakers often have images that do not fit well into the design and we need to be sure, that the images are in square format. How to get a fix and keep the feature?

I will try to fix this tonight.


Resolving patch:
diff --git a/app/views/admin/models_views/my_sessions.py b/app/views/admin/models_views/my_sessions.py
--- a/app/views/admin/models_views/my_sessions.py
+++ b/app/views/admin/models_views/my_sessions.py
@@ -55,10 +55,27 @@ def display_session_view(self, session_id):
         return self.render('/gentelella/admin/mysessions/mysession_detail.html', session=session,
                            speaker_form=speaker_form, session_form=session_form, event=event, speakers=speakers)
 
-    @expose('/<int:session_id>/', methods=('POST',))
+    @expose('/<int:session_id>/edit/', methods=('POST', 'GET'))
     @flask_login.login_required
     def process_session_view(self, session_id):
-        session = DataGetter.get_sessions_of_user_by_id(session_id)
-        DataManager.edit_session(request, session)
-        flash("The session has been updated successfully", "success")
-        return redirect(url_for('.display_session_view', session_id=session_id))
+        if request.method == 'GET':
+            session = DataGetter.get_sessions_of_user_by_id(session_id)
+            if not session:
+                abort(404)
+            form_elems = DataGetter.get_custom_form_elements(session.event_id)
+            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)
+            speakers = DataGetter.get_speakers(session.event_id).all()
+            return self.render('/gentelella/admin/mysessions/mysession_detail_edit.html', session=session,
+                               speaker_form=speaker_form, session_form=session_form, event=event, speakers=speakers)
+
+        if request.method == 'POST':
+            session = DataGetter.get_sessions_of_user_by_id(session_id)
+            DataManager.edit_session(request, session)
+            flash("The session has been updated successfully", "success")
+            return redirect(url_for('.display_session_view', session_id=session_id))
diff --git a/app/views/public/event_detail.py b/app/views/public/event_detail.py
--- a/app/views/public/event_detail.py
+++ b/app/views/public/event_detail.py
@@ -200,19 +200,50 @@ def display_event_cfs_via_hash(self, hash):
                            placeholder_images=placeholder_images, state=state, speakers=speakers,
                            via_hash=True, custom_placeholder=custom_placeholder)
 
-    @expose('/<identifier>/cfs/', methods=('POST',))
-    def process_event_cfs(self, identifier):
-        email = request.form['email']
-        event = DataGetter.get_event_by_identifier(identifier)
-        if not event.has_session_speakers:
-            abort(404)
-        DataManager.add_session_to_event(request, event.id)
-        if login.current_user.is_authenticated:
-            flash("Your session proposal has been submitted", "success")
-            return redirect(url_for('my_sessions.display_my_sessions_view', event_id=event.id))
-        else:
-            flash(Markup("Your session proposal has been submitted. Please login/register with <strong><u>" + email + "</u></strong> to manage it."), "success")
-            return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
+    @expose('/<identifier>/cfs/new/', methods=('POST', 'GET'))
+    def process_event_cfs(self, identifier, via_hash=False):
+        if request.method == 'GET':
+            event = get_published_event_or_abort(identifier)
+            placeholder_images = DataGetter.get_event_default_images()
+            custom_placeholder = DataGetter.get_custom_placeholders()
+            if not event.has_session_speakers:
+                abort(404)
+
+            call_for_speakers = DataGetter.get_call_for_papers(event.id).first()
+            accepted_sessions = DataGetter.get_sessions(event.id)
+
+            if not call_for_speakers or (not via_hash and call_for_speakers.privacy == 'private'):
+                abort(404)
+
+            form_elems = DataGetter.get_custom_form_elements(event.id)
+            speaker_form = json.loads(form_elems.speaker_form)
+            session_form = json.loads(form_elems.session_form)
+
+            now = datetime.now()
+            state = "now"
+            if call_for_speakers.end_date < now:
+                state = "past"
+            elif call_for_speakers.start_date > now:
+                state = "future"
+            speakers = DataGetter.get_speakers(event.id).all()
+            return self.render('/gentelella/guest/event/cfs_new.html', event=event, accepted_sessions=accepted_sessions,
+                               speaker_form=speaker_form,
+                               session_form=session_form, call_for_speakers=call_for_speakers,
+                               placeholder_images=placeholder_images, state=state, speakers=speakers,
+                               via_hash=via_hash, custom_placeholder=custom_placeholder)
+
+        if request.method == 'POST':
+            email = request.form['email']
+            event = DataGetter.get_event_by_identifier(identifier)
+            if not event.has_session_speakers:
+                abort(404)
+            DataManager.add_session_to_event(request, event.id)
+            if login.current_user.is_authenticated:
+                flash("Your session proposal has been submitted", "success")
+                return redirect(url_for('my_sessions.display_my_sessions_view', event_id=event.id))
+            else:
+                flash(Markup("Your session proposal has been submitted. Please login/register with <strong><u>" + email + "</u></strong> to manage it."), "success")
+                return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
 
     @expose('/<identifier>/coc/', methods=('GET',))
     def display_event_coc(self, identifier):


Test patch: