Add label rendering

master
informatic 2020-04-08 20:09:24 +02:00
parent 4b07ba0a35
commit e2ae029a09
5 changed files with 87 additions and 1 deletions

View File

@ -13,6 +13,8 @@ RUN apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev postgresql
pip3 install --no-cache-dir psycopg2==2.8.4 pycparser==2.20 cffi==1.14.0 bcrypt==3.1.7 && \
apk del --no-cache .build-deps
RUN apk add --no-cache py3-pillow cairo pango glib font-noto
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

View File

@ -1,4 +1,4 @@
from flask import redirect, flash, request
from flask import redirect, flash, request, url_for
import flask_admin
from formity.extensions import admin, db, ModelView, ModelViewHighSecurity, AdminSecurityMixin
from wtforms import TextAreaField
@ -6,6 +6,7 @@ from formity.models import FaceshieldRequest, RequestChange, Status, PostalCode,
from spaceauth import current_user
import enum
import decimal
from flask_weasyprint import HTML, render_pdf
from sqlalchemy import inspect, func
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.attributes import get_history
@ -151,6 +152,14 @@ class FaceshieldRequestAdmin(ModelView):
state_after=after,
))
@flask_admin.expose('/label/')
def label(self):
return render_pdf(HTML(string=self.label_html()))
@flask_admin.expose('/label/html')
def label_html(self):
return self.render('label.html', model=self.get_one(request.args.get('id')))
class FilteredFaceshieldRequestAdmin(FaceshieldRequestAdmin):
def get_query(self):
return super(FilteredFaceshieldRequestAdmin, self).get_query().filter(FaceshieldRequest.status != Status.rejected, FaceshieldRequest.status != Status.spam)

View File

@ -1,9 +1,14 @@
alembic==1.4.2
Babel==2.8.0
blinker==1.4
cairocffi==1.1.0
CairoSVG==2.4.2
certifi==2019.11.28
cffi==1.14.0
chardet==3.0.4
click==7.1.1
cssselect2==0.3.0
defusedxml==0.6.0
environs==7.3.1
Flask==1.1.1
Flask-Admin==1.5.5
@ -13,7 +18,9 @@ Flask-Migrate==2.5.3
Flask-OAuthlib==0.9.5
git+https://code.hackerspace.pl/informatic/flask-spaceauth#egg=Flask-SpaceAuth
Flask-SQLAlchemy==2.4.1
Flask-WeasyPrint==0.6
Flask-WTF==0.14.3
html5lib==1.0.1
idna==2.9
itsdangerous==1.1.0
Jinja2==2.11.1
@ -21,8 +28,11 @@ Mako==1.1.2
MarkupSafe==1.1.1
marshmallow==3.5.1
oauthlib==2.1.0
Pillow==6.2.1
prometheus-client==0.7.1
prometheus-flask-exporter==0.13.0
pycparser==2.20
Pyphen==0.9.5
python-dateutil==2.8.1
python-dotenv==0.12.0
python-editor==1.0.4
@ -31,6 +41,9 @@ requests==2.23.0
requests-oauthlib==1.3.0
six==1.14.0
SQLAlchemy==1.3.15
tinycss2==1.0.2
urllib3==1.25.8
WeasyPrint==51
webencodings==0.5.1
Werkzeug==0.16.1
WTForms==2.2.1

View File

@ -0,0 +1,6 @@
{% extends 'admin/model/list.html' %}
{% block list_row_actions %}
{{ super() }}
<a href="{{ url_for('map.index', id=row.id) }}" class="icon" title="Show on map"><span class="glyphicon glyphicon-map-marker"></span></a>
<a href="{{ url_for('faceshieldrequest.label', id=row.id) }}" class="icon" title="Render package label"><span class="glyphicon glyphicon-print"></span></a>
{% endblock %}

56
templates/label.html Normal file
View File

@ -0,0 +1,56 @@
<html>
<head>
<style>
@page {
margin: 0cm;
size: 15cm 10cm;
}
html, body {
padding: 0;
margin: 0;
width: 15cm;
height: 10cm;
font-family: "Lato";
font-size: 16pt
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
height: 10cm;
}
.line {
text-align: center;
vertical-align: middle;
width: 15cm;
padding: 0.5cm;
}
.mark {
background: #eee;
}
.idline {
font-size: 35pt;
}
</style>
</head>
<body>
<div class="container">
<div class="line idline">
{{ model.faceshield_full_delivered }} <b>#{{ model.id }}</b>
</div>
<div class="line mark">
{{ model.entity_info }}
</div>
<div class="line">
{{ model.full_name }} {{ model.phone_number }}
</div>
</div>
</body>
</html>