Merge pull request #479 from LeoMouyna:feature/external-link-bill-form

feat: Optional field 'external link' in bill form.
This commit is contained in:
Alexis Metaireau 2019-10-06 21:20:47 +02:00 committed by GitHub
commit 4b01276d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 141 additions and 20 deletions

View file

@ -1,8 +1,8 @@
from flask_wtf.form import FlaskForm from flask_wtf.form import FlaskForm
from wtforms.fields.core import SelectField, SelectMultipleField from wtforms.fields.core import SelectField, SelectMultipleField
from wtforms.fields.html5 import DateField, DecimalField from wtforms.fields.html5 import DateField, DecimalField, URLField
from wtforms.fields.simple import PasswordField, SubmitField, TextAreaField, StringField from wtforms.fields.simple import PasswordField, SubmitField, TextAreaField, StringField
from wtforms.validators import Email, DataRequired, ValidationError, EqualTo, NumberRange from wtforms.validators import Email, DataRequired, ValidationError, EqualTo, NumberRange, Optional
from flask_babel import lazy_gettext as _ from flask_babel import lazy_gettext as _
from flask import request from flask import request
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
@ -146,6 +146,8 @@ class BillForm(FlaskForm):
what = StringField(_("What?"), validators=[DataRequired()]) what = StringField(_("What?"), validators=[DataRequired()])
payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int) payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int)
amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()]) amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()])
external_link = URLField(_("External link"), validators=[Optional(
)], description=_("A link to an external document, related to this bill"))
payed_for = SelectMultipleField(_("For whom?"), payed_for = SelectMultipleField(_("For whom?"),
validators=[DataRequired()], coerce=int) validators=[DataRequired()], coerce=int)
submit = SubmitField(_("Submit")) submit = SubmitField(_("Submit"))
@ -155,6 +157,7 @@ class BillForm(FlaskForm):
bill.payer_id = self.payer.data bill.payer_id = self.payer.data
bill.amount = self.amount.data bill.amount = self.amount.data
bill.what = self.what.data bill.what = self.what.data
bill.external_link = self.external_link.data
bill.date = self.date.data bill.date = self.date.data
bill.owers = [Person.query.get(ower, project) bill.owers = [Person.query.get(ower, project)
for ower in self.payed_for.data] for ower in self.payed_for.data]
@ -165,6 +168,7 @@ class BillForm(FlaskForm):
self.payer.data = bill.payer_id self.payer.data = bill.payer_id
self.amount.data = bill.amount self.amount.data = bill.amount
self.what.data = bill.what self.what.data = bill.what
self.external_link.data = bill.external_link
self.date.data = bill.date self.date.data = bill.date
self.payed_for.data = [int(ower.id) for ower in bill.owers] self.payed_for.data = [int(ower.id) for ower in bill.owers]

View file

@ -60,6 +60,12 @@ msgstr ""
msgid "Amount paid" msgid "Amount paid"
msgstr "" msgstr ""
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "" msgstr ""
@ -412,6 +418,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "" msgstr ""
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "" msgstr ""

View file

@ -0,0 +1,26 @@
"""empty message
Revision ID: 6c6fb2b7f229
Revises: a67119aa3ee5
Create Date: 2019-09-28 13:38:09.550747
"""
# revision identifiers, used by Alembic.
revision = '6c6fb2b7f229'
down_revision = 'a67119aa3ee5'
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('bill', sa.Column('external_link', sa.UnicodeText(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('bill', 'external_link')
# ### end Alembic commands ###

View file

@ -327,6 +327,7 @@ class Bill(db.Model):
date = db.Column(db.Date, default=datetime.now) date = db.Column(db.Date, default=datetime.now)
creation_date = db.Column(db.Date, default=datetime.now) creation_date = db.Column(db.Date, default=datetime.now)
what = db.Column(db.UnicodeText) what = db.Column(db.UnicodeText)
external_link = db.Column(db.UnicodeText)
archive = db.Column(db.Integer, db.ForeignKey("archive.id")) archive = db.Column(db.Integer, db.ForeignKey("archive.id"))
@ -340,6 +341,7 @@ class Bill(db.Model):
"date": self.date, "date": self.date,
"creation_date": self.creation_date, "creation_date": self.creation_date,
"what": self.what, "what": self.what,
"external_link": self.external_link,
} }
def pay_each(self): def pay_each(self):

View file

@ -32,7 +32,7 @@ body {
@media (min-width: 992px) { @media (min-width: 992px) {
.projects-item { .projects-item {
margin-left: auto!important; margin-left: auto !important;
} }
} }
@ -108,7 +108,6 @@ body {
.identifier { .identifier {
margin-bottom: 0; margin-bottom: 0;
} }
} }
#add-member-form { #add-member-form {
@ -132,7 +131,7 @@ body {
/* Home */ /* Home */
.home-container { .home-container {
background: linear-gradient(150deg, #abe128 0%, #43CA61 100%); background: linear-gradient(150deg, #abe128 0%, #43ca61 100%);
} }
.home { .home {
padding-top: 1em; padding-top: 1em;
@ -146,7 +145,7 @@ body {
min-width: 25em; min-width: 25em;
border: 0; border: 0;
border-radius: 0; border-radius: 0;
box-shadow: 0px 0px 10px rgba(83, 88, 93, .40); box-shadow: 0px 0px 10px rgba(83, 88, 93, 0.4);
margin-right: 25px; margin-right: 25px;
margin-bottom: 20px; margin-bottom: 20px;
margin-left: 25px; margin-left: 25px;
@ -159,7 +158,6 @@ body {
.empty-bill { .empty-bill {
margin-top: 5rem !important; margin-top: 5rem !important;
} }
.empty-bill .card { .empty-bill .card {
border: 0; border: 0;
@ -240,7 +238,7 @@ footer .footer-right a {
@-moz-document url-prefix() { @-moz-document url-prefix() {
/** Firefox style fix **/ /** Firefox style fix **/
footer .footer-right a { footer .footer-right a {
padding-top: 2px padding-top: 2px;
} }
} }
footer .footer-right a:hover { footer .footer-right a:hover {
@ -290,7 +288,8 @@ footer .footer-left {
} }
.bill-actions > .delete, .bill-actions > .delete,
.bill-actions > .edit { .bill-actions > .edit,
.bill-actions > .see {
font-size: 0px; font-size: 0px;
display: block; display: block;
width: 16px; width: 16px;
@ -308,6 +307,10 @@ footer .footer-left {
background: url("../images/edit.png") no-repeat right; background: url("../images/edit.png") no-repeat right;
} }
.bill-actions > .see {
background: url("../images/see.png") no-repeat right;
}
#bill_table { #bill_table {
margin-top: 30px; margin-top: 30px;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

View file

@ -14,7 +14,7 @@
{{ field(class=class, placeholder=placeholder) | safe }} {{ field(class=class, placeholder=placeholder) | safe }}
{% endif %} {% endif %}
{% if field.description %} {% if field.description %}
<p class="help-inline">{{ field.description }}</p> <small id="{{field.name}}_description"" class="form-text text-muted">{{ field.description }}</small>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@ -95,6 +95,7 @@
{{ input(form.what, inline=True) }} {{ input(form.what, inline=True) }}
{{ input(form.payer, inline=True, class="form-control custom-select") }} {{ input(form.payer, inline=True, class="form-control custom-select") }}
{{ input(form.amount, inline=True) }} {{ input(form.amount, inline=True) }}
{{ input(form.external_link, inline=True) }}
<div class="form-group row"> <div class="form-group row">
<label class="col-3" for="payed_for">{{ _("For whom?") }}</label> <label class="col-3" for="payed_for">{{ _("For whom?") }}</label>

View file

@ -134,6 +134,9 @@
<td class="bill-actions"> <td class="bill-actions">
<a class="edit" href="{{ url_for(".edit_bill", bill_id=bill.id) }}" title="{{ _("edit") }}">{{ _('edit') }}</a> <a class="edit" href="{{ url_for(".edit_bill", bill_id=bill.id) }}" title="{{ _("edit") }}">{{ _('edit') }}</a>
<a class="delete" href="{{ url_for(".delete_bill", bill_id=bill.id) }}" title="{{ _("delete") }}">{{ _('delete') }}</a> <a class="delete" href="{{ url_for(".delete_bill", bill_id=bill.id) }}" title="{{ _("delete") }}">{{ _('delete') }}</a>
{% if bill.external_link %}
<a class="see" href="{{ bill.external_link }}" ref="noopener" target="_blank" title="{{ _("see") }}">{{ _('see') }} </a>
{% endif %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View file

@ -1282,6 +1282,7 @@ class APITestCase(IhatemoneyTestCase):
'payer': "1", 'payer': "1",
'payed_for': ["1", "2"], 'payed_for': ["1", "2"],
'amount': '25', 'amount': '25',
'external_link': "https://raclette.fr"
}, headers=self.get_auth("raclette")) }, headers=self.get_auth("raclette"))
# should return the id # should return the id
@ -1302,7 +1303,9 @@ class APITestCase(IhatemoneyTestCase):
{"activated": True, "id": 2, "name": "fred", "weight": 1}], {"activated": True, "id": 2, "name": "fred", "weight": 1}],
"amount": 25.0, "amount": 25.0,
"date": "2011-08-10", "date": "2011-08-10",
"id": 1} "id": 1,
'external_link': "https://raclette.fr"
}
got = json.loads(req.data.decode('utf-8')) got = json.loads(req.data.decode('utf-8'))
self.assertEqual( self.assertEqual(
@ -1325,6 +1328,7 @@ class APITestCase(IhatemoneyTestCase):
'payer': "1", 'payer': "1",
'payed_for': ["1", "2"], 'payed_for': ["1", "2"],
'amount': '25', 'amount': '25',
'external_link': "https://raclette.fr",
}, headers=self.get_auth("raclette")) }, headers=self.get_auth("raclette"))
self.assertStatus(400, req) self.assertStatus(400, req)
@ -1337,6 +1341,7 @@ class APITestCase(IhatemoneyTestCase):
'payer': "2", 'payer': "2",
'payed_for': ["1", "2"], 'payed_for': ["1", "2"],
'amount': '25', 'amount': '25',
'external_link': "https://raclette.fr",
}, headers=self.get_auth("raclette")) }, headers=self.get_auth("raclette"))
# check its fields # check its fields
@ -1355,7 +1360,9 @@ class APITestCase(IhatemoneyTestCase):
{"activated": True, "id": 2, "name": "fred", "weight": 1}], {"activated": True, "id": 2, "name": "fred", "weight": 1}],
"amount": 25.0, "amount": 25.0,
"date": "2011-09-10", "date": "2011-09-10",
"id": 1} 'external_link': "https://raclette.fr",
"id": 1
}
got = json.loads(req.data.decode('utf-8')) got = json.loads(req.data.decode('utf-8'))
self.assertEqual( self.assertEqual(
@ -1427,6 +1434,7 @@ class APITestCase(IhatemoneyTestCase):
"amount": expected_amount, "amount": expected_amount,
"date": "2011-08-10", "date": "2011-08-10",
"id": id, "id": id,
"external_link": '',
} }
got = json.loads(req.data.decode('utf-8')) got = json.loads(req.data.decode('utf-8'))
@ -1538,7 +1546,9 @@ class APITestCase(IhatemoneyTestCase):
{"activated": True, "id": 2, "name": "freddy familly", "weight": 4}], {"activated": True, "id": 2, "name": "freddy familly", "weight": 4}],
"amount": 25.0, "amount": 25.0,
"date": "2011-08-10", "date": "2011-08-10",
"id": 1} "id": 1,
"external_link": ''
}
got = json.loads(req.data.decode('utf-8')) got = json.loads(req.data.decode('utf-8'))
self.assertEqual( self.assertEqual(
creation_date, creation_date,

View file

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-30 23:53+0200\n" "POT-Creation-Date: 2019-10-01 21:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n" "Last-Translator: Automatically generated\n"
"Language: el\n" "Language: el\n"
@ -76,6 +76,12 @@ msgstr ""
msgid "Amount paid" msgid "Amount paid"
msgstr "" msgstr ""
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "" msgstr ""
@ -428,6 +434,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "" msgstr ""
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "" msgstr ""

View file

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-30 23:53+0200\n" "POT-Creation-Date: 2019-10-01 21:48+0200\n"
"PO-Revision-Date: 2019-09-25 22:28+0000\n" "PO-Revision-Date: 2019-09-25 22:28+0000\n"
"Last-Translator: Diego Caraballo <diegocaraballo84@gmail.com>\n" "Last-Translator: Diego Caraballo <diegocaraballo84@gmail.com>\n"
"Language: es_419\n" "Language: es_419\n"
@ -81,6 +81,12 @@ msgstr "Paga"
msgid "Amount paid" msgid "Amount paid"
msgstr "Cantidad pagada" msgstr "Cantidad pagada"
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "¿Para quién?" msgstr "¿Para quién?"
@ -443,6 +449,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "Cada" msgstr "Cada"
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "Sin facturas" msgstr "Sin facturas"

View file

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2019-09-30 23:53+0200\n" "POT-Creation-Date: 2019-10-01 21:48+0200\n"
"PO-Revision-Date: 2019-09-24 15:13+0000\n" "PO-Revision-Date: 2019-09-24 15:13+0000\n"
"Last-Translator: Alexis Metaireau <alexis@notmyidea.org>\n" "Last-Translator: Alexis Metaireau <alexis@notmyidea.org>\n"
"Language: fr\n" "Language: fr\n"
@ -85,6 +85,12 @@ msgstr "Payeur"
msgid "Amount paid" msgid "Amount paid"
msgstr "Montant" msgstr "Montant"
msgid "External link"
msgstr "Lien externe"
msgid "A link to an external document, related to this bill"
msgstr "Un lien vers un document, lié à cette facture"
msgid "For whom?" msgid "For whom?"
msgstr "Pour qui ?" msgstr "Pour qui ?"
@ -443,6 +449,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "chacun" msgstr "chacun"
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "Pas encore de factures" msgstr "Pas encore de factures"

View file

@ -82,6 +82,12 @@ msgstr "Betaler"
msgid "Amount paid" msgid "Amount paid"
msgstr "Beløp betalt" msgstr "Beløp betalt"
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "For hvem?" msgstr "For hvem?"
@ -456,6 +462,9 @@ msgstr "Alle, unntagen %(excluded)s"
msgid "each" msgid "each"
msgstr "hver" msgstr "hver"
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "Ingen regninger" msgstr "Ingen regninger"

View file

@ -77,6 +77,12 @@ msgstr "Betaler"
msgid "Amount paid" msgid "Amount paid"
msgstr "Betaald bedrag" msgstr "Betaald bedrag"
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "Aan wie?" msgstr "Aan wie?"
@ -437,6 +443,9 @@ msgstr "Iedereen, behalve %(excluded)s"
msgid "each" msgid "each"
msgstr "per persoon" msgstr "per persoon"
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "Geen rekeningen" msgstr "Geen rekeningen"

View file

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-30 23:53+0200\n" "POT-Creation-Date: 2019-10-01 21:48+0200\n"
"PO-Revision-Date: 2019-08-07 13:24+0000\n" "PO-Revision-Date: 2019-08-07 13:24+0000\n"
"Last-Translator: Mesut Akcan <makcan@gmail.com>\n" "Last-Translator: Mesut Akcan <makcan@gmail.com>\n"
"Language: tr\n" "Language: tr\n"
@ -81,6 +81,12 @@ msgstr "Mükellefi"
msgid "Amount paid" msgid "Amount paid"
msgstr "Ödenen tutar" msgstr "Ödenen tutar"
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "Kim için?" msgstr "Kim için?"
@ -433,6 +439,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "" msgstr ""
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "" msgstr ""

View file

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-30 23:53+0200\n" "POT-Creation-Date: 2019-10-01 21:48+0200\n"
"PO-Revision-Date: 2019-07-02 00:02+0000\n" "PO-Revision-Date: 2019-07-02 00:02+0000\n"
"Last-Translator: Elizabeth Sherrock <lizzyd710@gmail.com>\n" "Last-Translator: Elizabeth Sherrock <lizzyd710@gmail.com>\n"
"Language: zh_HANS_CN\n" "Language: zh_HANS_CN\n"
@ -78,6 +78,12 @@ msgstr ""
msgid "Amount paid" msgid "Amount paid"
msgstr "" msgstr ""
msgid "External link"
msgstr ""
msgid "A link to an external document, related to this bill"
msgstr ""
msgid "For whom?" msgid "For whom?"
msgstr "" msgstr ""
@ -430,6 +436,9 @@ msgstr ""
msgid "each" msgid "each"
msgstr "" msgstr ""
msgid "see"
msgstr ""
msgid "No bills" msgid "No bills"
msgstr "" msgstr ""