Skip to content
Snippets Groups Projects
Select Git revision
  • b9ccfd55a35dd8ee125554d76af7e5d1a7324375
  • master default protected
  • claims-in-idtoke
  • jwt_encode_inconsistencies
  • recovery-code-pwhash
  • incremental-sync
  • redis-rate-limits
  • typehints
  • v1.2.x
  • v1.x.x
  • v1.1.x
  • feature_invite_validuntil_minmax
  • Dockerfile
  • v1.0.x
  • roles-recursive-cte
  • v2.3.1
  • v2.3.0
  • v2.2.0
  • v2.1.0
  • v2.0.1
  • v2.0.0
  • v1.2.0
  • v1.1.2
  • v1.1.1
  • v1.0.2
  • v1.1.0
  • v1.0.1
  • v1.0.0
  • v0.3.0
  • v0.2.0
  • v0.1.5
  • v0.1.4
  • v0.1.2
33 results

create_db.py

Blame
  • Forked from uffd / uffd
    Source project has a limited visibility.
    template_helper.py 1.22 KiB
    import random
    import base64
    from datetime import timedelta, datetime
    import io
    
    from flask import Markup
    
    import qrcode
    import qrcode.image.svg
    
    def register_template_helper(app):
    	# debian ships jinja2 without this test...
    	def equalto(a, b):
    		return a == b
    
    	@app.template_filter()
    	def qrcode_svg(content, **attrs): #pylint: disable=unused-variable
    		img = qrcode.make(content, image_factory=qrcode.image.svg.SvgPathImage, border=0)
    		svg = img.get_image()
    		for key, value, in attrs.items():
    			svg.set(key, value)
    		buf = io.BytesIO()
    		img.save(buf)
    		return Markup(buf.getvalue().decode().replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n', '').replace(' id="qr-path" ', ' '))
    
    	@app.template_filter()
    	def datauri(data, mimetype='text/plain'): #pylint: disable=unused-variable
    		return Markup('data:%s;base64,%s'%(mimetype, base64.b64encode(data.encode()).decode()))
    
    	app.jinja_env.trim_blocks = True
    	app.jinja_env.lstrip_blocks = True
    
    	app.add_template_global(random.randint, name='randint')
    	app.add_template_global(datetime, name='datetime')
    	app.add_template_global(timedelta, name='timedelta')
    	app.add_template_global(min, name='min')
    	app.add_template_global(max, name='max')
    	app.add_template_global(equalto, name='equalto')