def hello(): if request.method == 'POST': json_str = request.form["text"] for character in escape_characters: json_str = json_str.replace(character, escape_characters[character]) if "verbatim" in request.form.keys(): return redirect(url_for('print_document'), code=307) else: document = JsonDocument(json_str) print type(document.get_printable_string()) # from http://stackoverflow.com/questions/13303464/can-flask-using-jinja2-render-templates-using-windows-1251-encoding r = Response() r.data = render_template('preview.html', text=document.main_string, json_str=json.dumps(json_str)) return r else: return render_template('index.html')
def print_document(): json_str = request.form['text'] print type(json_str) response_str = "Your printer should be making some noise!!" print_fp = open("print.txt", "w") # try: if platform.system() == 'Windows': if "verbatim" in request.form.keys(): json_str = json_str.encode('utf8') for character in spanish_characters: json_str = json_str.replace(character, spanish_characters[character]) print_fp.write(json_str) else: document = JsonDocument(json_str) print document.get_printable_string() print_fp.write(document.get_printable_string()) print_fp.close() os.system('RawPrinterConsole print.txt') else: epson = printer.Usb(0x4b8, 0x5) epson.set(codepage='iso8859_9', font='c') if "verbatim" in request.form.keys(): json_str = json_str.encode('utf8') for character in spanish_characters: json_str = json_str.replace(character, spanish_characters[character]) epson._raw(json_str) else: document = JsonDocument(json_str) epson._raw(document.get_printable_string()) #except Exception, e: # response_str = "Error: " + str(e) #finally: # try: # epson.close() # except NameError: # pass return response_str