diff --git a/Dockerfile b/Dockerfile index af80288..005a134 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ COPY static /usr/src/portal-webapp/static COPY contract/ /usr/src/portal-webapp/contract WORKDIR /usr/src/portal-webapp -RUN apt-get update && apt-get -y install wkhtmltopdf python3-pdfkit && \ +RUN apt-get update && apt-get -y install wkhtmltopdf && \ rm -rf /var/lib/apt/lists/* -RUN pip3 install --no-cache-dir flask flask-dropzone gunicorn pdfkit +RUN pip3 install --no-cache-dir pdfkit flask flask-dropzone gunicorn pdfkit CMD ["gunicorn", "--bind", "0.0.0.0:80", "-w", "1", "--access-logfile", "-", "app:app"] diff --git a/app.py b/app.py index e60ff93..1b806b7 100644 --- a/app.py +++ b/app.py @@ -71,6 +71,10 @@ if 'BASE_DIR' in config: BASE_DIR = Path(config['BASE_DIR']) else: BASE_DIR = Path(__file__).resolve().parent +if 'URL_ROOT' in config: + URL_ROOT = config['URL_ROOT'] +else: + URL_ROOT = '/' # Override configs with environment variables, if set if 'PORTALDS4DS1_MAIL_HOST' in os.environ: @@ -87,6 +91,8 @@ if 'PORTALDS4DS1_MAX_UPLOAD_SIZE' in os.environ: MAX_UPLOAD_SIZE = int(os.environ['PORTALDS4DS1_MAX_UPLOAD_SIZE']) if 'PORTALDS4DS1_CONTRACT_CLIENT_CONTACT' in os.environ: CONTRACT_CLIENT_CONTACT = os.environ['PORTALDS4DS1_CONTRACT_CLIENT_CONTACT'] +if 'PORTALDS4DS1_URL_ROOT' in os.environ: + URL_ROOT = os.environ['PORTALDS4DS1_URL_ROOT'] UPLOAD_DIR = BASE_DIR / 'uploads' if not UPLOAD_DIR.exists: @@ -107,12 +113,12 @@ dropzone = Dropzone(app) contract_creator = ContractCreator() -@app.route('/') +@app.route(URL_ROOT) def index(): return render_template('index.html') -@app.route('/upload', methods=['POST']) +@app.route(URL_ROOT + '/upload', methods=['POST']) def handle_upload(): files = request.files if len(files) > 20: @@ -259,8 +265,10 @@ def store_metadata(upload_metadata): f.write('\nnaslov=' + form_data['naslov']) f.write('\nposta=' + form_data['posta']) f.write('\nemail=' + form_data['email']) - f.write('\ndatoteke=' + str(sorted_f_hashes)) - f.write('\npogodba=' + contract) + f.write('\ntelefon=' + form_data['telefon']) + f.write('\nupload_time=' + str(upload_metadata['timestamp'])) + f.write('\nupload_files=' + str(sorted_f_hashes)) + f.write('\ncontract_file=' + contract) def store_datafiles(files, upload_metadata): diff --git a/contract/out.pdf b/contract/out.pdf deleted file mode 100644 index 34c3b9a..0000000 Binary files a/contract/out.pdf and /dev/null differ diff --git a/contract/pdf.py b/contract/pdf.py deleted file mode 100644 index c8b55e8..0000000 --- a/contract/pdf.py +++ /dev/null @@ -1,43 +0,0 @@ -import pdfkit -from jinja2 import Environment, FileSystemLoader - - -class ContractCreator: - - def __init__(self): - template_loader = FileSystemLoader(searchpath="./") - template_env = Environment(loader=template_loader) - self.template = template_env.get_template('template.html') - - self.pdfkit_options = { - 'page-size': 'A4', - 'margin-top': '0.75in', - 'margin-right': '0.75in', - 'margin-bottom': '0.75in', - 'margin-left': '0.75in', - 'encoding': "UTF-8", - 'custom-header' : [ - ('Accept-Encoding', 'gzip') - ] - } - - def fill_template(self, **kwargs): - return self.template.render(**kwargs) - - def create_pdf(self, out_f, fields_dict): - html_str = self.fill_template(**fields_dict) - pdfkit.from_string(html_str, out_f, options=self.pdfkit_options) - - -if __name__ == '__main__': - test_data = { - 'ime_priimek': 'Testko Tester', - 'naslov': 'Testovci 10', - 'posta': '1123', - 'kontakt_narocnik': 'Testica Testkovič', - 'kontakt_imetnikpravic': 'Testko Tester', - 'date': '16.2.2021' - } - - contract_creator = ContractCreator() - contract_creator.create_pdf('out.pdf', test_data) diff --git a/contract/template.html b/contract/template.html index 1bf585e..fdd95b9 100644 --- a/contract/template.html +++ b/contract/template.html @@ -1,6 +1,8 @@
+ +