prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Show image and square crop option (like in wizard) for speakers and ensure it shows up after import
  ![screenshot from 2016-08-24 11 30 08](https://cloud.githubusercontent.com/assets/1583873/17925701/48dd03be-69ee-11e6-84e4-c353001ddde1.png)
  
  As the above screenshot shows, the image of the speaker does not show up as expected. In the wizard step 1 it is already implemented in that way.
  
  Compare: http://open-event-dev.herokuapp.com/events/132/speakers/882/edit/
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/views/admin/models_views/speakers.py`
  Content:
  ```
  1 import json
  2 
  3 from flask.ext.admin import BaseView
  4 from flask.ext.restplus import abort
  5 from flask_admin import expose
  6 from flask.ext import login
  7 from flask import request, url_for, redirect, flash
  8 from ....helpers.data import delete_from_db, save_to_db
  9 from ....helpers.data_getter import DataGetter
  10 from ....helpers.storage import upload, UPLOAD_PATHS
  11 
  12 
  13 def get_speaker_or_throw(speaker_id):
  14     session = DataGetter.get_speaker(speaker_id)
  15     if not session:
  16         abort(404)
  17     return session
  18 
  19 
  20 class SpeakersView(BaseView):
  21 
  22     def is_accessible(self):
  23         return login.current_user.is_authenticated
  24 
  25     def _handle_view(self, name, **kwargs):
  26         if not self.is_accessible():
  27             return redirect(url_for('admin.login_view', next=request.url))
  28         event = DataGetter.get_event(kwargs['event_id'])
  29         if not event.has_session_speakers:
  30             return self.render('/gentelella/admin/event/info/enable_module.html', active_page='speakers', title='Speakers', event=event)
  31 
  32     @expose('/')
  33     def index_view(self, event_id):
  34         speakers = DataGetter.get_speakers(event_id)
  35         event = DataGetter.get_event(event_id)
  36         return self.render('/gentelella/admin/event/speakers/base_speaker_table.html',
  37                            speakers=speakers, event_id=event_id, event=event)
  38 
  39     @expose('/<int:speaker_id>/edit/', methods=('GET', 'POST'))
  40     def edit_view(self, event_id, speaker_id):
  41         speaker = get_speaker_or_throw(speaker_id)
  42         event = DataGetter.get_event(event_id)
  43         form_elems = DataGetter.get_custom_form_elements(event_id)
  44         if not form_elems:
  45             flash("Speaker form has been incorrectly configured for this event. Editing has been disabled", "danger")
  46             return redirect(url_for('.index_view', event_id=event_id))
  47         speaker_form = json.loads(form_elems.speaker_form)
  48         if request.method == 'GET':
  49             return self.render('/gentelella/admin/event/speakers/edit.html',
  50                                speaker=speaker, event_id=event_id,
  51                                event=event, speaker_form=speaker_form)
  52         if request.method == 'POST':
  53             # set photo
  54             if 'photo' in request.files and request.files['photo'].filename != '':
  55                 speaker_img_file = request.files['photo']
  56                 speaker_img = upload(
  57                     speaker_img_file,
  58                     UPLOAD_PATHS['speakers']['photo'].format(
  59                         event_id=int(event_id), id=int(speaker.id)
  60                     ))
  61                 speaker.photo = speaker_img
  62             # set other fields
  63             speaker.name = request.form.get('name', None)
  64             speaker.short_biography = request.form.get('short_biography', None)
  65             speaker.long_biography = request.form.get('long_biography', None)
  66             speaker.email = request.form.get('email', None)
  67             speaker.mobile = request.form.get('mobile', None)
  68             speaker.website = request.form.get('website', None)
  69             speaker.twitter = request.form.get('twitter', None)
  70             speaker.facebook = request.form.get('facebook', None)
  71             speaker.github = request.form.get('github', None)
  72             speaker.linkedin = request.form.get('linkedin', None)
  73             speaker.organisation = request.form.get('organisation', None)
  74             speaker.featured = True if request.form.get('featured', 'false') == 'true' else False
  75             speaker.position = request.form.get('position', None)
  76             speaker.country = request.form.get('country', None)
  77             save_to_db(speaker, "Speaker has been updated")
  78             flash("Speaker has been saved", "success")
  79 
  80         return redirect(url_for('.index_view', event_id=event_id))
  81 
  82     @expose('/<int:speaker_id>/delete', methods=('GET',))
  83     def delete(self, event_id, speaker_id):
  84         speaker = get_speaker_or_throw(speaker_id)
  85         delete_from_db(speaker, 'Speaker Rejected')
  86         flash("The speaker has been deleted", "danger")
  87         return redirect(url_for('.index_view', event_id=event_id))
  88
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/views/admin/models_views/speakers.py b/app/views/admin/models_views/speakers.py
  --- a/app/views/admin/models_views/speakers.py
  +++ b/app/views/admin/models_views/speakers.py
  @@ -4,10 +4,11 @@
   from flask.ext.restplus import abort
   from flask_admin import expose
   from flask.ext import login
  -from flask import request, url_for, redirect, flash
  +from flask import request, url_for, redirect, flash, jsonify
   from ....helpers.data import delete_from_db, save_to_db
   from ....helpers.data_getter import DataGetter
   from ....helpers.storage import upload, UPLOAD_PATHS
  +from app.helpers.helpers import uploaded_file
   
   
   def get_speaker_or_throw(speaker_id):
  @@ -85,3 +86,23 @@
           delete_from_db(speaker, 'Speaker Rejected')
           flash("The speaker has been deleted", "danger")
           return redirect(url_for('.index_view', event_id=event_id))
  +
  +    @expose('/<int:speaker_id>/photo_upload', methods=('POST',))
  +    def photo_upload(self, event_id, speaker_id):
  +        speaker = get_speaker_or_throw(speaker_id)
  +        event = DataGetter.get_event(event_id)
  +        photo = request.form['photo']
  +        if photo:
  +            photo_file = uploaded_file(file_content=photo)
  +            photo = upload(
  +                photo_file,
  +                UPLOAD_PATHS['speakers']['photo'].format(
  +                        event_id=int(event_id), id=int(speaker.id)
  +                ))
  +            speaker.photo = photo
  +            save_to_db(speaker)
  +            return jsonify({'status': 'ok', 'photo': photo})
  +        else:
  +            speaker.photo = None
  +            save_to_db(speaker)
  +            return jsonify({'status': 'Removed'})
  
verification_info: {"golden_diff": "diff --git a/app/views/admin/models_views/speakers.py b/app/views/admin/models_views/speakers.py\n--- a/app/views/admin/models_views/speakers.py\n+++ b/app/views/admin/models_views/speakers.py\n@@ -4,10 +4,11 @@\n from flask.ext.restplus import abort\n from flask_admin import expose\n from flask.ext import login\n-from flask import request, url_for, redirect, flash\n+from flask import request, url_for, redirect, flash, jsonify\n from ....helpers.data import delete_from_db, save_to_db\n from ....helpers.data_getter import DataGetter\n from ....helpers.storage import upload, UPLOAD_PATHS\n+from app.helpers.helpers import uploaded_file\n \n \n def get_speaker_or_throw(speaker_id):\n@@ -85,3 +86,23 @@\n         delete_from_db(speaker, 'Speaker Rejected')\n         flash(\"The speaker has been deleted\", \"danger\")\n         return redirect(url_for('.index_view', event_id=event_id))\n+\n+    @expose('/<int:speaker_id>/photo_upload', methods=('POST',))\n+    def photo_upload(self, event_id, speaker_id):\n+        speaker = get_speaker_or_throw(speaker_id)\n+        event = DataGetter.get_event(event_id)\n+        photo = request.form['photo']\n+        if photo:\n+            photo_file = uploaded_file(file_content=photo)\n+            photo = upload(\n+                photo_file,\n+                UPLOAD_PATHS['speakers']['photo'].format(\n+                        event_id=int(event_id), id=int(speaker.id)\n+                ))\n+            speaker.photo = photo\n+            save_to_db(speaker)\n+            return jsonify({'status': 'ok', 'photo': photo})\n+        else:\n+            speaker.photo = None\n+            save_to_db(speaker)\n+            return jsonify({'status': 'Removed'})\n", "issue": "Show image and square crop option (like in wizard) for speakers and ensure it shows up after import\n![screenshot from 2016-08-24 11 30 08](https://cloud.githubusercontent.com/assets/1583873/17925701/48dd03be-69ee-11e6-84e4-c353001ddde1.png)\n\nAs the above screenshot shows, the image of the speaker does not show up as expected. In the wizard step 1 it is already implemented in that way.\n\nCompare: http://open-event-dev.herokuapp.com/events/132/speakers/882/edit/\n\n", "before_files": [{"content": "import json\n\nfrom flask.ext.admin import BaseView\nfrom flask.ext.restplus import abort\nfrom flask_admin import expose\nfrom flask.ext import login\nfrom flask import request, url_for, redirect, flash\nfrom ....helpers.data import delete_from_db, save_to_db\nfrom ....helpers.data_getter import DataGetter\nfrom ....helpers.storage import upload, UPLOAD_PATHS\n\n\ndef get_speaker_or_throw(speaker_id):\n    session = DataGetter.get_speaker(speaker_id)\n    if not session:\n        abort(404)\n    return session\n\n\nclass SpeakersView(BaseView):\n\n    def is_accessible(self):\n        return login.current_user.is_authenticated\n\n    def _handle_view(self, name, **kwargs):\n        if not self.is_accessible():\n            return redirect(url_for('admin.login_view', next=request.url))\n        event = DataGetter.get_event(kwargs['event_id'])\n        if not event.has_session_speakers:\n            return self.render('/gentelella/admin/event/info/enable_module.html', active_page='speakers', title='Speakers', event=event)\n\n    @expose('/')\n    def index_view(self, event_id):\n        speakers = DataGetter.get_speakers(event_id)\n        event = DataGetter.get_event(event_id)\n        return self.render('/gentelella/admin/event/speakers/base_speaker_table.html',\n                           speakers=speakers, event_id=event_id, event=event)\n\n    @expose('/<int:speaker_id>/edit/', methods=('GET', 'POST'))\n    def edit_view(self, event_id, speaker_id):\n        speaker = get_speaker_or_throw(speaker_id)\n        event = DataGetter.get_event(event_id)\n        form_elems = DataGetter.get_custom_form_elements(event_id)\n        if not form_elems:\n            flash(\"Speaker form has been incorrectly configured for this event. Editing has been disabled\", \"danger\")\n            return redirect(url_for('.index_view', event_id=event_id))\n        speaker_form = json.loads(form_elems.speaker_form)\n        if request.method == 'GET':\n            return self.render('/gentelella/admin/event/speakers/edit.html',\n                               speaker=speaker, event_id=event_id,\n                               event=event, speaker_form=speaker_form)\n        if request.method == 'POST':\n            # set photo\n            if 'photo' in request.files and request.files['photo'].filename != '':\n                speaker_img_file = request.files['photo']\n                speaker_img = upload(\n                    speaker_img_file,\n                    UPLOAD_PATHS['speakers']['photo'].format(\n                        event_id=int(event_id), id=int(speaker.id)\n                    ))\n                speaker.photo = speaker_img\n            # set other fields\n            speaker.name = request.form.get('name', None)\n            speaker.short_biography = request.form.get('short_biography', None)\n            speaker.long_biography = request.form.get('long_biography', None)\n            speaker.email = request.form.get('email', None)\n            speaker.mobile = request.form.get('mobile', None)\n            speaker.website = request.form.get('website', None)\n            speaker.twitter = request.form.get('twitter', None)\n            speaker.facebook = request.form.get('facebook', None)\n            speaker.github = request.form.get('github', None)\n            speaker.linkedin = request.form.get('linkedin', None)\n            speaker.organisation = request.form.get('organisation', None)\n            speaker.featured = True if request.form.get('featured', 'false') == 'true' else False\n            speaker.position = request.form.get('position', None)\n            speaker.country = request.form.get('country', None)\n            save_to_db(speaker, \"Speaker has been updated\")\n            flash(\"Speaker has been saved\", \"success\")\n\n        return redirect(url_for('.index_view', event_id=event_id))\n\n    @expose('/<int:speaker_id>/delete', methods=('GET',))\n    def delete(self, event_id, speaker_id):\n        speaker = get_speaker_or_throw(speaker_id)\n        delete_from_db(speaker, 'Speaker Rejected')\n        flash(\"The speaker has been deleted\", \"danger\")\n        return redirect(url_for('.index_view', event_id=event_id))\n", "path": "app/views/admin/models_views/speakers.py"}], "after_files": [{"content": "import json\n\nfrom flask.ext.admin import BaseView\nfrom flask.ext.restplus import abort\nfrom flask_admin import expose\nfrom flask.ext import login\nfrom flask import request, url_for, redirect, flash, jsonify\nfrom ....helpers.data import delete_from_db, save_to_db\nfrom ....helpers.data_getter import DataGetter\nfrom ....helpers.storage import upload, UPLOAD_PATHS\nfrom app.helpers.helpers import uploaded_file\n\n\ndef get_speaker_or_throw(speaker_id):\n    session = DataGetter.get_speaker(speaker_id)\n    if not session:\n        abort(404)\n    return session\n\n\nclass SpeakersView(BaseView):\n\n    def is_accessible(self):\n        return login.current_user.is_authenticated\n\n    def _handle_view(self, name, **kwargs):\n        if not self.is_accessible():\n            return redirect(url_for('admin.login_view', next=request.url))\n        event = DataGetter.get_event(kwargs['event_id'])\n        if not event.has_session_speakers:\n            return self.render('/gentelella/admin/event/info/enable_module.html', active_page='speakers', title='Speakers', event=event)\n\n    @expose('/')\n    def index_view(self, event_id):\n        speakers = DataGetter.get_speakers(event_id)\n        event = DataGetter.get_event(event_id)\n        return self.render('/gentelella/admin/event/speakers/base_speaker_table.html',\n                           speakers=speakers, event_id=event_id, event=event)\n\n    @expose('/<int:speaker_id>/edit/', methods=('GET', 'POST'))\n    def edit_view(self, event_id, speaker_id):\n        speaker = get_speaker_or_throw(speaker_id)\n        event = DataGetter.get_event(event_id)\n        form_elems = DataGetter.get_custom_form_elements(event_id)\n        if not form_elems:\n            flash(\"Speaker form has been incorrectly configured for this event. Editing has been disabled\", \"danger\")\n            return redirect(url_for('.index_view', event_id=event_id))\n        speaker_form = json.loads(form_elems.speaker_form)\n        if request.method == 'GET':\n            return self.render('/gentelella/admin/event/speakers/edit.html',\n                               speaker=speaker, event_id=event_id,\n                               event=event, speaker_form=speaker_form)\n        if request.method == 'POST':\n            # set photo\n            if 'photo' in request.files and request.files['photo'].filename != '':\n                speaker_img_file = request.files['photo']\n                speaker_img = upload(\n                    speaker_img_file,\n                    UPLOAD_PATHS['speakers']['photo'].format(\n                        event_id=int(event_id), id=int(speaker.id)\n                    ))\n                speaker.photo = speaker_img\n            # set other fields\n            speaker.name = request.form.get('name', None)\n            speaker.short_biography = request.form.get('short_biography', None)\n            speaker.long_biography = request.form.get('long_biography', None)\n            speaker.email = request.form.get('email', None)\n            speaker.mobile = request.form.get('mobile', None)\n            speaker.website = request.form.get('website', None)\n            speaker.twitter = request.form.get('twitter', None)\n            speaker.facebook = request.form.get('facebook', None)\n            speaker.github = request.form.get('github', None)\n            speaker.linkedin = request.form.get('linkedin', None)\n            speaker.organisation = request.form.get('organisation', None)\n            speaker.featured = True if request.form.get('featured', 'false') == 'true' else False\n            speaker.position = request.form.get('position', None)\n            speaker.country = request.form.get('country', None)\n            save_to_db(speaker, \"Speaker has been updated\")\n            flash(\"Speaker has been saved\", \"success\")\n\n        return redirect(url_for('.index_view', event_id=event_id))\n\n    @expose('/<int:speaker_id>/delete', methods=('GET',))\n    def delete(self, event_id, speaker_id):\n        speaker = get_speaker_or_throw(speaker_id)\n        delete_from_db(speaker, 'Speaker Rejected')\n        flash(\"The speaker has been deleted\", \"danger\")\n        return redirect(url_for('.index_view', event_id=event_id))\n\n    @expose('/<int:speaker_id>/photo_upload', methods=('POST',))\n    def photo_upload(self, event_id, speaker_id):\n        speaker = get_speaker_or_throw(speaker_id)\n        event = DataGetter.get_event(event_id)\n        photo = request.form['photo']\n        if photo:\n            photo_file = uploaded_file(file_content=photo)\n            photo = upload(\n                photo_file,\n                UPLOAD_PATHS['speakers']['photo'].format(\n                        event_id=int(event_id), id=int(speaker.id)\n                ))\n            speaker.photo = photo\n            save_to_db(speaker)\n            return jsonify({'status': 'ok', 'photo': photo})\n        else:\n            speaker.photo = None\n            save_to_db(speaker)\n            return jsonify({'status': 'Removed'})\n", "path": "app/views/admin/models_views/speakers.py"}]}