Changeset - ade19bdcb84a
[Not reviewed]
crypto
0 4 0
Dennis Fink - 3 years ago 2022-01-19 18:22:05
dennis.fink@c3l.lu
Implement new conversion method for cryptocurrencies
4 files changed with 92 insertions and 17 deletions:
0 comments (0 inline, 0 general)
c3l_membership/templates/member.html
Show inline comments
 
@@ -62,13 +62,13 @@
 
      <div>
 
        <div>{% trans %}Starving:{% endtrans %}</div>
 
        <div>{{ _("Yes") if form.starving.data else _("No") }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Payment:{% endtrans %}</div>
 
        <div>{{ form.payment.data }}</div>
 
        <div>{{ form.payment.data.lower() }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Agreed to Terms &amp; Conditions:{% endtrans %}</div>
 
        <div>{{ _("Yes") if form.terms.data else _("No") }}</div>
 
      </div>
 
      <div>
 
@@ -94,13 +94,14 @@
 
            <li><b>{% trans %}Address:{% endtrans %}</b> {{ config["CRYPTOCURRENCIES"][form.payment.data]["ADDRESS"] }}</li>
 
            <li><b>{% trans %}Label:{% endtrans %}</b> Membership Fee</li>
 
            <li><b>{% trans %}Message:{% endtrans %}</b> {{ year }} {{ form.username.data }}</li>
 
            <li><b>{% trans %}Amount:{% endtrans %}</b> {{ price }} {{ config["CRYPTOCURRENCIES"][form.payment.data]["COMMODITY"] }}</li>
 
          </ul>
 
        </div>
 
        {% set crypto_url=config["CRYPTOCURRENCIES"][form.payment.data]["URL"].format(amount=price, year=year, username=form.username.data) %}
 
        {% set address = config["CRYPTOCURRENCIES"][form.payment.data]["ADDRESS"] %}
 
        {% set crypto_url=config["CRYPTOCURRENCIES"][form.payment.data]["URL"].format(address=address, amount=price, year=year, username=form.username.data) %}
 
        <div><img class="cryptoqrcode" src="{{ qrcode(crypto_url) }}" /></div>
 
      </div>
 
    {% elif form.payment.data == 'digicash' %}
 
      <div class="digicash">
 
        {% set digicash_url='https://pos.digica.sh/qrcode/generator?merchantId=CHAOSPC1&amount={amount}&transactionReference=Membership_{username}'.format(amount=price, username=form.username.data) %}
 
        <div><p>{% trans %}Pay with digicash!{% endtrans %}</p></div>
c3l_membership/views.py
Show inline comments
 
import re
 
import subprocess
 
from datetime import date
 

	
 
import requests
 
from flask import Blueprint, current_app, g, render_template, request
 
from flask_babel import gettext
 
from flask_weasyprint import HTML, render_pdf
 

	
 
from .forms import MembershipForm
 

	
 
@@ -39,13 +40,13 @@ def index():
 

	
 
    for cryptocurrency_label, options in current_app.config["CRYPTOCURRENCIES"].items():
 
        if options["ENABLED"]:
 
            choices.append(
 
                (
 
                    cryptocurrency_label,
 
                    " ".format((gettext("by"), options)),
 
                    " ".join((gettext("by"), cryptocurrency_label.title())),
 
                ),
 
            )
 

	
 
    form.payment.choices = choices
 

	
 
    if form.validate_on_submit():
 
@@ -62,20 +63,21 @@ def index():
 
        elif form.membership.data == "regular":
 
            price = current_app.config["REGULAR_FEE"]
 
            xml_data["voting"] = 1
 

	
 
        if form.starving.data:
 
            price = 1
 
            xml_data["status"] = "Starving"
 
            status = "Starving"
 
        elif form.minor_member.data or form.student.data:
 
            xml_data["status"] = "Student"
 
            status = "Student"
 
        elif form.membership.data == "supporting":
 
            xml_data["status"] = "Supporter"
 
            status = "Supporter"
 
        else:
 
            xml_data["status"] = "Regular"
 
            status = "Regular"
 

	
 
        xml_data["status"] = status
 
        xml_data["name"] = form.fullname.data
 
        xml_data["birthday"] = (
 
            form.birthday.data if form.birthday.data is not None else date(9999, 12, 12)
 
        )
 
        xml_data["username"] = form.username.data
 
        xml_data["email"] = form.email.data
 
@@ -88,21 +90,26 @@ def index():
 
                form.country.data,
 
            )
 
        )
 
        xml_data["address"] = re.sub("\s+", " ", xml_data["address"])
 

	
 
        if form.payment.data in current_app.config["CRYPTOCURRENCIES"]:
 
            price = subprocess.run(
 
                [
 
                    current_app.config["CRYPTOCURRENCIES_CONVERSION_SCRIPT"],
 
                    str(price),
 
                    form.payment.data,
 
                ],
 
                capture_output=True,
 
                encoding="utf-8",
 
            ).stdout
 

	
 
            current_conversion_r = requests.get(
 
                current_app.config["CONVERSION_URL"], timeout=30
 
            )
 
            try:
 
                current_conversion_r.raise_for_status()
 
            except:
 
                return 500
 
            else:
 
                current_conversion = current_conversion_r.json()
 
                commodity = current_app.config["CRYPTOCURRENCIES"][form.payment.data][
 
                    "COMMODITY"
 
                ]
 
                price = current_conversion[commodity][status.upper()]
 
        elif form.payment.data == "digicash":
 
            price = price * 100
 

	
 
        now = date.today()
 
        year = now.year
 
        xml_data["date"] = now
poetry.lock
Show inline comments
 
@@ -69,23 +69,42 @@ tinycss2 = "*"
 

	
 
[package.extras]
 
doc = ["sphinx", "sphinx-rtd-theme"]
 
test = ["pytest-runner", "pytest-cov", "pytest-flake8", "pytest-isort"]
 

	
 
[[package]]
 
name = "certifi"
 
version = "2021.10.8"
 
description = "Python package for providing Mozilla's CA Bundle."
 
category = "main"
 
optional = false
 
python-versions = "*"
 

	
 
[[package]]
 
name = "cffi"
 
version = "1.15.0"
 
description = "Foreign Function Interface for Python calling C code."
 
category = "main"
 
optional = false
 
python-versions = "*"
 

	
 
[package.dependencies]
 
pycparser = "*"
 

	
 
[[package]]
 
name = "charset-normalizer"
 
version = "2.0.10"
 
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
 
category = "main"
 
optional = false
 
python-versions = ">=3.5.0"
 

	
 
[package.extras]
 
unicode_backport = ["unicodedata2"]
 

	
 
[[package]]
 
name = "click"
 
version = "8.0.3"
 
description = "Composable command line interface toolkit"
 
category = "main"
 
optional = false
 
python-versions = ">=3.6"
 
@@ -425,12 +444,30 @@ all = ["zest.releaser", "tox", "pytest",
 
dev = ["tox", "pytest"]
 
maintainer = ["zest.releaser"]
 
pil = ["pillow"]
 
test = ["pytest", "pytest-cov"]
 

	
 
[[package]]
 
name = "requests"
 
version = "2.27.1"
 
description = "Python HTTP for Humans."
 
category = "main"
 
optional = false
 
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
 

	
 
[package.dependencies]
 
certifi = ">=2017.4.17"
 
charset-normalizer = {version = ">=2.0.0,<2.1.0", markers = "python_version >= \"3\""}
 
idna = {version = ">=2.5,<4", markers = "python_version >= \"3\""}
 
urllib3 = ">=1.21.1,<1.27"
 

	
 
[package.extras]
 
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
 
use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"]
 

	
 
[[package]]
 
name = "six"
 
version = "1.16.0"
 
description = "Python 2 and 3 compatibility utilities"
 
category = "main"
 
optional = false
 
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
 
@@ -472,12 +509,25 @@ version = "4.0.1"
 
description = "Backported and Experimental Type Hints for Python 3.6+"
 
category = "main"
 
optional = false
 
python-versions = ">=3.6"
 

	
 
[[package]]
 
name = "urllib3"
 
version = "1.26.8"
 
description = "HTTP library with thread-safe connection pooling, file post, and more."
 
category = "main"
 
optional = false
 
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
 

	
 
[package.extras]
 
brotli = ["brotlipy (>=0.6.0)"]
 
secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
 
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
 

	
 
[[package]]
 
name = "weasyprint"
 
version = "52.5"
 
description = "The Awesome Document Factory"
 
category = "main"
 
optional = false
 
python-versions = ">=3.6"
 
@@ -541,13 +591,13 @@ python-versions = ">=3.6"
 
docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
 
testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]
 

	
 
[metadata]
 
lock-version = "1.1"
 
python-versions = ">=3.7.0,<4"
 
content-hash = "e6337b7e5ae01abe852dbd202497fef50c09546e0a0f98f26b3ee81beb262237"
 
content-hash = "09986a21dfa3c1e41f48db17b04f4f3bade80e86642fecd895ad3df4b9cf061e"
 

	
 
[metadata.files]
 
babel = [
 
    {file = "Babel-2.9.1-py2.py3-none-any.whl", hash = "sha256:ab49e12b91d937cd11f0b67cb259a57ab4ad2b59ac7a3b41d6c06c0ac5b0def9"},
 
    {file = "Babel-2.9.1.tar.gz", hash = "sha256:bc0c176f9f6a994582230df350aa6e05ba2ebe4b3ac317eab29d9be5d2768da0"},
 
]
 
@@ -559,12 +609,16 @@ cairocffi = [
 
    {file = "cairocffi-1.3.0.tar.gz", hash = "sha256:108a3a7cb09e203bdd8501d9baad91d786d204561bd71e9364e8b34897c47b91"},
 
]
 
cairosvg = [
 
    {file = "CairoSVG-2.5.2-py3-none-any.whl", hash = "sha256:98c276b7e4f0caf01e5c7176765c104ffa1aa1461d63b2053b04ab663cf7052b"},
 
    {file = "CairoSVG-2.5.2.tar.gz", hash = "sha256:b0b9929cf5dba005178d746a8036fcf0025550f498ca54db61873322384783bc"},
 
]
 
certifi = [
 
    {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"},
 
    {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"},
 
]
 
cffi = [
 
    {file = "cffi-1.15.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:c2502a1a03b6312837279c8c1bd3ebedf6c12c4228ddbad40912d671ccc8a962"},
 
    {file = "cffi-1.15.0-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:23cfe892bd5dd8941608f93348c0737e369e51c100d03718f108bf1add7bd6d0"},
 
    {file = "cffi-1.15.0-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:41d45de54cd277a7878919867c0f08b0cf817605e4eb94093e7516505d3c8d14"},
 
    {file = "cffi-1.15.0-cp27-cp27m-win32.whl", hash = "sha256:4a306fa632e8f0928956a41fa8e1d6243c71e7eb59ffbd165fc0b41e316b2474"},
 
    {file = "cffi-1.15.0-cp27-cp27m-win_amd64.whl", hash = "sha256:e7022a66d9b55e93e1a845d8c9eba2a1bebd4966cd8bfc25d9cd07d515b33fa6"},
 
@@ -611,12 +665,16 @@ cffi = [
 
    {file = "cffi-1.15.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3f7d084648d77af029acb79a0ff49a0ad7e9d09057a9bf46596dac9514dc07df"},
 
    {file = "cffi-1.15.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ef1f279350da2c586a69d32fc8733092fd32cc8ac95139a00377841f59a3f8d8"},
 
    {file = "cffi-1.15.0-cp39-cp39-win32.whl", hash = "sha256:2a23af14f408d53d5e6cd4e3d9a24ff9e05906ad574822a10563efcef137979a"},
 
    {file = "cffi-1.15.0-cp39-cp39-win_amd64.whl", hash = "sha256:3773c4d81e6e818df2efbc7dd77325ca0dcb688116050fb2b3011218eda36139"},
 
    {file = "cffi-1.15.0.tar.gz", hash = "sha256:920f0d66a896c2d99f0adbb391f990a84091179542c205fa53ce5787aff87954"},
 
]
 
charset-normalizer = [
 
    {file = "charset-normalizer-2.0.10.tar.gz", hash = "sha256:876d180e9d7432c5d1dfd4c5d26b72f099d503e8fcc0feb7532c9289be60fcbd"},
 
    {file = "charset_normalizer-2.0.10-py3-none-any.whl", hash = "sha256:cb957888737fc0bbcd78e3df769addb41fd1ff8cf950dc9e7ad7793f1bf44455"},
 
]
 
click = [
 
    {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"},
 
    {file = "click-8.0.3.tar.gz", hash = "sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"},
 
]
 
colorama = [
 
    {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
 
@@ -844,12 +902,16 @@ pytz = [
 
    {file = "pytz-2021.3-py2.py3-none-any.whl", hash = "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c"},
 
    {file = "pytz-2021.3.tar.gz", hash = "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326"},
 
]
 
qrcode = [
 
    {file = "qrcode-7.3.1.tar.gz", hash = "sha256:375a6ff240ca9bd41adc070428b5dfc1dcfbb0f2507f1ac848f6cded38956578"},
 
]
 
requests = [
 
    {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"},
 
    {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"},
 
]
 
six = [
 
    {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
 
    {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
 
]
 
tinycss2 = [
 
    {file = "tinycss2-1.1.1-py3-none-any.whl", hash = "sha256:fe794ceaadfe3cf3e686b22155d0da5780dd0e273471a51846d0a02bc204fec8"},
 
@@ -881,12 +943,16 @@ typed-ast = [
 
    {file = "typed_ast-1.5.1.tar.gz", hash = "sha256:484137cab8ecf47e137260daa20bafbba5f4e3ec7fda1c1e69ab299b75fa81c5"},
 
]
 
typing-extensions = [
 
    {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"},
 
    {file = "typing_extensions-4.0.1.tar.gz", hash = "sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"},
 
]
 
urllib3 = [
 
    {file = "urllib3-1.26.8-py2.py3-none-any.whl", hash = "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed"},
 
    {file = "urllib3-1.26.8.tar.gz", hash = "sha256:0e7c33d9a63e7ddfcb86780aac87befc2fbddf46c58dbb487e0855f7ceec283c"},
 
]
 
weasyprint = [
 
    {file = "WeasyPrint-52.5-py3-none-any.whl", hash = "sha256:3433d657049a65d7d63f545fd71f5efa8aae7f05d24e49e01a757973fd3799f1"},
 
    {file = "WeasyPrint-52.5.tar.gz", hash = "sha256:b37ea02d75ca04babd7becad7341426be332ae560d8f02d664bfa1e9afb18481"},
 
]
 
webencodings = [
 
    {file = "webencodings-0.5.1-py2.py3-none-any.whl", hash = "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78"},
pyproject.toml
Show inline comments
 
@@ -14,12 +14,13 @@ Flask-WeasyPrint = "^0.6"
 
Flask-WTF = "^1.0.0"
 
email-validator = "^1.1.3"
 
WTForms="^3.0.1"
 
WeasyPrint="52.5"
 
djhtml = "^1.4.11"
 
Flask-Babel = "^2.0.0"
 
requests = "^2.27.1"
 

	
 
[tool.poetry.dev-dependencies]
 
black = "^21.12b0"
 
mypy = "^0.930"
 
isort = "^5.10.1"
 

	
0 comments (0 inline, 0 general)