Download apps/organization/forms.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/forms.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/organization/forms.py
-
curl -L -o forms.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/forms.py
1.93 kB
| from __future__ import annotations | |
| import re | |
| from typing import Any | |
| from django import forms | |
| from django.contrib.auth.forms import UserCreationForm | |
| from django.core.exceptions import ValidationError | |
| from django.utils.translation import gettext_lazy as _ | |
| from .models import Lawyer | |
| class LawyerRegistrationForm(UserCreationForm[Lawyer]): | |
| class Meta: | |
| model = Lawyer | |
| fields = ("username", "password1", "password2") | |
| def __init__(self, *args: Any, **kwargs: Any) -> None: | |
| super().__init__(*args, **kwargs) | |
| self.fields["username"].widget.attrs.update( | |
| { | |
| "class": "form-input", | |
| "placeholder": str(_("请输入中文姓名")), | |
| "autocomplete": "username", | |
| } | |
| ) | |
| self.fields["password1"].widget.attrs.update( | |
| { | |
| "class": "form-input", | |
| "placeholder": str(_("请输入密码")), | |
| "autocomplete": "new-password", | |
| } | |
| ) | |
| self.fields["password2"].widget.attrs.update( | |
| { | |
| "class": "form-input", | |
| "placeholder": str(_("请确认密码")), | |
| "autocomplete": "new-password", | |
| } | |
| ) | |
| self.fields["username"].label = _("用户名/真实姓名") | |
| self.fields["password1"].label = _("密码") | |
| self.fields["password2"].label = _("确认密码") | |
| self.fields["username"].help_text = _("只能输入中文") | |
| self.fields["password1"].help_text = "" | |
| self.fields["password2"].help_text = "" | |
| def clean_username(self) -> str: | |
| username: str | None = self.cleaned_data.get("username") | |
| if username: | |
| if not re.match(r"^[\u4e00-\u9fa5]+$", username): | |
| raise ValidationError(_("用户名只能输入中文")) | |
| if username is None: | |
| username = "" | |
| return username | |