diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..f958b30 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +before_script: + - docker info + +build_backend_test_image: + stage: build + script: + - docker build ./backend/ -t docker.maxiv.lu.se/elogy_backend-test + - docker push docker.maxiv.lu.se/elogy_backend-test + only: + - master + +build_frontend_test_image: + stage: build + script: + - docker build ./frontend/ -t docker.maxiv.lu.se/elogy_frontend-test + - docker push docker.maxiv.lu.se/elogy_frontend-test + only: + - master + +deploy_test_image: + stage: deploy + script: + - 'curl -H "Authorization: Bearer $AWX_TOKEN" -XPOST https://ansible.maxiv.lu.se/api/v2/job_templates/22/launch/' + only: + - master diff --git a/backend/backend/api/entries.py b/backend/backend/api/entries.py index 712cecf..37bd582 100644 --- a/backend/backend/api/entries.py +++ b/backend/backend/api/entries.py @@ -1,4 +1,5 @@ import logging +from slugify import slugify from flask import request, send_file from flask_restful import Resource, marshal, marshal_with, abort @@ -8,7 +9,7 @@ from ..db import Entry, Logbook, EntryLock from ..attachments import handle_img_tags -from ..export import export_entries_as_pdf +from ..export import export_entries_as_pdf, export_entries_as_html from ..actions import new_entry, edit_entry from . import fields, send_signal @@ -196,6 +197,16 @@ def get(self, args, logbook_id=None): as_attachment=True, attachment_filename=("{logbook.name}.pdf" .format(logbook=logbook))) + elif args.get("download") == "html": + # return a PDF version + # TODO: not sure if this belongs in the API + html = export_entries_as_html(logbook, entries) + if html is None: + abort(400, message="Could not create HTML!") + return send_file(html, mimetype="text/html", + as_attachment=False, + attachment_filename=(slugify("{logbook.name}.html" + .format(logbook=logbook)))) return marshal(dict(logbook=logbook, entries=list(entries)), fields.entries) diff --git a/backend/backend/export.py b/backend/backend/export.py index 2ff416a..53c5ef0 100644 --- a/backend/backend/export.py +++ b/backend/backend/export.py @@ -1,4 +1,5 @@ from tempfile import NamedTemporaryFile +from slugify import slugify try: import pdfkit @@ -52,3 +53,35 @@ def export_entries_as_pdf(logbook, entries): # https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2051 pass return f.name + +def export_entries_as_html(logbook, entries): + + """ + Super basic "proof-of-concept" html export + No proper formatting, and does not embed images. + """ + +# export = "" + entries_html = [ + """ +
{this.props.text}
+