changeset 73:02efda1f6919

issue5117: service for checking a pdf for merging readiness added.
author Bernhard Reiter <bernhard@intevation.de>
date Fri, 06 Mar 2015 14:56:26 +0100
parents 77c3e481bea9
children 22ce0dc2e71c
files odfcast/__init__.py odfcast/convert.py odfcast/templates/check.html odfcast/templates/index.html
diffstat 4 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/odfcast/__init__.py	Fri Mar 06 14:07:24 2015 +0100
+++ b/odfcast/__init__.py	Fri Mar 06 14:56:26 2015 +0100
@@ -12,7 +12,7 @@
 if app.config["DEBUG"]:
     logging.basicConfig(level=logging.DEBUG)
 
-from odfcast.convert import ConvertView, MergeView, TemplateView
+from odfcast.convert import ConvertView, MergeView, CheckView, TemplateView
 
 
 app.add_url_rule("/convert/",
@@ -25,6 +25,9 @@
 app.add_url_rule("/merge/",
                  view_func=MergeView.as_view("merge"),
                  )
+app.add_url_rule("/check/",
+                 view_func=CheckView.as_view("check"),
+                 )
 app.add_url_rule("/",
                  view_func=TemplateView.as_view("index", "index.html"),
                  )
--- a/odfcast/convert.py	Fri Mar 06 14:07:24 2015 +0100
+++ b/odfcast/convert.py	Fri Mar 06 14:56:26 2015 +0100
@@ -232,6 +232,34 @@
         return request.args.get("ignore_file_errors", False) or \
             request.form.get("ignore_file_errors", False)
 
+class CheckView(MethodView):
+
+    def get(self):
+        return render_template("check.html")
+
+    def post(self):
+        log.debug("Checking a PDF document's readiness for merging")
+
+        merger = PdfFileMerger()
+
+        ffile = request.files['file']
+        if not ffile.filename:
+            return ErrorResponse(
+                "Upload file missing", error_code=101,
+                details="Please upload a file for conversion",
+                html_error_code=400)
+
+        try:
+            merger.append(ffile)
+        except Exception, e:
+            log.exception("Error merging file %s" % ffile)
+            return MergeErrorResponse(details=str(e))
+
+        merger.close()
+
+        log.debug("PDF document %s checked." % ffile)
+        return Response("Okay.")
+
 
 class TemplateView(MethodView):
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/odfcast/templates/check.html	Fri Mar 06 14:56:26 2015 +0100
@@ -0,0 +1,13 @@
+{% extends 'base.html' %}
+
+{% block content %}
+<h1>Check</h1>
+
+<form role="form" action="" method="POST" enctype="multipart/form-data">
+    <div class="form-group">
+        <label for="files">File</label>
+        <input id="files" type="file" name="file">
+    </div>
+    <button class="btn btn-default" type="submit">Check</button>
+</form>
+{% endblock %}
--- a/odfcast/templates/index.html	Fri Mar 06 14:07:24 2015 +0100
+++ b/odfcast/templates/index.html	Fri Mar 06 14:56:26 2015 +0100
@@ -8,5 +8,8 @@
     <li>
     <a href="/merge/">Merge</a>
     </li>
+    <li>
+    <a href="/check/">Check</a>
+    </li>
 </ul>
 {% endblock %}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)