mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 13:01:50 +02:00
commit
868915fa13
10 changed files with 44 additions and 11 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
BIN
ihatemoney/.DS_Store
vendored
Normal file
BIN
ihatemoney/.DS_Store
vendored
Normal file
Binary file not shown.
|
@ -21,8 +21,7 @@ from jinja2 import Markup
|
||||||
import email_validator
|
import email_validator
|
||||||
|
|
||||||
from ihatemoney.models import Project, Person
|
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):
|
def strip_filter(string):
|
||||||
try:
|
try:
|
||||||
|
@ -87,6 +86,10 @@ class EditProjectForm(FlaskForm):
|
||||||
name = StringField(_("Project name"), validators=[DataRequired()])
|
name = StringField(_("Project name"), validators=[DataRequired()])
|
||||||
password = StringField(_("Private code"), validators=[DataRequired()])
|
password = StringField(_("Private code"), validators=[DataRequired()])
|
||||||
contact_email = StringField(_("Email"), validators=[DataRequired(), Email()])
|
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):
|
def save(self):
|
||||||
"""Create a new project with the information given by this form.
|
"""Create a new project with the information given by this form.
|
||||||
|
@ -98,6 +101,7 @@ class EditProjectForm(FlaskForm):
|
||||||
id=self.id.data,
|
id=self.id.data,
|
||||||
password=generate_password_hash(self.password.data),
|
password=generate_password_hash(self.password.data),
|
||||||
contact_email=self.contact_email.data,
|
contact_email=self.contact_email.data,
|
||||||
|
default_currency=self.default_currency.data
|
||||||
)
|
)
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
@ -106,6 +110,7 @@ class EditProjectForm(FlaskForm):
|
||||||
project.name = self.name.data
|
project.name = self.name.data
|
||||||
project.password = generate_password_hash(self.password.data)
|
project.password = generate_password_hash(self.password.data)
|
||||||
project.contact_email = self.contact_email.data
|
project.contact_email = self.contact_email.data
|
||||||
|
project.default_currency = self.default_currency.data
|
||||||
|
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,17 @@ Create Date: 2019-12-06 15:46:03.416256
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = '5cdb4f2e52c9'
|
revision = "5cdb4f2e52c9"
|
||||||
down_revision = 'e782dd493cdc'
|
down_revision = "e782dd493cdc"
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
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():
|
def downgrade():
|
||||||
|
|
|
@ -7,15 +7,17 @@ Create Date: 2019-12-06 15:12:46.116711
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = 'e782dd493cdc'
|
revision = "e782dd493cdc"
|
||||||
down_revision = '6c6fb2b7f229'
|
down_revision = "6c6fb2b7f229"
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
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))
|
op.add_column("bill", sa.Column("original_amount", sa.Float(), nullable=True))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -379,6 +379,7 @@ class Bill(db.Model):
|
||||||
"external_link": self.external_link,
|
"external_link": self.external_link,
|
||||||
"original_currency": self.original_currency,
|
"original_currency": self.original_currency,
|
||||||
"original_amount": self.original_amount,
|
"original_amount": self.original_amount,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def pay_each(self):
|
def pay_each(self):
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
{{ input(form.name) }}
|
{{ input(form.name) }}
|
||||||
{{ input(form.password) }}
|
{{ input(form.password) }}
|
||||||
{{ input(form.contact_email) }}
|
{{ input(form.contact_email) }}
|
||||||
|
{{ input(form.default_currency) }}
|
||||||
{% if not home %}
|
{% if not home %}
|
||||||
{{ submit(form.submit, home=True) }}
|
{{ submit(form.submit, home=True) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -78,6 +79,7 @@
|
||||||
{{ input(form.name) }}
|
{{ input(form.name) }}
|
||||||
{{ input(form.password) }}
|
{{ input(form.password) }}
|
||||||
{{ input(form.contact_email) }}
|
{{ input(form.contact_email) }}
|
||||||
|
{{ input(form.default_currency) }}
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button class="btn btn-primary">{{ _("Edit the project") }}</button>
|
<button class="btn btn-primary">{{ _("Edit the project") }}</button>
|
||||||
<a id="delete-project" style="color:red; margin-left:10px; cursor:pointer; ">{{ _("delete") }}</a>
|
<a id="delete-project" style="color:red; margin-left:10px; cursor:pointer; ">{{ _("delete") }}</a>
|
||||||
|
|
|
@ -12,7 +12,20 @@ from werkzeug.routing import HTTPException, RoutingException
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import csv
|
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):
|
def slugify(value):
|
||||||
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||||
|
|
|
@ -277,6 +277,8 @@ def create_project():
|
||||||
project = form.save()
|
project = form.save()
|
||||||
db.session.add(project)
|
db.session.add(project)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
print(project.name)
|
||||||
|
print(project.default_currency)
|
||||||
|
|
||||||
# create the session object (authenticate)
|
# create the session object (authenticate)
|
||||||
session[project.id] = True
|
session[project.id] = True
|
||||||
|
@ -299,7 +301,7 @@ def create_project():
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
current_app.mail.send(msg)
|
current_app.mail.send(msg)
|
||||||
except SMTPRecipientsRefused:
|
except (SMTPRecipientsRefused, ConnectionRefusedError):
|
||||||
msg_compl = "Problem sending mail. "
|
msg_compl = "Problem sending mail. "
|
||||||
# TODO: destroy the project and cancel instead?
|
# TODO: destroy the project and cancel instead?
|
||||||
else:
|
else:
|
||||||
|
@ -315,7 +317,9 @@ def create_project():
|
||||||
)
|
)
|
||||||
return redirect(url_for(".list_bills", project_id=project.id))
|
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"])
|
@main.route("/password-reminder", methods=["GET", "POST"])
|
||||||
|
@ -387,7 +391,9 @@ def edit_project():
|
||||||
edit_form.contact_email.data = g.project.contact_email
|
edit_form.contact_email.data = g.project.contact_email
|
||||||
|
|
||||||
return render_template(
|
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 +455,7 @@ def demo():
|
||||||
name="demonstration",
|
name="demonstration",
|
||||||
password=generate_password_hash("demo"),
|
password=generate_password_hash("demo"),
|
||||||
contact_email="demo@notmyidea.org",
|
contact_email="demo@notmyidea.org",
|
||||||
|
default_currency="USD",
|
||||||
)
|
)
|
||||||
db.session.add(project)
|
db.session.add(project)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -25,3 +25,4 @@ pytz==2019.2
|
||||||
SQLAlchemy==1.3.8
|
SQLAlchemy==1.3.8
|
||||||
Werkzeug==0.16.0
|
Werkzeug==0.16.0
|
||||||
WTForms==2.2.1
|
WTForms==2.2.1
|
||||||
|
requests==2.22.0
|
Loading…
Reference in a new issue