# HG changeset patch # User Bernhard Reiter # Date 1425650186 -3600 # Node ID 02efda1f69193c95e383012297a8de6e51faceb5 # Parent 77c3e481bea9990ef53e59ff58d7cde38a2650fc issue5117: service for checking a pdf for merging readiness added. diff -r 77c3e481bea9 -r 02efda1f6919 odfcast/__init__.py --- 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"), ) diff -r 77c3e481bea9 -r 02efda1f6919 odfcast/convert.py --- 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): diff -r 77c3e481bea9 -r 02efda1f6919 odfcast/templates/check.html --- /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 %} +

Check

+ +
+
+ + +
+ +
+{% endblock %} diff -r 77c3e481bea9 -r 02efda1f6919 odfcast/templates/index.html --- 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 @@
  • Merge
  • +
  • + Check +
  • {% endblock %}