Some small cleanups

This commit is contained in:
Alexis Métaireau 2021-12-23 00:19:35 +01:00 committed by Glandos
parent ed6676485a
commit 4698061276
5 changed files with 24 additions and 23 deletions

View file

@ -162,8 +162,8 @@ class EditProjectForm(FlaskForm):
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
@ -234,13 +234,13 @@ class ProjectForm(EditProjectForm):
)
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))
@ -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))
@ -277,11 +277,11 @@ class DestructiveActionProjectForm(FlaskForm):
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."))
@ -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"))
@ -398,14 +398,14 @@ class MemberForm(FlaskForm):
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
@ -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:

View file

@ -62,7 +62,7 @@ def generate_config(config_file):
random.SystemRandom().choice(
"abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
)
for i in range(50)
for _ in range(50)
]
)

View file

@ -42,8 +42,7 @@
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) }}

View file

@ -12,11 +12,12 @@ import socket
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):

View file

@ -11,6 +11,7 @@ and `add_project_id` for a quick overview)
from functools import wraps
import json
import os
from datetime import datetime
from flask import (
Blueprint,