Generating pritable labels
This commit is contained in:
+20
-4
@@ -6,7 +6,8 @@ from io import BytesIO
|
||||
import json, random, re, string
|
||||
|
||||
app = Flask(__name__)
|
||||
systemURL = 'http://192.168.0.11:5000/'
|
||||
systemURL = 'http://192.168.0.11:5000/' #FULL URL with a '/' at the end
|
||||
systemURL = 'http://10.0.1.115:5000/'
|
||||
randomchars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' #note the lack of zero
|
||||
|
||||
with open('links.json', 'r') as infile:
|
||||
@@ -23,7 +24,7 @@ def randomToken():
|
||||
return code
|
||||
|
||||
def codeValidation(code):
|
||||
if len(code) not in range (5,6):
|
||||
if len(code) not in range (3,10):
|
||||
return False
|
||||
if re.match('^[\w-]+$', code) is None:
|
||||
return False
|
||||
@@ -55,7 +56,15 @@ def serveCode(code):
|
||||
code = code[:code.find('.')]
|
||||
if codeValidation(code) is False:
|
||||
return send_file('static/invalid.png', mimetype='image/png')
|
||||
img = qrcode.make(systemURL + code)
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
||||
box_size=8,
|
||||
border=3,
|
||||
)
|
||||
qr.add_data('systemURL + code')
|
||||
qr.make(fit=True)
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
return serveImage(img)
|
||||
|
||||
@app.route("/edit", methods=['GET', 'POST'])
|
||||
@@ -87,7 +96,14 @@ def generate():
|
||||
howmany = request.form.get("howmany")
|
||||
if howmany is None:
|
||||
return render_template('generate.html')
|
||||
return render_template("message.html", message="Totally generated {} many codes right now.".format(howmany))
|
||||
codes = []
|
||||
for i in range(0, int(howmany)):
|
||||
codes.append(createNewCode())
|
||||
columns = 4
|
||||
codesarray = [codes[i:i+columns] for i in range(0, len(codes), columns)]
|
||||
saveFile()
|
||||
humanSystemURL = systemURL[systemURL.find('//')+2:]
|
||||
return render_template("printlabels.html", codes=codesarray, systemURL=humanSystemURL, codegenURL=systemURL+'code/', format='.png')
|
||||
|
||||
@app.route("/list")
|
||||
def list():
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
body {
|
||||
font-size: small;
|
||||
color: #3B3B3B;
|
||||
font-family: "Lucida Console", Monaco, monospace;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
td {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 1px;
|
||||
padding: 0px;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
{% block content %}
|
||||
<form action=/generate method="post">
|
||||
How many?:<br />
|
||||
<input type="number" name="howmany" value="20"/><br />
|
||||
<input type="number" name="howmany" value="16"/><br />
|
||||
<button type="submit" class="graybar" >Generate </button><br />
|
||||
Note: It is best to print the generated codes immediatly from the result of this generation.
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Printing QR labels</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='printstyle.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
{% for row in codes %}
|
||||
<tr>
|
||||
{% for code in row %}
|
||||
<td>
|
||||
<img src="{{codegenURL}}{{code}}{{format}}" />
|
||||
<p>ELAB KNOWLEDGE SYSTEM</p>
|
||||
<p>{{systemURL}}{{code}}</p>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user