Fixed utf bugs in pdf generation, deleted unnecessary files, some other minor tweaks.
This commit is contained in:
parent
c1d6cbbb70
commit
fd4bad4afe
|
@ -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"]
|
||||
|
|
16
app.py
16
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):
|
||||
|
|
BIN
contract/out.pdf
BIN
contract/out.pdf
Binary file not shown.
|
@ -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)
|
|
@ -1,6 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<style>
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@import url(http://fonts.googleapis.com/css?family=Roboto:400,400italic,500,500italic,700,700italic,900,900italic,300italic,300,100italic,100);
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto:400,400italic,500,500italic,700,700italic,900,900italic,300italic,300,100italic,100);
|
||||
|
||||
label,
|
||||
input {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="sl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Portal za oddajanje besedil za DS4 in DS1</title>
|
||||
|
@ -237,7 +237,7 @@ zagotovili vse potrebne informacije v skladu s predpisi o varstvu osebnih podatk
|
|||
const reEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
Dropzone.options.myDropzone = { // The camelized version of the ID of the form element
|
||||
url: "/upload",
|
||||
url: "./upload",
|
||||
autoProcessQueue: false,
|
||||
uploadMultiple: true,
|
||||
parallelUploads: 20,
|
||||
|
|
Loading…
Reference in New Issue
Block a user