internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: fossasia/open-event-server

Issue:
some events are not showing up on the API, though they exist on the website
Case in point 

This event exists - 
http://open-event-dev.herokuapp.com/e/34/

But the corresponding API doesn't
http://open-event-dev.herokuapp.com/api/v2/events/34 



Discussion:
@championswimmer Because the event has been removed. On the same note, when a user deletes an event it isn't exactly deleted. It is instead put in the trash and then automatically removed after a period of 30 days. Admins and Super Admins can still see and edit deleted events (`/events/34` and `/e/34`). But I checked right now, even a normal account can see them. I don't know if this has been kept this way or it's a bug.

@aditya1702 @niranjan94 ^

@shivamMg it's a bug... Will fix 


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
@@ -15,12 +15,15 @@
 
 def get_published_event_or_abort(event_id):
     event = DataGetter.get_event(event_id=event_id)
-    if not event or (event.state != u'Published' and event.state != 'Published'):
+    if not event or event.state != u'Published':
         user = login.current_user
         if not login.current_user.is_authenticated or (not user.is_organizer(event_id) and not
                                                        user.is_coorganizer(event_id) and not
                                                        user.is_track_organizer(event_id)):
             abort(404)
+
+    if event.in_trash:
+        abort(404)
     return event
 
 class EventDetailView(BaseView):


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
@@ -37,6 +37,16 @@ def test_unpublished_event_view_attempt(self):
                               follow_redirects=True)
             self.assertEqual(rv.status_code, 404)
 
+    def test_soft_deleted_event_view_attempt(self):
+        with app.test_request_context():
+            event = ObjectMother.get_event()
+            event.state = 'Published'
+            event.in_trash = True
+            save_to_db(event, "Event Saved")
+            rv = self.app.get(url_for('event_detail.display_event_detail_home', event_id=event.id),
+                              follow_redirects=True)
+            self.assertEqual(rv.status_code, 404)
+
     def test_published_event_sessions_view(self):
         with app.test_request_context():
             event = ObjectMother.get_event()
Repository: fossasia/open-event-server

Issue:
Session form: Show a drop down for track and session type selection
Show a drop down for track and session type selection in the session form. The user should pick from a list of available tracks/types. 



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -290,6 +290,12 @@ def add_session_to_event(request, event_id, state=None):
                               short_abstract=form.get('short_abstract', ''),
                               state=state)
 
+        if form.get('track', None) != "":
+            new_session.track_id = form.get('track', None)
+
+        if form.get('session_type', None) != "":
+            new_session.session_type_id = form.get('session_type', None)
+
         speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first()
         if not speaker:
             speaker = Speaker(name=form.get('name', ''),
@@ -499,6 +505,16 @@ def edit_session(request, session):
         session.long_abstract = form.get('long_abstract', '')
         session.short_abstract = form.get('short_abstract', '')
 
+        if form.get('track', None) != "":
+            session.track_id = form.get('track', None)
+        else:
+            session.track_id = None
+
+        if form.get('session_type', None) != "":
+            session.session_type_id = form.get('session_type', None)
+        else:
+            session.session_type_id = None
+
         existing_speaker_ids = form.getlist("speakers[]")
         current_speaker_ids = []
 


Test patch:
Repository: fossasia/open-event-server

Issue:
Duplicate New session proposal notification received 
The organizer of an event receives multiple new session proposal notifications for each session submission instead of one.



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -330,7 +330,6 @@ def add_session_to_event(request, event_id, state=None):
                                                                                                     event.id)
                 if email_notification_setting and email_notification_setting.new_paper == 1:
                     send_new_session_organizer(organizer.user.email, event.name, link)
-                    send_notif_new_session_organizer(organizer.user, event.name, link)
                 # Send notification
                 send_notif_new_session_organizer(organizer.user, event.name, link)
 
@@ -498,6 +497,7 @@ def edit_session(request, session):
             organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer')
             for organizer in organizers:
                 send_new_session_organizer(organizer.user.email, session.event.name, link)
+                send_notif_new_session_organizer(organizer.user, session.event.name, link)
             session.state = form_state
 
         session.title = form.get('title', '')


Test patch:
Repository: fossasia/open-event-server

Issue:
Edit event does not work



Discussion:

Resolving patch:
diff --git a/open_event/views/admin/models_views/events.py b/open_event/views/admin/models_views/events.py
--- a/open_event/views/admin/models_views/events.py
+++ b/open_event/views/admin/models_views/events.py
@@ -221,7 +221,7 @@ def edit_view_stepped(self, event_id, step):
                 microlocations, call_for_speakers, sponsors, custom_forms, img_files, old_sponsor_logos, old_sponsor_names)
 
             if (request.form.get('state',
-                                u'Draft') == u'Published' or event.state == 'Draft') and string_empty(
+                                u'Draft') == u'Published') and string_empty(
                                 event.location_name):
                 flash(
                     "Your event was saved. To publish your event please review the highlighted fields below.",


Test patch:
Repository: fossasia/open-event-server

Issue:
Tracks for events and sessions
There can be 2 kind of events:-
- Having only one track. This is equivalent to the event having no track. Sessions for such event donot need to have tracks either.
- Having more than one track. In such cases the track field for sessions need to be compulsory.

Sessions without tracks cannot be scheduled.
Sessions which don't have a track assigned to it cannot be scheduled. This is because while scheduling it expects the session to have track according to which it schedules the session to track.

For example in http://open-event-dev.herokuapp.com/events/74/scheduler/ you can drag and drop the session `Session with Track` but you cannot drag and drop session `Session without Track`

Console Error:  `TypeError: sessionRefObject.session.track is null`



Discussion:
Issue solves:
#1617 
#1613 



Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -854,6 +854,9 @@ def create_event(form, img_files):
 
             track_name = form.getlist('tracks[name]')
             track_color = form.getlist('tracks[color]')
+            if len(track_name) == 0:
+                track_name.append("Default Track")
+                track_color.append("#ffffff")
 
             room_name = form.getlist('rooms[name]')
             room_floor = form.getlist('rooms[floor]')


Test patch:
Repository: fossasia/open-event-server

Issue:
Take out "choose from existing speakers" etc. and change "invite speaker" by email only for now
The "choose from existing speakers" is an organizers feature. It is not a feature for normal users.

Only the organizer should have the ability to use such a feature, but this feature is not thought-through. 

Best is to take it out and use the "invite speaker by email"
![screenshot from 2016-07-14 01 11 08](https://cloud.githubusercontent.com/assets/1583873/16822970/ba870afe-4960-11e6-96cc-818973f39787.png)



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -312,10 +312,10 @@ def add_session_to_event(request, event_id, state=None):
 
         new_session.speakers.append(speaker)
 
-        existing_speaker_ids = form.getlist("speakers[]")
-        for existing_speaker_id in existing_speaker_ids:
-            existing_speaker = DataGetter.get_speaker(existing_speaker_id)
-            new_session.speakers.append(existing_speaker)
+        # existing_speaker_ids = form.getlist("speakers[]")
+        # for existing_speaker_id in existing_speaker_ids:
+        #     existing_speaker = DataGetter.get_speaker(existing_speaker_id)
+        #     new_session.speakers.append(existing_speaker)
 
         save_to_db(new_session, "Session saved")
 
@@ -367,7 +367,6 @@ def add_session_to_event(request, event_id, state=None):
                 if user:
                     Helper.send_notif_invite_papers(user, event.name, link)
 
-
     @staticmethod
     def add_speaker_to_event(request, event_id, user=login.current_user):
         form = request.form


Test patch:
Repository: fossasia/open-event-server

Issue:
Internal server error when search event in location wroclaw
http://open-event-dev.herokuapp.com/explore/wroc%C5%82aw/events/
`{"message": "Input payload validation failed", "errors": {"location": "'ascii' codec can't encode character u'\\u0142' in position 4: ordinal not in range(128)"}}`



Discussion:

Resolving patch:
diff --git a/open_event/api/events.py b/open_event/api/events.py
--- a/open_event/api/events.py
+++ b/open_event/api/events.py
@@ -184,8 +184,8 @@ class EventResource():
     Event Resource Base class
     """
     event_parser = reqparse.RequestParser()
-    event_parser.add_argument('location', type=str, dest='__event_search_location')
-    event_parser.add_argument('contains', type=str, dest='__event_contains')
+    event_parser.add_argument('location', type=unicode, dest='__event_search_location')
+    event_parser.add_argument('contains', type=unicode, dest='__event_contains')
     event_parser.add_argument('state', type=str)
     event_parser.add_argument('privacy', type=str)
     event_parser.add_argument('type', type=str)


Test patch:
Repository: fossasia/open-event-server

Issue:
Scheduler: Add Session view
Parent: [#1564 (Comment)](https://github.com/fossasia/open-event-orga-server/issues/1564#issuecomment-232690851)



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -1248,7 +1248,6 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
             CustomForms, event_id=event.id,
             session_form=session_form, speaker_form=speaker_form)
 
-        delete_from_db(call_for_papers, "CallForPaper Deleted")
 
         if form.get('call_for_speakers_state', u'off') == u'on':
             if call_for_papers:
@@ -1268,6 +1267,10 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
                                                          form['cfs_end_date'], '%m/%d/%Y'),
                                                      event_id=event.id)
                 save_to_db(call_for_speakers)
+        else:
+            if call_for_papers:
+                delete_from_db(call_for_papers, "Cfs deleted")
+
 
         save_to_db(event, "Event saved")
         record_activity('update_event', event_id=event.id)
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
@@ -60,12 +60,12 @@ def display_event_sessions(self, event_id):
 
     @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)
+        tracks = DataGetter.get_tracks(event_id)
         accepted_sessions = DataGetter.get_sessions(event_id)
-        if not event.schedule_published_on:
+        if not accepted_sessions or not event.schedule_published_on:
             abort(404)
-        return self.render('/gentelella/guest/event/schedule.html', event=event, accepted_sessions=accepted_sessions, call_for_speakers=call_for_speakers)
+        return self.render('/gentelella/guest/event/schedule.html', event=event, accepted_sessions=accepted_sessions, tracks=tracks)
 
     @expose('/<int:event_id>/cfs/', methods=('GET',))
     def display_event_cfs(self, event_id):


Test patch:
Repository: fossasia/open-event-server

Issue:
Save with unique filename when importing event
Currently when an event zip is imported, it is saved on the disk at /static/temp/{filename}
Now as celery workers are being used, there is a possiblity that 2 or more import jobs are running in parallel. 
So if their filenames are same, then one of them will be overwritten.

Solution - Check if another file exists with same name before saving. If exists, increment filename as filename_1, filename_2 and so on..



Discussion:

Resolving patch:
diff --git a/open_event/api/helpers/import_helpers.py b/open_event/api/helpers/import_helpers.py
--- a/open_event/api/helpers/import_helpers.py
+++ b/open_event/api/helpers/import_helpers.py
@@ -59,6 +59,21 @@ def _allowed_file(filename, ext):
     return '.' in filename and filename.rsplit('.', 1)[1] in ext
 
 
+def _available_path(folder, filename):
+    """
+    takes filename and folder and returns available path
+    """
+    path = folder + filename
+    if not os.path.isfile(path):
+        return path
+    path += str(1)
+    ct = 1
+    while os.path.isfile(path):
+        ct += 1
+        path = folder + filename + str(ct)
+    return path
+
+
 def get_file_from_request(ext=[], folder='/static/temp/', name='file'):
     """
     Get file from a request, save it locally and return its path
@@ -74,7 +89,7 @@ def get_file_from_request(ext=[], folder='/static/temp/', name='file'):
     if not _allowed_file(file.filename, ext):
         raise NotFoundError('Invalid file type')
     filename = secure_filename(file.filename)
-    path = folder + filename
+    path = _available_path(folder, filename)
     file.save(path)
     return path
 


Test patch:
Repository: fossasia/open-event-server

Issue:
Past events shown incorrectly in UI
Past event shown at /admin/events and /events are incorrect as they don't check if event state is Completed. 



Discussion:

Resolving patch:
diff --git a/app/helpers/data_getter.py b/app/helpers/data_getter.py
--- a/app/helpers/data_getter.py
+++ b/app/helpers/data_getter.py
@@ -38,7 +38,7 @@
 from flask.ext import login
 from flask import flash, current_app, abort
 import datetime
-from sqlalchemy import desc, asc
+from sqlalchemy import desc, asc, or_
 
 
 class DataGetter:
@@ -399,7 +399,8 @@ def get_draft_events():
     @staticmethod
     def get_past_events():
         return Event.query.join(Event.roles, aliased=True).filter_by(user_id=login.current_user.id) \
-            .filter(Event.end_time <= datetime.datetime.now()).filter(Event.state == 'Published')
+            .filter(Event.end_time <= datetime.datetime.now()).filter(
+            or_(Event.state == 'completed', Event.state == 'Published'))
 
     @staticmethod
     def get_all_live_events():
@@ -417,7 +418,8 @@ def get_all_draft_events():
 
     @staticmethod
     def get_all_past_events():
-        return Event.query.filter(Event.end_time <= datetime.datetime.now()).filter(Event.state == 'Published').filter(
+        return Event.query.filter(Event.end_time <= datetime.datetime.now()).filter(
+            or_(Event.state == 'Completed', Event.state == 'Published')).filter(
             Event.in_trash == False)
 
     @staticmethod


Test patch:
Repository: fossasia/open-event-server

Issue:
Add meta.json in exports to contain additional information
For now, it can contain the following information.
- root_url - base url of the website the event was exported from. 



Discussion:

Resolving patch:
diff --git a/app/api/helpers/export_helpers.py b/app/api/helpers/export_helpers.py
--- a/app/api/helpers/export_helpers.py
+++ b/app/api/helpers/export_helpers.py
@@ -2,6 +2,7 @@
 import os
 import shutil
 import requests
+from flask import request
 from flask_restplus import marshal
 
 from ..events import DAO as EventDAO, EVENT, \
@@ -89,6 +90,15 @@ def _download_media(data, srv, dir_path, settings):
             pass
 
 
+def _generate_meta():
+    """
+    Generate Meta information for export
+    """
+    d = {}
+    d['root_url'] = request.url_root
+    return d
+
+
 def export_event_json(event_id, settings):
     """
     Exports the event as a zip on the server and return its path
@@ -111,6 +121,11 @@ def export_event_json(event_id, settings):
         fp = open(dir_path + '/' + e[0] + '.json', 'w')
         fp.write(data_str)
         fp.close()
+    # add meta
+    data_str = json.dumps(_generate_meta(), sort_keys=True, indent=4)
+    fp = open(dir_path + '/meta.json', 'w')
+    fp.write(data_str)
+    fp.close()
     # make zip
     shutil.make_archive(dir_path, 'zip', dir_path)
     return os.path.realpath('.') + '/' + dir_path + '.zip'


Test patch:
diff --git a/tests/api/test_export_import.py b/tests/api/test_export_import.py
--- a/tests/api/test_export_import.py
+++ b/tests/api/test_export_import.py
@@ -107,7 +107,7 @@ def test_export_no_event(self):
 
     def test_export_media(self):
         """
-        test successful export of media
+        test successful export of media (and more)
         """
         resp = self._put(get_path(1), {'logo': 'https://placehold.it/350x150'})
         self.assertIn('placehold', resp.data, resp.data)
@@ -118,6 +118,9 @@ def test_export_media(self):
         obj = json.loads(data)
         logo_data = open(dr + obj['logo'], 'r').read()
         self.assertTrue(len(logo_data) > 10)
+        # test meta.json
+        data = open(dr + '/meta.json', 'r').read()
+        self.assertIn('http', data)
 
     def test_export_settings_marshal(self):
         """
Repository: fossasia/open-event-server

Issue:
Add "Export" tab in specific event dashboard
This is related to https://github.com/fossasia/open-event-orga-server/issues/1217

The event export feature should only be possible from the specific event dashboard.
- [x] Add a tab to the dashboard "Export" and a page with all relevant features

On the export page give the following options:
- [x] Include radio buttons: Button 1: Access Link to Internet | Button 2: Download Data in Export File
  - [x] Images
  - [x] Slides
  - [x] Audio
  - [x] Video

Are there other options needed?



Discussion:

Resolving patch:
diff --git a/app/views/admin/admin.py b/app/views/admin/admin.py
--- a/app/views/admin/admin.py
+++ b/app/views/admin/admin.py
@@ -6,7 +6,7 @@
 from app.models.user import User
 from app.views.admin.models_views.events import EventsView
 from app.views.admin.models_views.my_sessions import MySessionView
-from app.views.admin.models_views.event_api import EventApiView
+from app.views.admin.models_views.export import ExportView
 from app.views.admin.models_views.roles import RoleView
 from app.views.admin.models_views.profile import ProfileView
 from app.views.admin.models_views.settings import SettingsView
@@ -56,7 +56,7 @@ def _add_views(self):
         self.admin.add_view(SponsorsView(name='Sponsors', url='/events/<event_id>/sponsors', endpoint="event_sponsors"))
         self.admin.add_view(SessionsView(name='Sessions', url='/events/<event_id>/sessions', endpoint="event_sessions"))
         self.admin.add_view(SchedulerView(name='Scheduler', url='/events/<event_id>/scheduler', endpoint="event_scheduler"))
-        self.admin.add_view(EventApiView(name='Api', url='/events/<event_id>/api', endpoint="event_api"))
+        self.admin.add_view(ExportView(name='Export', url='/events/<event_id>/export', endpoint="event_export"))
         self.admin.add_view(RoleView(name='Role', url='/events/<event_id>/roles', endpoint="event_roles"))
         self.admin.add_view(ProfileView(name='Profile', url='/profile', endpoint="profile"))
         self.admin.add_view(InviteView(name='Invite', url='/events/<event_id>/invite', endpoint="event_invites"))
diff --git a/app/views/admin/models_views/export.py b/app/views/admin/models_views/export.py
new file mode 100644
--- /dev/null
+++ b/app/views/admin/models_views/export.py
@@ -0,0 +1,20 @@
+import json
+
+import flask_login
+from flask import flash
+from app.api import api
+from flask_admin import BaseView, expose
+
+from app.views.admin.models_views.events import is_verified_user
+from ....helpers.data_getter import DataGetter
+
+class ExportView(BaseView):
+
+    @expose('/')
+    @flask_login.login_required
+    def display_api_view(self, event_id):
+        event = DataGetter.get_event(event_id)
+        if not is_verified_user():
+            flash("Your account is unverified. "
+                  "Please verify by clicking on the confirmation link that has been emailed to you.")
+        return self.render('/gentelella/admin/event/export/export.html', event=event)


Test patch:
Repository: fossasia/open-event-server

Issue:
Event logo is lost when an event is updated without changing logo
1. First make sure that logo is set for an event. Then go to edit basic details page of an event. ( like http://localhost:5000/events/106/edit/ )
2. Don't do anything and click on Save.
3. Again go back to event edit basic details page for that event.
4. Logo is gone. 



Discussion:

Resolving patch:
diff --git a/app/helpers/data.py b/app/helpers/data.py
--- a/app/helpers/data.py
+++ b/app/helpers/data.py
@@ -1110,7 +1110,6 @@ def edit_event(request, event_id, event, session_types, tracks, social_links, mi
         """
         form = request.form
         event.name = form['name']
-        event.logo = form['logo']
         event.start_time = datetime.strptime(form['start_date'] + ' ' + form['start_time'], '%m/%d/%Y %H:%M')
         event.end_time = datetime.strptime(form['end_date'] + ' ' + form['end_time'], '%m/%d/%Y %H:%M')
         event.timezone = form['timezone']


Test patch: