Skip to content

Commit

Permalink
Some small cleanups (#976)
Browse files Browse the repository at this point in the history
Co-authored-by: Glandos <[email protected]>
  • Loading branch information
almet and Glandos authored Jan 30, 2022
1 parent ed66764 commit 7c3ced0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
34 changes: 17 additions & 17 deletions ihatemoney/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def logging_preference(self):
else:
return LoggingMode.ENABLED

def validate_default_currency(form, field):
project = Project.query.get(form.id.data)
def validate_default_currency(self, field):
project = Project.query.get(self.id.data)
if (
project is not None
and field.data == CurrencyConverter.no_currency
Expand Down Expand Up @@ -234,13 +234,13 @@ def save(self):
)
return project

def validate_id(form, field):
form.id.data = slugify(field.data)
if (form.id.data == "dashboard") or Project.query.get(form.id.data):
def validate_id(self, field):
self.id.data = slugify(field.data)
if (self.id.data == "dashboard") or Project.query.get(self.id.data):
message = _(
'A project with this identifier ("%(project)s") already exists. '
"Please choose a new identifier",
project=form.id.data,
project=self.id.data,
)
raise ValidationError(Markup(message))

Expand All @@ -250,7 +250,7 @@ class ProjectFormWithCaptcha(ProjectForm):
_("Which is a real currency: Euro or Petro dollar?"), default=""
)

def validate_captcha(form, field):
def validate_captcha(self, field):
if not field.data.lower() == _("euro"):
message = _("Please, validate the captcha to proceed.")
raise ValidationError(Markup(message))
Expand All @@ -277,11 +277,11 @@ def __init__(self, *args, **kwargs):
self.id = SimpleNamespace(data=kwargs.pop("id", ""))
super().__init__(*args, **kwargs)

def validate_password(form, field):
project = Project.query.get(form.id.data)
def validate_password(self, field):
project = Project.query.get(self.id.data)
if project is None:
raise ValidationError(_("Unknown error"))
if not check_password_hash(project.password, form.password.data):
if not check_password_hash(project.password, self.password.data):
raise ValidationError(_("Invalid private code."))


Expand All @@ -300,7 +300,7 @@ class PasswordReminder(FlaskForm):
id = StringField(_("Project identifier"), validators=[DataRequired()])
submit = SubmitField(_("Send me the code by email"))

def validate_id(form, field):
def validate_id(self, field):
if not Project.query.get(field.data):
raise ValidationError(_("This project does not exists"))

Expand Down Expand Up @@ -398,14 +398,14 @@ def __init__(self, project, edit=False, *args, **kwargs):
self.project = project
self.edit = edit

def validate_name(form, field):
if field.data == form.name.default:
def validate_name(self, field):
if field.data == self.name.default:
raise ValidationError(_("The participant name is invalid"))
if (
not form.edit
not self.edit
and Person.query.filter(
Person.name == field.data,
Person.project == form.project,
Person.project == self.project,
Person.activated,
).all()
): # NOQA
Expand All @@ -428,8 +428,8 @@ class InviteForm(FlaskForm):
emails = StringField(_("People to notify"), render_kw={"class": "tag"})
submit = SubmitField(_("Send invites"))

def validate_emails(form, field):
for email in [email.strip() for email in form.emails.data.split(",")]:
def validate_emails(self, field):
for email in [email.strip() for email in self.emails.data.split(",")]:
try:
email_validator.validate_email(email)
except email_validator.EmailNotValidError:
Expand Down
2 changes: 1 addition & 1 deletion ihatemoney/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def gen_secret_key():
random.SystemRandom().choice(
"abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
)
for i in range(50)
for _ in range(50)
]
)

Expand Down
3 changes: 1 addition & 2 deletions ihatemoney/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ <h2>{{ _("Manage your shared <br />expenses, easily") }}</h2>
id="authentication-form"
class="form-horizontal"
action="{{ url_for('.authenticate') }}"
method="post"
>
method="post">
<fieldset class="form-group">
<legend></legend>
{{ forms.authenticate(auth_form, home=True) }}
Expand Down
9 changes: 5 additions & 4 deletions ihatemoney/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

from babel import Locale
from babel.numbers import get_currency_name, get_currency_symbol
from flask import current_app, escape, redirect, render_template
from flask import current_app, redirect, render_template
from flask_babel import get_locale, lazy_gettext as _
import jinja2
from markupsafe import Markup
from werkzeug.routing import HTTPException, RoutingException
from markupsafe import Markup, escape
from werkzeug.exceptions import HTTPException
from werkzeug.routing import RoutingException


def slugify(value):
Expand Down Expand Up @@ -329,7 +330,7 @@ def em_surround(string, regex_escape=False):
string = escape(string)

if regex_escape:
return fr'<em class="font-italic">{string}<\/em>'
return rf'<em class="font-italic">{string}<\/em>'
else:
return f'<em class="font-italic">{string}</em>'

Expand Down

0 comments on commit 7c3ced0

Please sign in to comment.