From cc41527d07b6098aa9d671a533c704192797ad71 Mon Sep 17 00:00:00 2001 From: Mike_Went Date: Sat, 27 Jul 2024 01:00:24 +0400 Subject: [PATCH] improve form rendering, add description --- api/app/schemas/transaction.py | 2 ++ ui/app/controllers/entity.py | 14 +++++++-- ui/app/controllers/transaction.py | 21 ++++++++++++-- ui/app/static/style.css | 11 ++++++++ ui/app/templates/base.jinja2 | 2 +- ui/app/templates/form.jinja2 | 18 +++++++++--- ui/app/templates/transaction/add.jinja2 | 36 ++++++++---------------- ui/app/templates/transaction/edit.jinja2 | 2 +- 8 files changed, 70 insertions(+), 36 deletions(-) diff --git a/api/app/schemas/transaction.py b/api/app/schemas/transaction.py index 6a5252b..a025b01 100644 --- a/api/app/schemas/transaction.py +++ b/api/app/schemas/transaction.py @@ -48,6 +48,8 @@ def check_ids_are_different(self): class TransactionUpdateSchema(BaseUpdateSchema): + amount: Decimal | None = None + currency: str | None = None confirmed: bool | None = None diff --git a/ui/app/controllers/entity.py b/ui/app/controllers/entity.py index ec77562..5aa3ed1 100644 --- a/ui/app/controllers/entity.py +++ b/ui/app/controllers/entity.py @@ -10,10 +10,18 @@ class EntityForm(FlaskForm): - name = StringField("Name", validators=[DataRequired()]) + name = StringField( + "Name", + validators=[DataRequired()], + description="Unique, short identifier", + render_kw={"placeholder": "h4ck3r"}, + ) + telegram_id = StringField( + "Telegram ID", + description="Required for residents. Leave 0 for system entities. View ID: t.me/myidbot", + render_kw={"placeholder": "91827364"}, + ) comment = StringField("Comment") - telegram_id = StringField("Telegram ID") - active = BooleanField("Active", default=True) submit = SubmitField("Submit") diff --git a/ui/app/controllers/transaction.py b/ui/app/controllers/transaction.py index 73d2d6e..cbdf2c3 100644 --- a/ui/app/controllers/transaction.py +++ b/ui/app/controllers/transaction.py @@ -8,6 +8,7 @@ FloatField, HiddenField, IntegerField, + SelectField, StringField, SubmitField, ) @@ -21,10 +22,24 @@ class TransactionForm(FlaskForm): to_entity_name = StringField("To") from_entity_id = IntegerField("", validators=[DataRequired(), NumberRange(min=1)]) to_entity_id = IntegerField("", validators=[DataRequired(), NumberRange(min=1)]) - amount = FloatField("Amount", validators=[DataRequired()]) - currency = StringField("Currency", validators=[DataRequired()]) comment = StringField("Comment") - confirmed = BooleanField("Confirmed", default=False) + amount = FloatField( + "Amount", + validators=[DataRequired()], + render_kw={"placeholder": "10.00"}, + ) + currency = StringField( + "Currency", + validators=[DataRequired()], + description="Any string, but prefer ISO 4217. Case insensitive.", + render_kw={"placeholder": "GEL, USD, DOGE"}, + ) + confirmed = SelectField( + "Confirmed", + choices=(True, False), + default=False, + description="Funds have been received by recipient.", + ) submit = SubmitField("Submit") diff --git a/ui/app/static/style.css b/ui/app/static/style.css index 46740ba..0f614dd 100644 --- a/ui/app/static/style.css +++ b/ui/app/static/style.css @@ -49,6 +49,13 @@ nav .user { float: right; } +/* FORMS */ +input.small { + width: 3rem; +} +.description { + padding-bottom: 0.5rem; +} /* COLORS */ a { color: #007bff; @@ -72,3 +79,7 @@ table tr:nth-child(even) { .amount-negative { color: red; } + +.secondary { + color: gray; +} diff --git a/ui/app/templates/base.jinja2 b/ui/app/templates/base.jinja2 index 324562e..097d90b 100644 --- a/ui/app/templates/base.jinja2 +++ b/ui/app/templates/base.jinja2 @@ -3,7 +3,7 @@ - + refinance diff --git a/ui/app/templates/form.jinja2 b/ui/app/templates/form.jinja2 index 5323c4f..c915ed4 100644 --- a/ui/app/templates/form.jinja2 +++ b/ui/app/templates/form.jinja2 @@ -1,15 +1,25 @@ -{% macro render_form(form) %} +{% macro render_form(form, except=(), new_table=True) %} + +{% if new_table %}{% endif %} -
{% for field in form %} + {% if field.name not in except%} {% if field.type not in ('CSRFTokenField', 'SubmitField') %} {% endif %} - + + + {% if field.description %} + + + + {% endif %} + {% endif %} {% endfor %} -
{{ field.label() }}{{ field() }}{{ field(autocomplete="off") }}
{{ field.description }}
+ +{% if new_table %}{% endif %} {% if form.errors %}