From fe18d04305a0c8ab4f06aa61f0c7cb8564f819f8 Mon Sep 17 00:00:00 2001
From: Anton Akhmerov <anton.akhmerov@gmail.com>
Date: Mon, 26 Mar 2018 02:43:21 +0200
Subject: [PATCH] implement full export

---
 zesje/api.py              |  7 +++++++
 zesje/resources/export.py | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 zesje/resources/export.py

diff --git a/zesje/api.py b/zesje/api.py
index a9e8ffc93..54496c500 100644
--- a/zesje/api.py
+++ b/zesje/api.py
@@ -9,6 +9,7 @@ from .resources.submissions import Submissions
 from .resources import signature
 from .resources import images
 from .resources import summary_plot
+from .resources import export
 from .resources.problems import Problems
 from .resources.feedback import Feedback
 
@@ -53,3 +54,9 @@ api_bp.add_url_rule(
     'exam_summary',
     summary_plot.get,
 )
+
+api_bp.add_url_rule(
+    '/export/full',
+    'full_export',
+    export.full,
+)
diff --git a/zesje/resources/export.py b/zesje/resources/export.py
new file mode 100644
index 000000000..2cbf09761
--- /dev/null
+++ b/zesje/resources/export.py
@@ -0,0 +1,23 @@
+import os
+from io import BytesIO
+from flask import abort, Response, current_app as app
+from pony import orm
+
+from ..helpers import db_helper
+
+
+def full():
+    """Export the complete database
+
+    Returns
+    -------
+    course.sqlite
+    """
+    data_dir = app.config['DATA_DIRECTORY']
+
+    with open(os.path.join(data_dir, 'course.sqlite'), 'rb') as f:
+        data = f.read()
+    resp = Response(data, 200)
+    resp.headers.set('Content-Disposition', 'attachment',
+                     filename='course.sqlite')
+    return resp
-- 
GitLab