From 92f9a2c3932f416d9e355e0c18961e54b6fec133 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 14:03:20 -0500 Subject: [PATCH 1/7] Datafield entry in forms --- .DS_Store | Bin 0 -> 8196 bytes ihatemoney/forms.py | 9 +++++++-- .../5cdb4f2e52c9_add_default_currency.py | 8 +++++--- ...2dd493cdc_add_original_currency_and_amount.py | 8 +++++--- ihatemoney/models.py | 2 -- ihatemoney/templates/forms.html | 2 ++ ihatemoney/templates/list_bills.html | 4 +--- ihatemoney/utils.py | 13 +++++++++++++ ihatemoney/web.py | 9 +++++++-- 9 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..34f9181f981414cd12418b0003c60a8e6b454c52 GIT binary patch literal 8196 zcmeHMPj4GV6n~QhymlJ0X%iBPkSr{uN)1s0Q6qt>8YiZ;_~VcbA)zhq+8#TrZg$M> zI)4eug%7}qa^MapJ^&KuegjU3j{p)UPT@B*>(skW4jiBecBGy6cJ}?=oB6Hgjo+Gx zSgG4wAetc}1DBNMD7tf+d@iqnHWZCaK{DV;H0rLXR0#k%f??I5s~`W6c{u=CjO2-y z7(rti3aOziDlu48J1`B$^I~LwqNRotQ<32(ip-)4g+-+Y%PVtYMJ>}lWgul>kO5h{ z4^y2S@+xkuet#32YyVU=1skJfxqCxEg9LfhO4xk| zzx{TX5TOeH>$FA{D$$3~s?e=Cj!h?Ulhh_OPV2>X4agc+zZL%>BIWNfur-KCMTVTG@ znA20}=VI!6K_~jk^0?k{ogkc_|A`F^k392i#xQb5ZY+1-+7^3OXouaPWczpJ-KrgK z*CTyh2=`34>l+T=tC^F_!V7K37%0? z3$yvx7MG4^^G8cd^RxNI*KZsjXN~Ds7H(D^>>L~(eRll$Bdi6DMX8&{_5E4@HMDcr z>NIwvwXz?3YyHJEd#lanMlX#$H*QW`zA`a6G4=e^^vu)?S6{qZGq2R`#>2KR=e;ak z;g{SlzuWemrq!_-<{|7R7ke0cIkg?|E8WK@t*62s& zkk!h-tpHuVIEyl)FN2tWExVCqs~?|59^}YBUFslW1Np6;n5AT{A7R80on*d}`7>sp zfp>vCs~8|B;T;^rtU*cIo+<;wI{J*P|H~JD|9`4;OoOKkqzwGM46u zPS)CaTn})`ChbnNR1kEk9EVipION$MhS2jcm6&2APqf4c+CTmwAXeq5TB84CPS1b! QlS93l^!!&e{5QKl0bxQfy#N3J literal 0 HcmV?d00001 diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index eb1bf2b9..39a299db 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -21,8 +21,7 @@ from jinja2 import Markup import email_validator from ihatemoney.models import Project, Person -from ihatemoney.utils import slugify, eval_arithmetic_expression - +from ihatemoney.utils import slugify, eval_arithmetic_expression,CurrencyConverter def strip_filter(string): try: @@ -87,6 +86,10 @@ class EditProjectForm(FlaskForm): name = StringField(_("Project name"), validators=[DataRequired()]) password = StringField(_("Private code"), validators=[DataRequired()]) contact_email = StringField(_("Email"), validators=[DataRequired(), Email()]) + currency_helper = CurrencyConverter() + default_currency = SelectField( + _("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()] + ) def save(self): """Create a new project with the information given by this form. @@ -98,6 +101,7 @@ class EditProjectForm(FlaskForm): id=self.id.data, password=generate_password_hash(self.password.data), contact_email=self.contact_email.data, + default_currency=self.default_currency.data ) return project @@ -106,6 +110,7 @@ class EditProjectForm(FlaskForm): project.name = self.name.data project.password = generate_password_hash(self.password.data) project.contact_email = self.contact_email.data + project.default_currency = self.default_currency.data return project diff --git a/ihatemoney/migrations/versions/5cdb4f2e52c9_add_default_currency.py b/ihatemoney/migrations/versions/5cdb4f2e52c9_add_default_currency.py index 77a7517c..e037daa0 100644 --- a/ihatemoney/migrations/versions/5cdb4f2e52c9_add_default_currency.py +++ b/ihatemoney/migrations/versions/5cdb4f2e52c9_add_default_currency.py @@ -7,15 +7,17 @@ Create Date: 2019-12-06 15:46:03.416256 """ # revision identifiers, used by Alembic. -revision = '5cdb4f2e52c9' -down_revision = 'e782dd493cdc' +revision = "5cdb4f2e52c9" +down_revision = "e782dd493cdc" from alembic import op import sqlalchemy as sa def upgrade(): - op.add_column("project", sa.Column("default_currency", sa.String(length=3), nullable=True)) + op.add_column( + "project", sa.Column("default_currency", sa.String(length=3), nullable=True) + ) def downgrade(): diff --git a/ihatemoney/migrations/versions/e782dd493cdc_add_original_currency_and_amount.py b/ihatemoney/migrations/versions/e782dd493cdc_add_original_currency_and_amount.py index 0b17e902..64ae16cd 100644 --- a/ihatemoney/migrations/versions/e782dd493cdc_add_original_currency_and_amount.py +++ b/ihatemoney/migrations/versions/e782dd493cdc_add_original_currency_and_amount.py @@ -7,15 +7,17 @@ Create Date: 2019-12-06 15:12:46.116711 """ # revision identifiers, used by Alembic. -revision = 'e782dd493cdc' -down_revision = '6c6fb2b7f229' +revision = "e782dd493cdc" +down_revision = "6c6fb2b7f229" from alembic import op import sqlalchemy as sa def upgrade(): - op.add_column("bill", sa.Column("original_currency", sa.String(length=3), nullable=True)) + op.add_column( + "bill", sa.Column("original_currency", sa.String(length=3), nullable=True) + ) op.add_column("bill", sa.Column("original_amount", sa.Float(), nullable=True)) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 0f4c19de..63b43e3c 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -377,8 +377,6 @@ class Bill(db.Model): "creation_date": self.creation_date, "what": self.what, "external_link": self.external_link, - "original_currency": self.original_currency, - "original_amount": self.original_amount, } def pay_each(self): diff --git a/ihatemoney/templates/forms.html b/ihatemoney/templates/forms.html index 61127ce7..af3c0357 100644 --- a/ihatemoney/templates/forms.html +++ b/ihatemoney/templates/forms.html @@ -65,6 +65,7 @@ {{ input(form.name) }} {{ input(form.password) }} {{ input(form.contact_email) }} + {{ input(form.default_currency) }} {% if not home %} {{ submit(form.submit, home=True) }} {% endif %} @@ -78,6 +79,7 @@ {{ input(form.name) }} {{ input(form.password) }} {{ input(form.contact_email) }} + {{ input(form.default_currency) }}
{{ _("delete") }} diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index 33d8fe4c..84f72994 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -101,7 +101,7 @@
- + {% for bill in bills %} @@ -121,8 +121,6 @@ {{ bill.owers|join(', ', 'name') }} {%- endif %} - - + +
{{ _("When?") }}{{ _("Who paid?") }}{{ _("For what?") }}{{ _("For whom?") }}{{ _("How much?") }}{{ _("Original currency") }}{{ _("Original amount") }}{{ _("Actions") }}
{{ _("When?") }}{{ _("Who paid?") }}{{ _("For what?") }}{{ _("For whom?") }}{{ _("How much?") }}{{ _("Actions") }}
{{ "%0.2f"|format(bill.amount) }} ({{ "%0.2f"|format(bill.pay_each()) }} {{ _("each") }}){{ bill.original_currency }}{{ bill.original_amount }} {{ _('edit') }} {{ _('delete') }} diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index cdc11c9c..be418266 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -12,7 +12,20 @@ from werkzeug.routing import HTTPException, RoutingException from datetime import datetime, timedelta import csv +import requests +class CurrencyConverter(object): + api_url = 'https://api.exchangerate-api.com/v4/latest/USD' + response = [] + + def __init__(self): + self.response = requests.get(self.api_url).json(); + + def get_currencies(self): + currencies = [] + for rate in self.response["rates"]: + currencies.append((rate,rate)) + return currencies def slugify(value): """Normalizes string, converts to lowercase, removes non-alpha characters, diff --git a/ihatemoney/web.py b/ihatemoney/web.py index fc12e9d5..3c8c6da4 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -315,7 +315,9 @@ def create_project(): ) return redirect(url_for(".list_bills", project_id=project.id)) - return render_template("create_project.html", form=form) + return render_template( + "create_project.html", form=form, + ) @main.route("/password-reminder", methods=["GET", "POST"]) @@ -387,7 +389,9 @@ def edit_project(): edit_form.contact_email.data = g.project.contact_email return render_template( - "edit_project.html", edit_form=edit_form, current_view="edit_project" + "edit_project.html", + edit_form=edit_form, + current_view="edit_project", ) @@ -449,6 +453,7 @@ def demo(): name="demonstration", password=generate_password_hash("demo"), contact_email="demo@notmyidea.org", + default_currency="USD", ) db.session.add(project) db.session.commit() From 244a858ba746e4a31fd0fca0708c69d8d9afb8d2 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 14:06:06 -0500 Subject: [PATCH 2/7] adding a stray file --- ihatemoney/.DS_Store | Bin 0 -> 8196 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ihatemoney/.DS_Store diff --git a/ihatemoney/.DS_Store b/ihatemoney/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d5c892a07be525d3b08d21f5cab7ffbf43769ba3 GIT binary patch literal 8196 zcmeHM!EVz)5S?w))JY3e0+b$oLE;cl166xKNKq(<-jIUe04TMaG_~Y1D zWzAf<4Jm*p3Miotj{7uN(6$#W1C{~HfMvikU>W!u7{EK5i?igtuSacb8L$lemkjXp z!9``+G;*q?dUT*sDF9>%msLR@d4R&WMmCL{YN?>Gsj~-Rpu(gWLc=lcvN~kb$f=eZ zPC~;;n3;viP=uNtI9I8YXliL&%YbEIkpa%#w^Ys^P&AjnUml0@)DNW(4Zf)!q2B$W z3VK9k@{r{RD%a2Je#z-p$cMI1Jqn?JN@vucw=QZ0h?Kh22POfgOMVXVDTlZYyAnQ} z(LEq~bb-}{n3el+4*NZay$Sn0AU#Tf;cpnRnm2)e5!MhFddZAjWf*Z_LDCR27wa=C zS^Ww$J=ph@m;B8n$D?8;i`WJN-r&#}J&&X$=O1&E#Z`d|Fv}1)_KA5a;v|dV)k(!m zxWpg$FPx13W!O()xxf>G?>XHVE77Yt&8;4>FsEBld$?*p;qUJd{wN-pX#VOC!XQre z_P&X=_0mRp({ZX!^;-2!`&^FNiI=2t%NxGpvu9p%?wkH|DZ^Rc^IrtLQD^7Y6B#95 z5cP%%9CUk7dHphox^mQ#Y1ECCowgouoQhNF?9|5NgGSwbuzxtIyW_*dy}G;q@L)2j zIJG;C$HylZm+!|PCLgb`izvdp^5}*>pS7RSE8ymBdl-c>>N6B|L$Swf7wq^PYunJ_ z2tjO^JEt&G_(>q%W%k{{u5(l^ixb}atbUnBh+@AePB`M{bT^?JBXSF$GlKU$YZ<5Z z{XdHj+p!F+Vqjel?sESBbouxHRVM71Wxz7m^I8Tg|N`~=zCSXcl6 literal 0 HcmV?d00001 From 13687c198e6b26c2fb883f9e0cce3e3bc87346d9 Mon Sep 17 00:00:00 2001 From: nathan koch Date: Sun, 8 Dec 2019 14:12:28 -0500 Subject: [PATCH 3/7] added requests to the requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 27280428..13e8560a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,3 +25,4 @@ pytz==2019.2 SQLAlchemy==1.3.8 Werkzeug==0.16.0 WTForms==2.2.1 +requests==2.22.0 \ No newline at end of file From 015a00f7a3439777d3cef03ee058c95b9f50a39a Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 14:50:10 -0500 Subject: [PATCH 4/7] Added another exception for catching errors related to mail --- ihatemoney/models.py | 3 +++ ihatemoney/templates/list_bills.html | 2 ++ ihatemoney/web.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 63b43e3c..5cbc974d 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -377,6 +377,9 @@ class Bill(db.Model): "creation_date": self.creation_date, "what": self.what, "external_link": self.external_link, + "original_currency": self.original_currency, + "original_amount": self.original_amount, + } def pay_each(self): diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index 84f72994..f9a2a9f8 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -121,6 +121,8 @@ {{ bill.owers|join(', ', 'name') }} {%- endif %} {{ "%0.2f"|format(bill.amount) }} ({{ "%0.2f"|format(bill.pay_each()) }} {{ _("each") }}){{ bill.original_currency }}{{ bill.original_amount }} {{ _('edit') }} {{ _('delete') }} diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 3c8c6da4..819a5e45 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -299,7 +299,7 @@ def create_project(): ) try: current_app.mail.send(msg) - except SMTPRecipientsRefused: + except (SMTPRecipientsRefused, ConnectionRefusedError): msg_compl = "Problem sending mail. " # TODO: destroy the project and cancel instead? else: From 912b6635238462d9dd107129a69b05dc3cf19304 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 15:13:57 -0500 Subject: [PATCH 5/7] Testing to find the issue --- ihatemoney/forms.py | 8 ++++---- ihatemoney/web.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 39a299db..7dd92252 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -87,9 +87,9 @@ class EditProjectForm(FlaskForm): password = StringField(_("Private code"), validators=[DataRequired()]) contact_email = StringField(_("Email"), validators=[DataRequired(), Email()]) currency_helper = CurrencyConverter() - default_currency = SelectField( - _("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()] - ) + # default_currency = SelectField( + # _("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()] + # ) def save(self): """Create a new project with the information given by this form. @@ -101,7 +101,7 @@ class EditProjectForm(FlaskForm): id=self.id.data, password=generate_password_hash(self.password.data), contact_email=self.contact_email.data, - default_currency=self.default_currency.data + # default_currency=self.default_currency.data ) return project diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 819a5e45..eb61ae66 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -277,6 +277,8 @@ def create_project(): project = form.save() db.session.add(project) db.session.commit() + print(project.name) + print(project.default_currency) # create the session object (authenticate) session[project.id] = True From b581e8ab9d120172d4d2ba609c437ab458b0e27e Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 15:16:52 -0500 Subject: [PATCH 6/7] revert change --- ihatemoney/forms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 7dd92252..39a299db 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -87,9 +87,9 @@ class EditProjectForm(FlaskForm): password = StringField(_("Private code"), validators=[DataRequired()]) contact_email = StringField(_("Email"), validators=[DataRequired(), Email()]) currency_helper = CurrencyConverter() - # default_currency = SelectField( - # _("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()] - # ) + default_currency = SelectField( + _("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()] + ) def save(self): """Create a new project with the information given by this form. @@ -101,7 +101,7 @@ class EditProjectForm(FlaskForm): id=self.id.data, password=generate_password_hash(self.password.data), contact_email=self.contact_email.data, - # default_currency=self.default_currency.data + default_currency=self.default_currency.data ) return project From 78efdaf4c99bbd0894f4bfea2a0ed10afe191cc5 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Sun, 8 Dec 2019 15:18:26 -0500 Subject: [PATCH 7/7] Adding a removed change to list_bills.html template --- ihatemoney/templates/list_bills.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index f9a2a9f8..33d8fe4c 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -101,7 +101,7 @@
- + {% for bill in bills %}
{{ _("When?") }}{{ _("Who paid?") }}{{ _("For what?") }}{{ _("For whom?") }}{{ _("How much?") }}{{ _("Actions") }}
{{ _("When?") }}{{ _("Who paid?") }}{{ _("For what?") }}{{ _("For whom?") }}{{ _("How much?") }}{{ _("Original currency") }}{{ _("Original amount") }}{{ _("Actions") }}