+
A lemotdepasse is needed
+
lemotdepasse
+
+
+
+ `);
+
+ appbody
+ .append(lemotdepasse)
+ .append(block)
+ .append(action);
+
+ $(".modal").modal();
+});
\ No newline at end of file
diff --git a/static/zetikettes.js b/static/zetikettes.js
index fceafff..e1bd1e0 100644
--- a/static/zetikettes.js
+++ b/static/zetikettes.js
@@ -3,275 +3,6 @@ const backend_api = {
'dev': '/zetikettes.dev/srv/',
}[config];
-const zetikettes = [
- {
- 'title': 'Aromate herbes de Provence',
- 'sticker': 'Aromate - Herbes de Provence.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': false,
- },
- {
- 'title': 'Aromate herbes de Provence avec romarin',
- 'sticker': 'Aromate - Herbes de Provence avec romarin.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': false,
- },
- {
- 'title': 'Aromate thym',
- 'sticker': 'Aromate - Thym.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': false,
- },
- {
- 'title': 'Chocolat lavande',
- 'sticker': 'Chocolat - Lavande.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '100',
- },
- 'landscape': false,
- },
- {
- 'title': 'Confiture de Mirabelle - non bio',
- 'sticker': 'Confiture - Mirabelle.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'fruit': '80',
- 'teneur': '50',
- 'lot': '0000-0',
- 'qty': '370',
- },
- 'landscape': true,
- },
- {
- 'title': 'Gelée Extra de groseille',
- 'sticker': 'Gelée Extra - Groseille.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'fruit': '80',
- 'teneur': '50',
- 'lot': '0000-0',
- 'qty': '370',
- },
- 'landscape': true,
- },
- {
- 'title': 'Gelée Extra de groseille au basilic',
- 'sticker': 'Gelée Extra - Groseille Basilic.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'fruit': '80',
- 'teneur': '50',
- 'lot': '0000-0',
- 'qty': '370',
- },
- 'landscape': true,
- },
- {
- 'title': 'Gelée Extra de cassis',
- 'sticker': 'Gelée Extra - Cassis.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'fruit': '80',
- 'teneur': '50',
- 'lot': '0000-0',
- 'qty': '370',
- },
- 'landscape': true,
- },
- {
- 'title': 'Pesto ail des ours',
- 'sticker': 'Pesto - Ail des Ours - 100% Olive.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '150',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sel grillade et légumes',
- 'sticker': 'Sel - Grillade.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sel herbes de Provence',
- 'sticker': 'Sel - Herbes de Provence.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sel viande blanche et poisson',
- 'sticker': 'Sel - Poisson et Viande Blanche.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sel salade',
- 'sticker': 'Sel - Salade.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sel salade sans basilic',
- 'sticker': 'Sel - Salade - Sans Basilic.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '40',
- },
- 'landscape': true,
- },
- {
- 'title': 'Sirop de sureau',
- 'sticker': 'Sirop - Sureau.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- },
- {
- 'title': 'Sirop de lavande',
- 'sticker': 'Sirop - Lavande.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- },
- {
- 'title': 'Sirop de cassis',
- 'sticker': 'Sirop - Cassis.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- 'landscape': false,
- },
- {
- 'title': 'Sirop de thym',
- 'sticker': 'Sirop - Thym.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- 'landscape': false,
- },
- {
- 'title': 'Sirop de mélisse',
- 'sticker': 'Sirop - Melisse.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- 'landscape': false,
- },
- {
- 'title': 'Sirop de menthe verte',
- 'sticker': 'Sirop - Menthe Verte.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '75',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane Hiver',
- 'sticker': 'Tisane - Hiver.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane Joie de Vivre',
- 'sticker': 'Tisane - Joie de Vivre.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane Réconfort de la Gorge (Origan, Thym, Agastache, Mauve)',
- 'sticker': 'Tisane - Reconfort de la Gorge - Origan Thym Agastache Mauve.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane Nuit Étoilée (Mélisse, Lavande, Aubépine)',
- 'sticker': 'Tisane - Nuit Etoilee - Melisse Lavande Aubepine.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane Détox (Menthe, Sarriette, Basilic, Souci)',
- 'sticker': 'Tisane - Detox - Menthe Sarriette Basilic Souci.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
- {
- 'title': 'Tisane digestion',
- 'sticker': 'Tisane - Digestion.svg',
- 'subs': {
- 'dluo': 'germinal 9999',
- 'lot': '0000-0',
- 'qty': '25',
- },
- 'landscape': false,
- },
-];
-
const params = {
'dluo': 'DLUO',
'lot': 'Nº de lot',
@@ -281,7 +12,7 @@ const params = {
'fruit': 'Quantité de fruits pour 100g (g)',
}
-$(document).ready(() => {
+function loadAll(zetikettes) {
const appbody = $("#appbody");
for (let zett of zetikettes) {
const block = $('
');
@@ -331,4 +62,18 @@ $(document).ready(() => {
}
$('.collapsible').collapsible();
-});
+}
+
+$(document).ready(async () => {
+ try {
+ const resp = await $.ajax({
+ url: backend_api + 'list',
+ timeout: 1000,
+ });
+ loadAll(resp.tikettes);
+ } catch(e) {
+ const appbody = $("#appbody");
+ appbody.append(`
Could not reach backend server`);
+ throw e;
+ }
+});
\ No newline at end of file
diff --git a/tikettes.json b/tikettes.json
new file mode 100644
index 0000000..7ec6814
--- /dev/null
+++ b/tikettes.json
@@ -0,0 +1 @@
+[{"title":"Aromate herbes de Provence","sticker":"Aromate - Herbes de Provence.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":false},{"title":"Aromate herbes de Provence avec romarin","sticker":"Aromate - Herbes de Provence avec romarin.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":false},{"title":"Aromate thym","sticker":"Aromate - Thym.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":false},{"title":"Chocolat lavande","sticker":"Chocolat - Lavande.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"100"},"landscape":false},{"title":"Confiture de Mirabelle - non bio","sticker":"Confiture - Mirabelle.svg","subs":{"dluo":"germinal 9999","fruit":"80","teneur":"50","lot":"0000-0","qty":"370"},"landscape":true},{"title":"Gelée Extra de groseille","sticker":"Gelée Extra - Groseille.svg","subs":{"dluo":"germinal 9999","fruit":"80","teneur":"50","lot":"0000-0","qty":"370"},"landscape":true},{"title":"Gelée Extra de groseille au basilic","sticker":"Gelée Extra - Groseille Basilic.svg","subs":{"dluo":"germinal 9999","fruit":"80","teneur":"50","lot":"0000-0","qty":"370"},"landscape":true},{"title":"Gelée Extra de cassis","sticker":"Gelée Extra - Cassis.svg","subs":{"dluo":"germinal 9999","fruit":"80","teneur":"50","lot":"0000-0","qty":"370"},"landscape":true},{"title":"Pesto ail des ours","sticker":"Pesto - Ail des Ours - 100% Olive.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"150"},"landscape":true},{"title":"Sel grillade et légumes","sticker":"Sel - Grillade.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":true},{"title":"Sel herbes de Provence","sticker":"Sel - Herbes de Provence.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":true},{"title":"Sel viande blanche et poisson","sticker":"Sel - Poisson et Viande Blanche.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":true},{"title":"Sel salade","sticker":"Sel - Salade.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":true},{"title":"Sel salade sans basilic","sticker":"Sel - Salade - Sans Basilic.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"40"},"landscape":true},{"title":"Sirop de sureau","sticker":"Sirop - Sureau.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"}},{"title":"Sirop de lavande","sticker":"Sirop - Lavande.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"}},{"title":"Sirop de cassis","sticker":"Sirop - Cassis.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"},"landscape":false},{"title":"Sirop de thym","sticker":"Sirop - Thym.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"},"landscape":false},{"title":"Sirop de mélisse","sticker":"Sirop - Melisse.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"},"landscape":false},{"title":"Sirop de menthe verte","sticker":"Sirop - Menthe Verte.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"75"},"landscape":false},{"title":"Tisane Hiver","sticker":"Tisane - Hiver.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false},{"title":"Tisane Joie de Vivre","sticker":"Tisane - Joie de Vivre.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false},{"title":"Tisane Réconfort de la Gorge (Origan, Thym, Agastache, Mauve)","sticker":"Tisane - Reconfort de la Gorge - Origan Thym Agastache Mauve.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false},{"title":"Tisane Nuit Étoilée (Mélisse, Lavande, Aubépine)","sticker":"Tisane - Nuit Etoilee - Melisse Lavande Aubepine.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false},{"title":"Tisane Détox (Menthe, Sarriette, Basilic, Souci)","sticker":"Tisane - Detox - Menthe Sarriette Basilic Souci.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false},{"title":"Tisane digestion","sticker":"Tisane - Digestion.svg","subs":{"dluo":"germinal 9999","lot":"0000-0","qty":"25"},"landscape":false}]
\ No newline at end of file
diff --git a/web.py b/web.py
index 9043868..0893545 100644
--- a/web.py
+++ b/web.py
@@ -1,5 +1,8 @@
+import argparse
from http.server import BaseHTTPRequestHandler, HTTPServer
+import io
import json
+import logging
import os
import re
import string
@@ -11,10 +14,22 @@ import traceback
from makesticker import makesticker
from makeplanche import makeplanche
+# defaults
PORT = 8000
OUT_DIR = tempfile.gettempdir()
-TEMPLATE_DIR = '/data'
+DATA_DIR = '/data'
+TEMPLATE_DIR = DATA_DIR
DEFAULT_DPI = 300
+LEMOTDEPASSE = 'je veux ajouter une étiquette'
+TIKETTES = os.path.join(DATA_DIR, 'tikettes.json')
+
+config = {}
+
+def tikettes_path():
+ return config.get('tikettes', TIKETTES)
+
+def template_dir():
+ return config.get('template_dir', TEMPLATE_DIR)
def inkscapize(svg_in, pdf_out):
@@ -31,7 +46,41 @@ def inkscapize(svg_in, pdf_out):
os.unlink(png_out)
-def parse_request(request):
+def handle_newtikette(formdata):
+ with open(tikettes_path()) as f:
+ tikettes = json.load(f)
+
+ sticker = formdata['title'] + '.svg'
+ with open(os.path.join(template_dir(), sticker), 'w') as f:
+ f.write(formdata['sticker'])
+
+ known_subs = {
+ "dluo": "germinal 9999",
+ "fruit": "80",
+ "teneur": "50",
+ "lot": "0000-0",
+ "qty": "370",
+ "vol": "50",
+ }
+
+ newtikette = {
+ 'title': formdata['title'],
+ 'sticker': sticker,
+ 'landscape': 'landscape' in formdata,
+ 'subs': {k: v for k, v in known_subs.items() if k in formdata},
+ }
+
+ logging.info(f'adding newtikette: {newtikette}')
+
+ tikettes.append(newtikette)
+
+ with open(tikettes_path(), 'w') as f:
+ json.dump(tikettes, f, indent=2)
+
+ return json.dumps({'status': 'ok', 'message': 'newtikette added'})
+
+
+def handle_generate(request):
request = json.loads(request)
# fill in sticker details
@@ -41,7 +90,7 @@ def parse_request(request):
with open(sticker_out, 'w') as stickout:
landscape = request.get('landscape', False)
print(f'landscape: {landscape}')
- makesticker(os.path.join(TEMPLATE_DIR, request['sticker']), stickout,
+ makesticker(os.path.join(template_dir(), request['sticker']), stickout,
request['subs'], landscape=landscape)
# make sticker sheet
@@ -65,8 +114,68 @@ def parse_request(request):
os.unlink(planche_out)
+def parse_multipart(data, boundary):
+ logging.debug(f'parsing data with boundary: {boundary}')
+ f = io.StringIO(data)
+ out = []
+
+ if boundary not in f.readline():
+ return out
+
+ while True:
+ headers = []
+ while True:
+ h = f.readline().strip()
+ try:
+ k, v = re.findall(r'^([a-zA-Z-]+): (.*)$', h)[0]
+ except IndexError:
+ break
+ headers.append((k, v))
+ metadata = None
+ otherheaders = []
+ logging.debug(headers)
+ for k, v in headers:
+ if k == 'Content-Disposition':
+ parts = v.split('; ')
+ if parts[0] != 'form-data':
+ continue
+ d = dict(re.findall(r'([^=]+)="(.*)"$', p)[0] for p in parts[1:])
+ metadata = d
+ else:
+ otherheaders.append((k, v))
+
+ value = io.StringIO()
+ while True:
+ l = f.readline()
+ if not l:
+ break
+ if boundary in l:
+# value.write(l.split(boundary)[0])
+ break
+ value.write(l)
+ if metadata is None:
+ break
+ logging.debug(f'({metadata}, {value.getvalue()[:-2]}, {otherheaders})')
+ out.append((metadata, value.getvalue()[:-2], otherheaders))
+
+ return out
+
+
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
+ logging.info(f'GET {self.path}')
+ if self.path == '/list':
+ self.send_response(200)
+ self.send_header("Content-type", "application/json")
+ self.send_header('Access-Control-Allow-Origin', '*')
+ self.end_headers()
+ with open(tikettes_path()) as f:
+ tikettes = json.load(f)
+
+ resp = {'status': 'ok', 'message': 'this is the way',
+ 'tikettes': tikettes}
+ self.wfile.write(json.dumps(resp).encode())
+ return
match = re.match(r'/data/(\w+\.pdf)', self.path)
if match is not None:
pdf_path = os.path.join(OUT_DIR, match.groups()[0])
@@ -89,14 +198,37 @@ class MyServer(BaseHTTPRequestHandler):
self.wfile.write("This is not the way.
".encode())
self.wfile.write(b"