Add QR code to item detail view
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2024-07-28 13:58:39 +03:00
parent a60a540408
commit c06db59898
3 changed files with 17 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import markdown
import pymongo import pymongo
import requests import requests
import safe import safe
import segno
from flask import Flask, abort, g, make_response, redirect, render_template, request, session from flask import Flask, abort, g, make_response, redirect, render_template, request, session
from flask_wtf import FlaskForm, RecaptchaField from flask_wtf import FlaskForm, RecaptchaField
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
@ -101,6 +102,10 @@ def render_user_link(item):
def is_list(value): def is_list(value):
return isinstance(value, list) return isinstance(value, list)
def render_qr_code(slug):
qr = segno.make(str("http://k6.ee/" + slug), micro=False, mode='byte', mask=3, error='L', boost_error=False)
return Markup(qr.svg_inline(light='black', dark='yellow', scale=3, border=1))
jinja2.filters.FILTERS['format_name'] = format_name jinja2.filters.FILTERS['format_name'] = format_name
jinja2.filters.FILTERS['markdown'] = render_markdown jinja2.filters.FILTERS['markdown'] = render_markdown
jinja2.filters.FILTERS['timeago'] = render_timeago jinja2.filters.FILTERS['timeago'] = render_timeago
@ -111,6 +116,8 @@ jinja2.filters.FILTERS['is_list'] = is_list
jinja2.filters.FILTERS['quote_plus'] = lambda u: urllib.parse.quote_plus(u) jinja2.filters.FILTERS['quote_plus'] = lambda u: urllib.parse.quote_plus(u)
jinja2.filters.FILTERS['check_foreign_key_format'] = check_foreign_key_format jinja2.filters.FILTERS['check_foreign_key_format'] = check_foreign_key_format
jinja2.filters.FILTERS['display_name'] = render_user_display_name jinja2.filters.FILTERS['display_name'] = render_user_display_name
jinja2.filters.FILTERS['qr_code'] = render_qr_code
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))

View File

@ -89,6 +89,15 @@
</td> </td>
</tr> </tr>
<tr>
<td>QR Code (WIP)</td>
<td>
{% if item.get("shortener").slug %}
{{ item.get("shortener", {}).get("slug") | qr_code }}
{% endif %}
</td>
</tr>
<tr> <tr>
<td>Issue tracker</td> <td>Issue tracker</td>
<td><a href="{{ item.issue_tracker }}">Issue tracker</a></td> <td><a href="{{ item.issue_tracker }}">Issue tracker</a></td>

View File

@ -10,6 +10,7 @@ markdown
pytz pytz
requests requests
safe safe
segno
sepa sepa
Flask-WTF Flask-WTF
prometheus-flask-exporter prometheus-flask-exporter