mirror of
https://github.com/kjanat/livegraphs-django.git
synced 2026-02-13 15:15:43 +01:00
- Add ty.toml configuration with Django project root - Add py.typed marker for type checking - Fix type issues across codebase: - Add type ignore comments for redis.exceptions imports - Fix django.db.models.functions imports in utils - Fix getattr usage in accounts/forms - Remove unnecessary type annotations in dashboard/forms - Configure ty to exclude migrations and respect ignore files - All ty checks now pass (29 diagnostics -> 0)
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# accounts/forms.py
|
|
|
|
from django import forms
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
|
|
from .models import Company, CustomUser
|
|
|
|
|
|
class CustomUserCreationForm(UserCreationForm):
|
|
"""Form for creating new users"""
|
|
|
|
class Meta:
|
|
model = CustomUser
|
|
fields = ("username", "email", "password1", "password2")
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Add help text for fields
|
|
self.fields["email"].required = True
|
|
self.fields["email"].help_text = "Required. Enter a valid email address."
|
|
|
|
|
|
class CustomUserChangeForm(forms.ModelForm):
|
|
"""Form for updating users"""
|
|
|
|
class Meta:
|
|
model = CustomUser
|
|
fields = ("username", "email", "company", "is_company_admin")
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
# Only staff members can change company and admin status
|
|
instance = kwargs.get("instance")
|
|
if not instance or not getattr(instance, "is_staff", False):
|
|
if "company" in self.fields:
|
|
self.fields["company"].disabled = True
|
|
if "is_company_admin" in self.fields:
|
|
self.fields["is_company_admin"].disabled = True
|
|
|
|
|
|
class CompanyForm(forms.ModelForm):
|
|
"""Form for creating and updating companies"""
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = ("name", "description")
|