92 lines
1.9 KiB
Python
92 lines
1.9 KiB
Python
from hserver.api import WebObject,Persistence,WebFolder,WebCallable
|
|
import hserver
|
|
|
|
import Templates
|
|
import uuid
|
|
import os
|
|
import io
|
|
import time
|
|
|
|
|
|
class Artikel(WebObject,Persistence):
|
|
|
|
_public_names = {
|
|
"bezeichnung": "",
|
|
"bezeichnung2": "",
|
|
"preis": 0.00,
|
|
"beschreibung": "",
|
|
"seriennummer": "",
|
|
"bemerkungen": "",
|
|
"verkauft": False,
|
|
"bezahlt": False,
|
|
"erloes": 0.00
|
|
}
|
|
_public_types = {
|
|
"preis": float,
|
|
"verkauft": bool,
|
|
"bezahlt": bool,
|
|
"erloes": float
|
|
}
|
|
|
|
#tag = Templates.artikel_tag_html
|
|
|
|
def __init__(self,vid):
|
|
WebObject.__init__(self)
|
|
|
|
self.id = uuid.uuid4().hex
|
|
self.vid = vid
|
|
self.update(None)
|
|
|
|
|
|
def __call__(self,request,o=None):
|
|
Templates.artikel_display_html(request,self)
|
|
|
|
def verkaeufer(self):
|
|
vl = self._aq_parent._aq_parent.verkaeufer
|
|
v = getattr( vl, self.vid, None)
|
|
return v
|
|
|
|
def _tag(self,request,o=None):
|
|
_io = io.StringIO()
|
|
Templates.artikel_tag_html(request,o,output=_io)
|
|
|
|
if "printer" in request.getForm():
|
|
prn = request.getForm()["printer"].value()
|
|
else:
|
|
prn = None
|
|
|
|
pcmd = None
|
|
if prn in self.printers:
|
|
pcmd = self.printers[prn]
|
|
|
|
print("TAG Print: {0} / {1}".format(prn,pcmd))
|
|
|
|
|
|
tmphtml = "/tmp/print.{0}.html".format(time.time())
|
|
tmppdf = tmphtml + ".pdf"
|
|
|
|
tmp = open(tmphtml,"w")
|
|
tmp.write(_io.getvalue())
|
|
tmp.close()
|
|
|
|
os.system("wkhtmltopdf -T 0 -B 0 -L 0 -R 0 --dpi 400 --print-media-type --page-width 96mm --page-height 48mm {0} {1}".format(tmphtml,tmppdf))
|
|
#os.system("lpr -P SII_SLP440 {0}".format(tmppdf))
|
|
if pcmd is None:
|
|
request.reset()
|
|
tp = open(tmppdf,"rb")
|
|
pdf = tp.read()
|
|
tp.close()
|
|
|
|
request.getBinaryContentFile().write(pdf)
|
|
request.setResponseHeader("content-type","application/pdf")
|
|
else:
|
|
os.system(pcmd.format(tmppdf))
|
|
request.redirect(request.self(-1))
|
|
|
|
tag = WebCallable(method=_tag)
|
|
|
|
def __str__(self):
|
|
return self.bezeichnung
|
|
|
|
|