121 lines
5.1 KiB
Python
121 lines
5.1 KiB
Python
from django import forms
|
|
from .models import Voter, Interaction, Donation, VoterLikelihood, InteractionType, DonationMethod, ElectionType, Event, EventParticipation, EventType
|
|
|
|
class VoterForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Voter
|
|
fields = [
|
|
'first_name', 'last_name', 'address_street', 'city', 'state',
|
|
'zip_code', 'county', 'latitude', 'longitude',
|
|
'phone', 'email', 'voter_id', 'district', 'precinct',
|
|
'registration_date', 'is_targeted', 'candidate_support', 'yard_sign'
|
|
]
|
|
widgets = {
|
|
'registration_date': forms.DateInput(attrs={'type': 'date'}),
|
|
'latitude': forms.TextInput(attrs={'class': 'form-control bg-light'}),
|
|
'longitude': forms.TextInput(attrs={'class': 'form-control bg-light'}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
for name, field in self.fields.items():
|
|
if name in ['latitude', 'longitude']:
|
|
continue
|
|
if isinstance(field.widget, forms.CheckboxInput):
|
|
field.widget.attrs.update({'class': 'form-check-input'})
|
|
else:
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
|
|
self.fields['candidate_support'].widget.attrs.update({'class': 'form-select'})
|
|
self.fields['yard_sign'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class InteractionForm(forms.ModelForm):
|
|
# ... (rest of the file remains the same)
|
|
class Meta:
|
|
model = Interaction
|
|
fields = ['type', 'date', 'description', 'notes']
|
|
widgets = {
|
|
'date': forms.DateInput(attrs={'type': 'date'}),
|
|
'notes': forms.Textarea(attrs={'rows': 2}),
|
|
}
|
|
|
|
def __init__(self, *args, tenant=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if tenant:
|
|
self.fields['type'].queryset = InteractionType.objects.filter(tenant=tenant, is_active=True)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['type'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class DonationForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Donation
|
|
fields = ['date', 'method', 'amount']
|
|
widgets = {
|
|
'date': forms.DateInput(attrs={'type': 'date'}),
|
|
}
|
|
|
|
def __init__(self, *args, tenant=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if tenant:
|
|
self.fields['method'].queryset = DonationMethod.objects.filter(tenant=tenant, is_active=True)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['method'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class VoterLikelihoodForm(forms.ModelForm):
|
|
class Meta:
|
|
model = VoterLikelihood
|
|
fields = ['election_type', 'likelihood']
|
|
|
|
def __init__(self, *args, tenant=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if tenant:
|
|
self.fields['election_type'].queryset = ElectionType.objects.filter(tenant=tenant, is_active=True)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['election_type'].widget.attrs.update({'class': 'form-select'})
|
|
self.fields['likelihood'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class EventParticipationForm(forms.ModelForm):
|
|
class Meta:
|
|
model = EventParticipation
|
|
fields = ['event', 'participation_type']
|
|
|
|
def __init__(self, *args, tenant=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if tenant:
|
|
self.fields['event'].queryset = Event.objects.filter(tenant=tenant)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['event'].widget.attrs.update({'class': 'form-select'})
|
|
self.fields['participation_type'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class EventForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Event
|
|
fields = ['date', 'event_type', 'description']
|
|
widgets = {
|
|
'date': forms.DateInput(attrs={'type': 'date'}),
|
|
'description': forms.Textarea(attrs={'rows': 2}),
|
|
}
|
|
|
|
def __init__(self, *args, tenant=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if tenant:
|
|
self.fields['event_type'].queryset = EventType.objects.filter(tenant=tenant, is_active=True)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['event_type'].widget.attrs.update({'class': 'form-select'})
|
|
|
|
class EventTypeForm(forms.ModelForm):
|
|
class Meta:
|
|
model = EventType
|
|
fields = ['name', 'is_active']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
for field in self.fields.values():
|
|
if not isinstance(field.widget, forms.CheckboxInput):
|
|
field.widget.attrs.update({'class': 'form-control'})
|
|
self.fields['is_active'].widget.attrs.update({'class': 'form-check-input'}) |