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

Issue:
Absolute links in sitemap.xml pages not displayed correctly
Pages which have absolute links are not linked correctly in their sitemaps.
For example, see opev.wordpress.com in the following screenshot

![pages xml](https://cloud.githubusercontent.com/assets/4047597/17020279/4c75c9fc-4f5e-11e6-862b-97748aa7b5e5.png)



Discussion:

Resolving patch:
diff --git a/app/views/sitemap.py b/app/views/sitemap.py
--- a/app/views/sitemap.py
+++ b/app/views/sitemap.py
@@ -19,13 +19,6 @@
     'display_event_coc'
 ]
 
-static_pages = [
-    'how_it_works',
-    'pricing',
-    'about'
-    # TODO: add more when the pages are built
-]
-
 
 @app.route('/sitemap.xml', methods=('GET', 'POST'))
 def render_sitemap():
@@ -51,7 +44,9 @@ def render_sitemap():
 @app.route('/sitemaps/pages.xml.gz', methods=('GET', 'POST'))
 def render_pages_sitemap():
     urls = [
-        full_url(url_for('basicpagesview.url_view', url=page.url)) for page in DataGetter.get_all_pages()
+        page.url if page.url.find('://') > -1 else
+        full_url(url_for('basicpagesview.url_view', url=page.url))
+        for page in DataGetter.get_all_pages()
     ]
     return make_sitemap_response(urls)
 


Test patch:
diff --git a/tests/views/guest/test_sitemaps.py b/tests/views/guest/test_sitemaps.py
--- a/tests/views/guest/test_sitemaps.py
+++ b/tests/views/guest/test_sitemaps.py
@@ -1,6 +1,7 @@
 import unittest
 
 from app.helpers.data import save_to_db
+from app.models.page import Page
 from tests.object_mother import ObjectMother
 from tests.auth_helper import register
 from tests.setup_database import Setup
@@ -39,6 +40,16 @@ def test_event_page_not_exist(self):
         resp = self.app.get('/sitemaps/events/2.xml.gz')
         self.assertEqual(resp.status_code, 404)
 
+    def test_basic_page(self):
+        with app.test_request_context():
+            page = Page(name='abc', url='abc')
+            save_to_db(page)
+            page2 = Page(name='def', url='http://def.com')
+            save_to_db(page2)
+        resp = self.app.get('/sitemaps/pages.xml.gz')
+        self.assertIn('localhost/abc', resp.data)
+        self.assertIn('<loc>http://def.com', resp.data)
+
 
 if __name__ == '__main__':
     unittest.main()
Repository: fossasia/open-event-server

Issue:
User don't see a query phase when puts input to search
![main](https://cloud.githubusercontent.com/assets/2479753/17020752/a15d78a4-4f43-11e6-9e65-86178fce0065.png)

http://127.0.0.1:8001/explore/united-states/events?query=blabla
![explore open event](https://cloud.githubusercontent.com/assets/2479753/17020757/acf35076-4f43-11e6-9783-418a7fcc4501.png)

Query phase should be visible in search form 



Discussion:

Resolving patch:
diff --git a/app/views/admin/home.py b/app/views/admin/home.py
--- a/app/views/admin/home.py
+++ b/app/views/admin/home.py
@@ -181,7 +181,7 @@ def forbidden_view(self):
     def browse_view(self):
         params = request.args.items()
         params = dict((k, v) for k, v in params if v)
-
+        print params
         def test_and_remove(key):
             if request.args.get(key):
                 if request.args.get(key).lower() == request.args.get("query").lower():
diff --git a/app/views/public/explore.py b/app/views/public/explore.py
--- a/app/views/public/explore.py
+++ b/app/views/public/explore.py
@@ -68,6 +68,7 @@ def events_autocomplete(self, location_slug):
     def explore_view(self, location):
         location = deslugify(location)
         current_page = request.args.get('page')
+        query = request.args.get('query', '')
         if not current_page:
             current_page = 1
         else:
@@ -106,7 +107,7 @@ def explore_view(self, location):
                            location=location,
                            filters=filters,
                            current_page=current_page,
-                           categories=CATEGORIES)
+                           categories=CATEGORIES, query=query)
 
 
 CATEGORIES = {'Auto, Boat & Air': ['Air', 'Auto', 'Boat', 'Motorcycle/ATV', 'Other'],


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

Issue:
Internal server error on development 
I suppose this PR https://github.com/fossasia/open-event-orga-server/pull/1763 causes error 



Discussion:

Resolving patch:
diff --git a/migrations/versions/4e143b2ac72a_.py b/migrations/versions/4e143b2ac72a_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/4e143b2ac72a_.py
@@ -0,0 +1,41 @@
+"""empty message
+
+Revision ID: 4e143b2ac72a
+Revises: 8cdaeb567de4
+Create Date: 2016-07-23 09:02:51.743000
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4e143b2ac72a'
+down_revision = '8cdaeb567de4'
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+def upgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.create_table('modules',
+    sa.Column('id', sa.Integer(), nullable=False),
+    sa.Column('ticket_include', sa.Boolean(), nullable=True),
+    sa.Column('payment_include', sa.Boolean(), nullable=True),
+    sa.Column('donation_include', sa.Boolean(), nullable=True),
+    sa.PrimaryKeyConstraint('id')
+    )
+    op.add_column(u'events', sa.Column('ticket_include', sa.Boolean(), nullable=True))
+    op.add_column(u'events_version', sa.Column('ticket_include', sa.Boolean(), autoincrement=False, nullable=True))
+    op.create_index(op.f('ix_speakers_sessions_version_operation_type'), 'speakers_sessions_version', ['operation_type'], unique=False)
+    op.create_index(op.f('ix_speakers_sessions_version_transaction_id'), 'speakers_sessions_version', ['transaction_id'], unique=False)
+    ### end Alembic commands ###
+
+
+def downgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.drop_index(op.f('ix_speakers_sessions_version_transaction_id'), table_name='speakers_sessions_version')
+    op.drop_index(op.f('ix_speakers_sessions_version_operation_type'), table_name='speakers_sessions_version')
+    op.drop_column(u'events_version', 'ticket_include')
+    op.drop_column(u'events', 'ticket_include')
+    op.drop_table('modules')
+    ### end Alembic commands ###


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

Issue:
Issue with Event Importing
Importing Event with Copyright information in event.json fails.

The issue is because of CopyrightDAO which has no real value of version_key defined. 



Discussion:

Resolving patch:
diff --git a/app/api/helpers/utils.py b/app/api/helpers/utils.py
--- a/app/api/helpers/utils.py
+++ b/app/api/helpers/utils.py
@@ -111,7 +111,7 @@ class BaseDAO:
     """
     DAO for a basic independent model
     """
-    version_key = 'base_ver'
+    version_key = None
 
     def __init__(self, model, post_api_model=None, put_api_model=None):
         self.model = model
@@ -164,7 +164,8 @@ def update_version(self, event_id):
         """
         Update version of the component of the event
         """
-        update_version(event_id, False, self.version_key)
+        if self.version_key:
+            update_version(event_id, False, self.version_key)
 
     # Helper functions
     def _del(self, data, fields):


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

Issue:
Enhance Call for Speakers setup
- [x] Make choice to display cfs publicly standard choice
- [x] Change text to: "Display this publicly. Anybody will be able to submit a proposal within the dates chosen, once the event is published."



Discussion:

Resolving patch:
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
@@ -74,7 +74,7 @@ def display_event_schedule(self, event_id):
         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):
+    def display_event_cfs(self, event_id, via_hash=False):
         event = get_published_event_or_abort(event_id)
         if not event.has_session_speakers:
             abort(404)
@@ -82,11 +82,7 @@ def display_event_cfs(self, 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)
-
-        calling_frame = inspect.getouterframes(inspect.currentframe(), 2)
-        if call_for_speakers.privacy != 'public' and calling_frame[1][3] != 'display_event_cfs_via_hash':
+        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)
@@ -101,14 +97,14 @@ def display_event_cfs(self, event_id):
             sate = "future"
         speakers = DataGetter.get_speakers(event_id).all()
         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)
+                           session_form=session_form, call_for_speakers=call_for_speakers, state=state, speakers=speakers, via_hash=via_hash)
 
     @expose('/cfs/<hash>', methods=('GET',))
     def display_event_cfs_via_hash(self, hash):
         call_for_speakers = CallForPaper.query.filter_by(hash=hash).first()
         if not call_for_speakers:
             abort(404)
-        return self.display_event_cfs(call_for_speakers.event_id)
+        return self.display_event_cfs(call_for_speakers.event_id, True)
 
     @expose('/<int:event_id>/cfs/', methods=('POST',))
     def process_event_cfs(self, event_id):


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

Issue:
Change custom_forms to forms in Import/Export
https://github.com/fossasia/open-event-orga-server/issues/1787#issuecomment-234786050



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
@@ -26,7 +26,7 @@
     ('tracks', TrackDAO, TRACK),
     ('session_types', SessionTypeDAO, SESSION_TYPE),
     ('social_links', SocialLinkDAO, SOCIAL_LINK),
-    ('custom_forms', CustomFormDAO, CUSTOM_FORM)
+    ('forms', CustomFormDAO, CUSTOM_FORM)
 ]
 
 # keep sync with storage.UPLOAD_PATHS
diff --git a/app/api/helpers/import_helpers.py b/app/api/helpers/import_helpers.py
--- a/app/api/helpers/import_helpers.py
+++ b/app/api/helpers/import_helpers.py
@@ -34,7 +34,7 @@
     ('tracks', TrackDAO),
     ('session_types', SessionTypeDAO),
     ('sessions', SessionDAO),
-    ('custom_forms', CustomFormDAO)
+    ('forms', CustomFormDAO)
 ]
 
 DELETE_FIELDS = {


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

Issue:
Call for Speaker: Only allow CfS proposal submission when on set dates
Here the proposal submission is possible event though the CfS only starts later.

![screenshot from 2016-07-24 18 43 53](https://cloud.githubusercontent.com/assets/1583873/17085048/a6867636-51ce-11e6-948e-a315549ba21f.png)



Discussion:

Resolving patch:
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
@@ -94,7 +94,7 @@ def display_event_cfs(self, event_id, via_hash=False):
         if call_for_speakers.end_date < now:
             state = "past"
         elif call_for_speakers.start_date > now:
-            sate = "future"
+            state = "future"
         speakers = DataGetter.get_speakers(event_id).all()
         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, via_hash=via_hash)


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

Issue:
Transaction error when importing OTS sample
```
DETAIL:  Key (transaction_id)=(3551) already exists.
 [SQL: 'INSERT INTO speakers_sessions_version (speaker_id, session_id, transaction_id, operation_type) VALUES (%(speaker_id)s, %(session_id)s, %(transaction_id)s, %(operation_type)s)'] [parameters: {'operation_type': 0, 'session_id': 79, 'transaction_id': 3551L, 'speaker_id': 76}]
```

The issue is similar as https://github.com/fossasia/open-event-orga-server/pull/1785/
Because of this, import of OTS sample fails when audio of session 50 is being uploaded to the server (as session 50 is not created properly). 

Also see https://github.com/fossasia/open-event/pull/51



Discussion:

Resolving patch:
diff --git a/app/api/sessions.py b/app/api/sessions.py
--- a/app/api/sessions.py
+++ b/app/api/sessions.py
@@ -9,7 +9,7 @@
 from app.models.microlocation import Microlocation as MicrolocationModel
 from app.models.speaker import Speaker as SpeakerModel
 from app.models.session_type import SessionType as SessionTypeModel
-from app.helpers.data import record_activity
+from app.helpers.data import record_activity, save_to_db
 from app.helpers.data_getter import DataGetter
 
 from .helpers.helpers import save_db_model, get_object_in_event, \
@@ -172,7 +172,11 @@ def update(self, event_id, service_id, data):
     def create(self, event_id, data, url):
         data = self.validate(data, event_id)
         payload = self.fix_payload_post(event_id, data)
+        speakers = payload.pop('speakers', None)
         session, status_code, location = ServiceDAO.create(self, event_id, payload, url, validate=False)
+        if speakers:
+            session.speakers = speakers
+            save_to_db(session)
         if session.state == 'pending':
             trigger_new_session_notifications(session.id, event_id=event_id)
         return session, status_code, location


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

Issue:
Event is visible in call for speakers when event has been deleted



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
@@ -359,7 +359,7 @@ def get_all_published_events(include_private=False):
         else:
             events = Event.query.filter(Event.state == 'Published').filter(Event.privacy != 'private')
         events = events.filter(Event.start_time >= datetime.datetime.now()).filter(
-            Event.end_time >= datetime.datetime.now())
+            Event.end_time >= datetime.datetime.now()).filter(Event.in_trash == 'False')
         return events
 
     @staticmethod
@@ -369,14 +369,14 @@ def get_call_for_speakers_events(include_private=False):
             events = DataGetter.get_all_published_events(include_private)
             for e in events:
                 call_for_speakers = DataGetter.get_call_for_papers(e.id).first()
-                if call_for_speakers:
+                if call_for_speakers and not e.in_trash:
                     results.append(e)
 
         else:
             events = DataGetter.get_all_published_events()
             for e in events:
                 call_for_speakers = DataGetter.get_call_for_papers(e.id).first()
-                if call_for_speakers:
+                if call_for_speakers and not e.in_trash:
                     results.append(e)
         return results[:12]
 


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

Issue:
Configure Codacy and Fix Codacy Issues
- [x] Configure codacy to remove unavoidable checks ( #1768 )
- [x] Fix other codacy issues



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
@@ -798,9 +798,9 @@ def update_user(form, user_id, avatar_img, contacts_only_update=False):
                             user_id=user.id, old=user.email, new=form['email'])
         if user.email != form['email']:
             user.is_verified = False
-            s = Helper.get_serializer()
+            serializer = Helper.get_serializer()
             data = [form['email']]
-            form_hash = s.dumps(data)
+            form_hash = serializer.dumps(data)
             link = url_for('admin.create_account_after_confirmation_view', hash=form_hash, _external=True)
             Helper.send_email_when_changes_email(user.email, form['email'])
             Helper.send_email_confirmation(form, link)
@@ -1491,9 +1491,9 @@ def remove_file(file_id):
         """
         File from request will be removed from database
         """
-        file = File.query.get(file_id)
-        os.remove(os.path.join(os.path.realpath('.') + '/static/', file.name))
-        delete_from_db(file, "File removed")
+        file_obj = File.query.get(file_id)
+        os.remove(os.path.join(os.path.realpath('.') + '/static/', file_obj.name))
+        delete_from_db(file_obj, "File removed")
         flash("File removed")
 
     @staticmethod
@@ -1589,9 +1589,8 @@ def delete_from_db(item, msg):
         logging.info('removed from session')
         db.session.commit()
         return True
-    except Exception, e:
-        print e
-        logging.error('DB Exception! %s' % e)
+    except Exception, error:
+        logging.error('DB Exception! %s' % error)
         db.session.rollback()
         return False
 
@@ -1684,22 +1683,22 @@ def record_activity(template, login_user=None, **kwargs):
     else:
         actor = 'Anonymous'
     id_str = ' (%d)'
-    s = '"%s"'
+    sequence = '"%s"'
     # add more information for objects
     for k in kwargs:
         v = kwargs[k]
         if k.find('_id') > -1:
             kwargs[k] = str(v)
         elif k.startswith('user'):
-            kwargs[k] = s % v.email + id_str % v.id
+            kwargs[k] = sequence % v.email + id_str % v.id
         elif k.startswith('role'):
-            kwargs[k] = s % v.title_name
+            kwargs[k] = sequence % v.title_name
         elif k.startswith('session'):
-            kwargs[k] = s % v.title + id_str % v.id
+            kwargs[k] = sequence % v.title + id_str % v.id
         elif k.startswith('track'):
-            kwargs[k] = s % v.name + id_str % v.id
+            kwargs[k] = sequence % v.name + id_str % v.id
         elif k.startswith('speaker'):
-            kwargs[k] = s % v.name + id_str % v.id
+            kwargs[k] = sequence % v.name + id_str % v.id
         else:
             kwargs[k] = str(v)
     try:


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

Issue:
Run email tasks in background using Celery
Sending email involves sending a POST request to sendgrid. Currently this happens in the request cycle and can easily block the request for some time.
A better solution will be to run the POST request to sendgrid in the background.  Popular/Developed web services/apps usually follow this method. 



Discussion:

Resolving patch:
diff --git a/app/__init__.py b/app/__init__.py
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -286,6 +286,7 @@ def __call__(self, *args, **kwargs):
 
 celery = make_celery(current_app)
 import api.helpers.tasks
+import helpers.tasks
 
 
 @app.before_first_request
diff --git a/app/helpers/helpers.py b/app/helpers/helpers.py
--- a/app/helpers/helpers.py
+++ b/app/helpers/helpers.py
@@ -304,9 +304,8 @@ def send_email(to, action, subject, html):
                 'subject': subject,
                 'html': html
             }
-            requests.post("https://api.sendgrid.com/api/mail.send.json",
-                          data=payload,
-                          headers=headers)
+            from tasks import send_email_task
+            send_email_task.delay(payload, headers)
         # record_mail(to, action, subject, html)
         mail = Mail(
             recipient=to, action=action, subject=subject,
@@ -320,6 +319,7 @@ def send_email(to, action, subject, html):
 # Notifications #
 #################
 
+
 def send_notification(user, action, title, message):
     # DataManager imported here to prevent circular dependency
     from app.helpers.data import DataManager
diff --git a/app/helpers/tasks.py b/app/helpers/tasks.py
new file mode 100644
--- /dev/null
+++ b/app/helpers/tasks.py
@@ -0,0 +1,11 @@
+import requests
+from app import celery
+
+
+@celery.task(name='send.email.post')
+def send_email_task(payload, headers):
+    requests.post(
+        "https://api.sendgrid.com/api/mail.send.json",
+        data=payload,
+        headers=headers
+    )


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

Issue:
Export job time not being updated
Steps to reproduce - 
1. Run export of an event. Wait for it to finish.
2. Run export of the same event few hours later.
3. Open the /export page. The last export time corresponds to the first step, not the (more recent) second step. 



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 datetime import datetime
 from flask import request, g, url_for
 from flask_restplus import marshal
 
@@ -149,6 +150,7 @@ def create_export_job(task_id, event_id):
         export_job.task = task_url
         export_job.user_email = g.user.email
         export_job.event = EventModel.query.get(event_id)
+        export_job.start_time = datetime.now()
     else:
         export_job = ExportJob(
             task=task_url, user_email=g.user.email,


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

Issue:
My tickets page: Wrong tab headers
It should be Upcoming and Past events (not Sessions). 

![my_tickets_sessions](https://cloud.githubusercontent.com/assets/4047597/17353744/56477b72-5960-11e6-82e0-52dc62adce0d.png)



Discussion:

Resolving patch:
diff --git a/app/views/admin/models_views/my_tickets.py b/app/views/admin/models_views/my_tickets.py
--- a/app/views/admin/models_views/my_tickets.py
+++ b/app/views/admin/models_views/my_tickets.py
@@ -1,15 +1,15 @@
-
 import flask_login
 from flask_admin import BaseView, expose
 from app.helpers.ticketing import TicketingManager
 
+
 class MyTicketsView(BaseView):
 
     @expose('/')
     @flask_login.login_required
     def display_my_tickets(self):
-        page_content = {"tab_upcoming_events": "Upcoming Sessions",
-                        "tab_past_events": "Past Sessions",
+        page_content = {"tab_upcoming_events": "Upcoming Events",
+                        "tab_past_events": "Past Events",
                         "title": "My Tickets"}
 
         upcoming_events_orders = TicketingManager.get_orders_of_user(upcoming_events=True)


Test patch: