Compare commits
No commits in common. "61fd1849ed22706e662e942e1647432d452a2a72" and "5c6bfd8b4976fead4261109036bc8ad2b02a3730" have entirely different histories.
61fd1849ed
...
5c6bfd8b49
@ -17,6 +17,8 @@
|
||||
"""The forms for the currency management.
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, ValidationError
|
||||
from wtforms.validators import DataRequired, Regexp, NoneOf
|
||||
@ -28,25 +30,22 @@ from accounting.utils.strip_text import strip_text
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
|
||||
|
||||
class CodeUnique:
|
||||
"""The validator to check if the code is unique."""
|
||||
|
||||
def __call__(self, form: FlaskForm, field: StringField) -> None:
|
||||
if field.data == "":
|
||||
return
|
||||
if not isinstance(form, CurrencyForm):
|
||||
return
|
||||
if form.obj_code is not None and form.obj_code == field.data:
|
||||
return
|
||||
if db.session.get(Currency, field.data) is not None:
|
||||
raise ValidationError(lazy_gettext(
|
||||
"Code conflicts with another currency."))
|
||||
|
||||
|
||||
class CurrencyForm(FlaskForm):
|
||||
"""The form to create or edit a currency."""
|
||||
CODE_BLOCKLIST: list[str] = ["create", "store", "exists-code"]
|
||||
"""The reserved codes that are not available."""
|
||||
|
||||
class CodeUnique:
|
||||
"""The validator to check if the code is unique."""
|
||||
def __call__(self, form: CurrencyForm, field: StringField) -> None:
|
||||
if field.data == "":
|
||||
return
|
||||
if form.obj_code is not None and form.obj_code == field.data:
|
||||
return
|
||||
if db.session.get(Currency, field.data) is not None:
|
||||
raise ValidationError(lazy_gettext(
|
||||
"Code conflicts with another currency."))
|
||||
|
||||
code = StringField(
|
||||
filters=[strip_text],
|
||||
validators=[DataRequired(lazy_gettext("Please fill in the code.")),
|
||||
|
@ -17,6 +17,8 @@
|
||||
"""The journal entry sub-forms for the transaction management.
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from flask_babel import LazyString
|
||||
|
@ -17,6 +17,8 @@
|
||||
"""The reorder forms for the transaction management.
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
|
||||
from flask import request
|
||||
|
@ -17,6 +17,8 @@
|
||||
"""The account option for the transaction management.
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from accounting.models import Account
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user