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
|
@ -22,7 +22,8 @@ from jinja2 import Markup
|
|||
import email_validator
|
||||
|
||||
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):
|
||||
try:
|
||||
|
@ -39,7 +40,9 @@ def get_billform_for(project, set_default=True, **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]
|
||||
|
||||
form.payed_for.choices = form.payer.choices = active_members
|
||||
|
@ -90,7 +93,9 @@ class EditProjectForm(FlaskForm):
|
|||
contact_email = StringField(_("Email"), validators=[DataRequired(), Email()])
|
||||
currency_helper = CurrencyConverter()
|
||||
default_currency = SelectField(
|
||||
_("Default Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()]
|
||||
_("Default Currency"),
|
||||
choices=currency_helper.get_currencies(),
|
||||
validators=[DataRequired()],
|
||||
)
|
||||
|
||||
def save(self):
|
||||
|
@ -103,7 +108,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
|
||||
|
||||
|
@ -172,7 +177,9 @@ class BillForm(FlaskForm):
|
|||
amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()])
|
||||
currency_helper = CurrencyConverter()
|
||||
original_currency = SelectField(
|
||||
_("Currency"), choices=currency_helper.get_currencies(), validators=[DataRequired()]
|
||||
_("Currency"),
|
||||
choices=currency_helper.get_currencies(),
|
||||
validators=[DataRequired()],
|
||||
)
|
||||
external_link = URLField(
|
||||
_("External link"),
|
||||
|
@ -193,7 +200,9 @@ class BillForm(FlaskForm):
|
|||
bill.date = self.date.data
|
||||
bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.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
|
||||
|
||||
|
|
|
@ -379,7 +379,6 @@ class Bill(db.Model):
|
|||
"external_link": self.external_link,
|
||||
"original_currency": self.original_currency,
|
||||
"original_amount": self.original_amount,
|
||||
|
||||
}
|
||||
|
||||
def pay_each(self):
|
||||
|
|
|
@ -14,26 +14,28 @@ from datetime import datetime, timedelta
|
|||
import csv
|
||||
import requests
|
||||
|
||||
|
||||
class CurrencyConverter(object):
|
||||
api_url = 'https://api.exchangerate-api.com/v4/latest/USD'
|
||||
api_url = "https://api.exchangerate-api.com/v4/latest/USD"
|
||||
response = []
|
||||
|
||||
def __init__(self):
|
||||
self.response = requests.get(self.api_url).json();
|
||||
|
||||
self.response = requests.get(self.api_url).json()
|
||||
|
||||
def get_currencies(self):
|
||||
currencies = []
|
||||
for rate in self.response["rates"]:
|
||||
currencies.append((rate,rate))
|
||||
currencies.append((rate, rate))
|
||||
return currencies
|
||||
|
||||
def exchange_currency(self,amount,currency1,currency2):
|
||||
|
||||
def exchange_currency(self, amount, currency1, currency2):
|
||||
base = self.response["base"]
|
||||
conversion_rate1 = self.response["rates"][currency1]
|
||||
conversion_rate2 = self.response["rates"][currency2]
|
||||
new_amount = (amount / conversion_rate1) * conversion_rate2
|
||||
# round to two digits because we are dealing with money
|
||||
return round(new_amount,2)
|
||||
return round(new_amount, 2)
|
||||
|
||||
|
||||
def slugify(value):
|
||||
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||
|
|
|
@ -317,9 +317,7 @@ 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"])
|
||||
|
@ -391,9 +389,7 @@ 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",
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue