Skip to content

Commit

Permalink
Almet/qrcode (#1000)
Browse files Browse the repository at this point in the history
Add a QRCode utility to join the project.
  • Loading branch information
almet authored May 11, 2022
1 parent dc6cead commit 936ea0e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ihatemoney/templates/send_invites.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ <h3>{{ _('Share the Link') }}</h3>
</a>
</td>
</tr>
<tr>
<td>
<h3>{{ _('Scan QR code') }}</h3>
<p><small>{% trans download_mobile=url_for(".mobile") %}On a mobile device, with <a href="{{ download_mobile }}">a compatible app installed</a>.{% endtrans %}</small></p>
</td>
<td>
{{ qrcode | safe }}
</td>
</tr>
<tr>
<td>
<h3>{{ _('Send via Emails') }}</h3>
Expand Down
21 changes: 20 additions & 1 deletion ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
and `add_project_id` for a quick overview)
"""
from functools import wraps
from io import StringIO
import json
import os
from urllib.parse import urlparse, urlunparse

from flask import (
Blueprint,
Expand All @@ -28,6 +30,8 @@
)
from flask_babel import gettext as _
from flask_mail import Message
import qrcode
import qrcode.image.svg
from sqlalchemy_continuum import Operation
from werkzeug.exceptions import NotFound
from werkzeug.security import check_password_hash, generate_password_hash
Expand Down Expand Up @@ -586,7 +590,22 @@ def invite():
"Sorry, there was an error while trying to send the invitation emails."
)
# Fall-through: we stay on the same page and display the form again
return render_template("send_invites.html", form=form)

# Generate the SVG QRCode.
invite_link = url_for(
".join_project",
project_id=g.project.id,
token=g.project.generate_token(),
_external=True,
)
invite_link = urlunparse(urlparse(invite_link)._replace(scheme="ihatemoney"))
qr = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage)
qr.add_data(invite_link)
qr.make(fit=True)
img = qr.make_image(attrib={"class": "qrcode"})
qrcode_svg = img.to_string().decode()

return render_template("send_invites.html", form=form, qrcode=qrcode_svg)


@main.route("/<project_id>/")
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install_requires =
Werkzeug>=2,<2.1 # See https://github.com/spiral-project/ihatemoney/pull/1015
itsdangerous>=2,<3
Jinja2>=3,<4
qrcode>=7,<8
requests>=2.22,<3
SQLAlchemy-Continuum>=1.3.12,<2
SQLAlchemy>=1.3.0,<1.4 # New 1.4 changes API, see #728
Expand Down

0 comments on commit 936ea0e

Please sign in to comment.