Repository: fossasia/open-event-server

Issue:
Export Speakers as PDF
**Is your feature request related to a problem? Please describe.**
Add an endpoint to export speakers as PDF

**Describe the solution you'd like**
Create a template and follow the steps used by other export endpoints.

**Describe alternatives you've considered**
\-



Discussion:
can i take up this issue?

@starlord1311 Are you clear of what is required and the implementation?
@mayank8318 can you explain what i am supposed to do?
@starlord1311 just look at other pdf export endpoints. You need to follow the same flow. Create an html template to display the list of speakers similar to orders for example. Also, a speaker can have multiple sessions, so you need to display all of those(you can take the export speakers as csv task as a hint). Feel free to ask if you have any queries :)
where are all the other pdf export endpoints?
https://github.com/fossasia/open-event-server/blob/development/app/api/exports.py
This has all the export tasks
@mayank8318  made a pr. can you check it out?

Resolving patch:
diff --git a/app/api/exports.py b/app/api/exports.py
--- a/app/api/exports.py
+++ b/app/api/exports.py
@@ -272,3 +272,23 @@ def export_sessions_pdf(event_identifier):
     return jsonify(
         task_url=url_for('tasks.celery_task', task_id=task.id)
     )
+
+
+@export_routes.route('/events/<string:event_identifier>/export/speakers/pdf', methods=['GET'])
+@jwt_required()
+def export_speakers_pdf(event_identifier):
+    if not event_identifier.isdigit():
+        event = db.session.query(Event).filter_by(identifier=event_identifier).first()
+        event_id = str(event.id)
+    else:
+        event_id = event_identifier
+
+    from .helpers.tasks import export_speakers_pdf_task
+
+    task = export_speakers_pdf_task.delay(event_id)
+
+    create_export_job(task.id, event_id)
+
+    return jsonify(
+        task_url=url_for('tasks.celery_task', task_id=task.id)
+    )
diff --git a/app/api/helpers/tasks.py b/app/api/helpers/tasks.py
--- a/app/api/helpers/tasks.py
+++ b/app/api/helpers/tasks.py
@@ -403,3 +403,20 @@ def export_sessions_pdf_task(self, event_id):
         result = {'__error': True, 'result': str(e)}
 
     return result
+
+
+@celery.task(base=RequestContextTask, name='export.speakers.pdf', bind=True)
+def export_speakers_pdf_task(self, event_id):
+    speakers = db.session.query(Speaker).filter_by(event_id=event_id)
+    try:
+        speakers_pdf_url = create_save_pdf(
+            render_template('pdf/speakers_pdf.html', speakers=speakers),
+            UPLOAD_PATHS['exports-temp']['pdf'].format(event_id=event_id, identifier=''))
+        result = {
+            'download_url': speakers_pdf_url
+        }
+    except Exception as e:
+        print(traceback.format_exc())
+        result = {'__error': True, 'result': str(e)}
+
+    return result


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -3908,6 +3908,20 @@ def event_sessions_export_pdf_get(transaction):
         db.session.add(event)
         db.session.commit()
 
+
+@hooks.before(
+    "Event Export > Start Speakers Export as PDF > Start a Task to Export Speakers of an Event as PDF")
+def event_speakers_export_pdf_get(transaction):
+    """
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
+
+
 # ------------------------- Import -------------------------
 @hooks.before(
     "Event Import > Start Event Import > Start a Task to Import an Event")