Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Optional field 'external link' in bill form. #479

Merged
merged 3 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ihatemoney/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask_wtf.form import FlaskForm
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.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 import request
from werkzeug.security import generate_password_hash
Expand Down Expand Up @@ -146,6 +146,8 @@ class BillForm(FlaskForm):
what = StringField(_("What?"), validators=[DataRequired()])
payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int)
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?"),
validators=[DataRequired()], coerce=int)
submit = SubmitField(_("Submit"))
Expand All @@ -155,6 +157,7 @@ def save(self, bill, project):
bill.payer_id = self.payer.data
bill.amount = self.amount.data
bill.what = self.what.data
bill.external_link = self.external_link.data
bill.date = self.date.data
bill.owers = [Person.query.get(ower, project)
for ower in self.payed_for.data]
Expand All @@ -165,6 +168,7 @@ def fill(self, bill):
self.payer.data = bill.payer_id
self.amount.data = bill.amount
self.what.data = bill.what
self.external_link.data = bill.external_link
self.date.data = bill.date
self.payed_for.data = [int(ower.id) for ower in bill.owers]

Expand Down
9 changes: 9 additions & 0 deletions ihatemoney/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ msgstr ""
msgid "Amount paid"
msgstr ""

msgid "External link"
msgstr ""

msgid "A link to an external document, related to this bill"
msgstr ""

msgid "For whom?"
msgstr ""

Expand Down Expand Up @@ -412,6 +418,9 @@ msgstr ""
msgid "each"
msgstr ""

msgid "see"
msgstr ""

msgid "No bills"
msgstr ""

Expand Down
26 changes: 26 additions & 0 deletions ihatemoney/migrations/versions/6c6fb2b7f229_.py
Original file line number Diff line number Diff line change
@@ -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 ###
2 changes: 2 additions & 0 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def delete(self, project, id):
date = db.Column(db.Date, default=datetime.now)
creation_date = db.Column(db.Date, default=datetime.now)
what = db.Column(db.UnicodeText)
external_link = db.Column(db.UnicodeText)

archive = db.Column(db.Integer, db.ForeignKey("archive.id"))

Expand All @@ -340,6 +341,7 @@ def _to_serialize(self):
"date": self.date,
"creation_date": self.creation_date,
"what": self.what,
"external_link": self.external_link,
}

def pay_each(self):
Expand Down
19 changes: 11 additions & 8 deletions ihatemoney/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ body {

@media (min-width: 992px) {
.projects-item {
margin-left: auto!important;
margin-left: auto !important;
}
}

Expand Down Expand Up @@ -108,7 +108,6 @@ body {
.identifier {
margin-bottom: 0;
}

}

#add-member-form {
Expand All @@ -132,7 +131,7 @@ body {

/* Home */
.home-container {
background: linear-gradient(150deg, #abe128 0%, #43CA61 100%);
background: linear-gradient(150deg, #abe128 0%, #43ca61 100%);
}
.home {
padding-top: 1em;
Expand All @@ -146,7 +145,7 @@ body {
min-width: 25em;
border: 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-bottom: 20px;
margin-left: 25px;
Expand All @@ -159,7 +158,6 @@ body {

.empty-bill {
margin-top: 5rem !important;

}
.empty-bill .card {
border: 0;
Expand Down Expand Up @@ -240,7 +238,7 @@ footer .footer-right a {
@-moz-document url-prefix() {
/** Firefox style fix **/
footer .footer-right a {
padding-top: 2px
padding-top: 2px;
}
}
footer .footer-right a:hover {
Expand Down Expand Up @@ -290,7 +288,8 @@ footer .footer-left {
}

.bill-actions > .delete,
.bill-actions > .edit {
.bill-actions > .edit,
.bill-actions > .see {
font-size: 0px;
display: block;
width: 16px;
Expand All @@ -308,6 +307,10 @@ footer .footer-left {
background: url("../images/edit.png") no-repeat right;
}

.bill-actions > .see {
background: url("../images/see.png") no-repeat right;
}

#bill_table {
margin-top: 30px;
}
Expand Down Expand Up @@ -483,4 +486,4 @@ footer .icon svg {
}
.icon.icon-white {
fill: white;
}
}
Binary file added ihatemoney/static/images/see.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ihatemoney/templates/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{ field(class=class, placeholder=placeholder) | safe }}
{% endif %}
{% if field.description %}
<p class="help-inline">{{ field.description }}</p>
<small id="{{field.name}}_description"" class="form-text text-muted">{{ field.description }}</small>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -95,6 +95,7 @@
{{ input(form.what, inline=True) }}
{{ input(form.payer, inline=True, class="form-control custom-select") }}
{{ input(form.amount, inline=True) }}
{{ input(form.external_link, inline=True) }}

<div class="form-group row">
<label class="col-3" for="payed_for">{{ _("For whom?") }}</label>
Expand Down
3 changes: 3 additions & 0 deletions ihatemoney/templates/list_bills.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ <h3 class="modal-title">{{ _('Add a bill') }}</h3>
<td class="bill-actions">
<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>
{% if bill.external_link %}
<a class="see" href="{{ bill.external_link }}" ref="noopener" target="_blank" title="{{ _("see") }}">{{ _('see') }} </a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace "See" by "See attached document"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no preference tell me what's the best in your opinion :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
18 changes: 14 additions & 4 deletions ihatemoney/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ def test_bills(self):
'payer': "1",
'payed_for': ["1", "2"],
'amount': '25',
'external_link': "https://raclette.fr"
}, headers=self.get_auth("raclette"))

# should return the id
Expand All @@ -1302,7 +1303,9 @@ def test_bills(self):
{"activated": True, "id": 2, "name": "fred", "weight": 1}],
"amount": 25.0,
"date": "2011-08-10",
"id": 1}
"id": 1,
'external_link': "https://raclette.fr"
}

got = json.loads(req.data.decode('utf-8'))
self.assertEqual(
Expand All @@ -1325,6 +1328,7 @@ def test_bills(self):
'payer': "1",
'payed_for': ["1", "2"],
'amount': '25',
'external_link': "https://raclette.fr",
}, headers=self.get_auth("raclette"))

self.assertStatus(400, req)
Expand All @@ -1337,6 +1341,7 @@ def test_bills(self):
'payer': "2",
'payed_for': ["1", "2"],
'amount': '25',
'external_link': "https://raclette.fr",
}, headers=self.get_auth("raclette"))

# check its fields
Expand All @@ -1355,7 +1360,9 @@ def test_bills(self):
{"activated": True, "id": 2, "name": "fred", "weight": 1}],
"amount": 25.0,
"date": "2011-09-10",
"id": 1}
'external_link': "https://raclette.fr",
"id": 1
}

got = json.loads(req.data.decode('utf-8'))
self.assertEqual(
Expand Down Expand Up @@ -1427,6 +1434,7 @@ def test_bills_with_calculation(self):
"amount": expected_amount,
"date": "2011-08-10",
"id": id,
"external_link": '',
}

got = json.loads(req.data.decode('utf-8'))
Expand Down Expand Up @@ -1538,7 +1546,9 @@ def test_weighted_bills(self):
{"activated": True, "id": 2, "name": "freddy familly", "weight": 4}],
"amount": 25.0,
"date": "2011-08-10",
"id": 1}
"id": 1,
"external_link": ''
}
got = json.loads(req.data.decode('utf-8'))
self.assertEqual(
creation_date,
Expand Down Expand Up @@ -1603,7 +1613,7 @@ def test_generate_config(self):
def test_generate_password_hash(self):
cmd = GeneratePasswordHash()
with patch('sys.stdout', new=six.StringIO()) as stdout, \
patch('getpass.getpass', new=lambda prompt: 'secret'): # NOQA
patch('getpass.getpass', new=lambda prompt: 'secret'): # NOQA
cmd.run()
print(stdout.getvalue())
self.assertEqual(len(stdout.getvalue().strip()), 189)
Expand Down
11 changes: 10 additions & 1 deletion ihatemoney/translations/el/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: Automatically generated\n"
"Language: el\n"
Expand Down Expand Up @@ -76,6 +76,12 @@ msgstr ""
msgid "Amount paid"
msgstr ""

msgid "External link"
msgstr ""

msgid "A link to an external document, related to this bill"
msgstr ""

msgid "For whom?"
msgstr ""

Expand Down Expand Up @@ -428,6 +434,9 @@ msgstr ""
msgid "each"
msgstr ""

msgid "see"
msgstr ""

msgid "No bills"
msgstr ""

Expand Down
11 changes: 10 additions & 1 deletion ihatemoney/translations/es_419/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: Diego Caraballo <[email protected]>\n"
"Language: es_419\n"
Expand Down Expand Up @@ -81,6 +81,12 @@ msgstr "Paga"
msgid "Amount paid"
msgstr "Cantidad pagada"

msgid "External link"
msgstr ""

msgid "A link to an external document, related to this bill"
msgstr ""

msgid "For whom?"
msgstr "¿Para quién?"

Expand Down Expand Up @@ -443,6 +449,9 @@ msgstr ""
msgid "each"
msgstr "Cada"

msgid "see"
msgstr ""

msgid "No bills"
msgstr "Sin facturas"

Expand Down
11 changes: 10 additions & 1 deletion ihatemoney/translations/fr/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\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"
"Last-Translator: Alexis Metaireau <[email protected]>\n"
"Language: fr\n"
Expand Down Expand Up @@ -85,6 +85,12 @@ msgstr "Payeur"
msgid "Amount paid"
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?"
msgstr "Pour qui ?"

Expand Down Expand Up @@ -443,6 +449,9 @@ msgstr ""
msgid "each"
msgstr "chacun"

msgid "see"
msgstr ""

msgid "No bills"
msgstr "Pas encore de factures"

Expand Down
Loading