mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 05:01:48 +02:00
Ran black on the project directory
This commit is contained in:
parent
adb6b21174
commit
54ef41bded
4 changed files with 26 additions and 20 deletions
|
@ -24,6 +24,7 @@ import email_validator
|
||||||
from ihatemoney.models import Project, Person
|
from ihatemoney.models import Project, Person
|
||||||
from ihatemoney.utils import slugify, eval_arithmetic_expression, CurrencyConverter
|
from ihatemoney.utils import slugify, eval_arithmetic_expression, CurrencyConverter
|
||||||
|
|
||||||
|
|
||||||
def strip_filter(string):
|
def strip_filter(string):
|
||||||
try:
|
try:
|
||||||
return string.strip()
|
return string.strip()
|
||||||
|
@ -39,7 +40,9 @@ def get_billform_for(project, set_default=True, **kwargs):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
form = BillForm(**kwargs)
|
form = BillForm(**kwargs)
|
||||||
form.original_currency.label = Label("original_currency", "Currency (Default: %s)" % (project.default_currency))
|
form.original_currency.label = Label(
|
||||||
|
"original_currency", "Currency (Default: %s)" % (project.default_currency)
|
||||||
|
)
|
||||||
active_members = [(m.id, m.name) for m in project.active_members]
|
active_members = [(m.id, m.name) for m in project.active_members]
|
||||||
|
|
||||||
form.payed_for.choices = form.payer.choices = active_members
|
form.payed_for.choices = form.payer.choices = active_members
|
||||||
|
@ -90,7 +93,9 @@ class EditProjectForm(FlaskForm):
|
||||||
contact_email = StringField(_("Email"), validators=[DataRequired(), Email()])
|
contact_email = StringField(_("Email"), validators=[DataRequired(), Email()])
|
||||||
currency_helper = CurrencyConverter()
|
currency_helper = CurrencyConverter()
|
||||||
default_currency = SelectField(
|
default_currency = SelectField(
|
||||||
_("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()]
|
_("Default Currency"),
|
||||||
|
choices=currency_helper.get_currencies(),
|
||||||
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -103,7 +108,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
|
default_currency=self.default_currency.data,
|
||||||
)
|
)
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
@ -172,7 +177,9 @@ class BillForm(FlaskForm):
|
||||||
amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()])
|
amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()])
|
||||||
currency_helper = CurrencyConverter()
|
currency_helper = CurrencyConverter()
|
||||||
original_currency = SelectField(
|
original_currency = SelectField(
|
||||||
_("Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()]
|
_("Currency"),
|
||||||
|
choices=currency_helper.get_currencies(),
|
||||||
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
external_link = URLField(
|
external_link = URLField(
|
||||||
_("External link"),
|
_("External link"),
|
||||||
|
@ -193,7 +200,9 @@ class BillForm(FlaskForm):
|
||||||
bill.date = self.date.data
|
bill.date = self.date.data
|
||||||
bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.data]
|
bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.data]
|
||||||
bill.original_currency = self.original_currency.data
|
bill.original_currency = self.original_currency.data
|
||||||
bill.original_amount = self.currency_helper.exchange_currency(float(bill.amount), bill.original_currency, project.default_currency)
|
bill.original_amount = self.currency_helper.exchange_currency(
|
||||||
|
float(bill.amount), bill.original_currency, project.default_currency
|
||||||
|
)
|
||||||
|
|
||||||
return bill
|
return bill
|
||||||
|
|
||||||
|
|
|
@ -379,7 +379,6 @@ 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):
|
||||||
|
|
|
@ -14,12 +14,13 @@ from datetime import datetime, timedelta
|
||||||
import csv
|
import csv
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class CurrencyConverter(object):
|
class CurrencyConverter(object):
|
||||||
api_url = 'https://api.exchangerate-api.com/v4/latest/USD'
|
api_url = "https://api.exchangerate-api.com/v4/latest/USD"
|
||||||
response = []
|
response = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.response = requests.get(self.api_url).json();
|
self.response = requests.get(self.api_url).json()
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self):
|
||||||
currencies = []
|
currencies = []
|
||||||
|
@ -35,6 +36,7 @@ class CurrencyConverter(object):
|
||||||
# round to two digits because we are dealing with money
|
# round to two digits because we are dealing with money
|
||||||
return round(new_amount, 2)
|
return round(new_amount, 2)
|
||||||
|
|
||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||||
and converts spaces to hyphens.
|
and converts spaces to hyphens.
|
||||||
|
|
|
@ -317,9 +317,7 @@ 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(
|
return render_template("create_project.html", form=form,)
|
||||||
"create_project.html", form=form,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/password-reminder", methods=["GET", "POST"])
|
@main.route("/password-reminder", methods=["GET", "POST"])
|
||||||
|
@ -391,9 +389,7 @@ 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_project.html", edit_form=edit_form, current_view="edit_project",
|
||||||
edit_form=edit_form,
|
|
||||||
current_view="edit_project",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue