Restrict user input to more sensible ranges #251
1 changed files with 18 additions and 3 deletions
|
|
@ -9,7 +9,17 @@ from servala.core.odoo import get_invoice_addresses, get_odoo_countries
|
|||
from servala.frontend.forms.mixins import HtmxMixin
|
||||
|
||||
|
||||
ORG_NAME_PATTERN = r"[\w\s\-.,&'()+]+"
|
||||
|
||||
|
||||
class OrganizationForm(HtmxMixin, ModelForm):
|
||||
name_validator = RegexValidator(
|
||||
regex=f"^{ORG_NAME_PATTERN}$",
|
||||
message=_(
|
||||
"Organization name can only contain letters, numbers, spaces, and common punctuation (-.,&'()+)."
|
||||
),
|
||||
)
|
||||
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# super().__init__(*args, **kwargs)
|
||||
# if self.instance and self.instance.has_inherited_billing_entity:
|
||||
|
|
@ -20,15 +30,20 @@ class OrganizationForm(HtmxMixin, ModelForm):
|
|||
widgets = {
|
||||
"name": forms.TextInput(
|
||||
attrs={
|
||||
"maxlength": "32",
|
||||
"pattern": "[A-Za-z0-9\\s]+",
|
||||
"maxlength": "100",
|
||||
"pattern": ORG_NAME_PATTERN,
|
||||
"title": _(
|
||||
"Organization name can only contain letters, numbers, and spaces"
|
||||
"Organization name can contain letters, numbers, spaces, and common punctuation (-.,&'()+). Emoji not allowed."
|
||||
),
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["name"].validators.append(self.name_validator)
|
||||
self.fields["name"].max_length = 100
|
||||
|
||||
|
||||
class OrganizationCreateForm(OrganizationForm):
|
||||
address_validator = RegexValidator(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue