Unit Tests / test (push) Successful in 3s
## Summary Closes #20. - Bump Django pin from `>=5.2,<6` to `>=6.0,<7` (resolved **6.0.7**) and refresh `uv.lock` - Update `TimeInfoBase.save` for Django 6 keyword-only `Model.save` - Pass `required_score` directly to `ReCaptchaV3` (removes django-recaptcha deprecation warning) - Fix `Payments.date` fixed default → callable `timezone.now` (+ migration `0012`) Reviewed against [Django 6.0 release notes](https://docs.djangoproject.com/en/6.0/releases/6.0/). `DEFAULT_AUTO_FIELD` already `BigAutoField`. No other removed APIs in use. **Compat notes** - `django-phonenumber-field` 8.4.0 advertises Django 6.0 support - `django-recaptcha` 4.1.0 has no upper Django bound; classifiers still list through 5.2 only — smoke-tested via suite ## Test plan - [x] `uv run python manage.py check` — clean - [x] `uv run python manage.py test` — 30 passed - [ ] CI unit tests green on this PR - [ ] Smoke board pages, membership form, auth/sign-in, recaptcha after merge/deploy Reviewed-on: #26
148 lines
4.7 KiB
Python
148 lines
4.7 KiB
Python
from django import forms
|
|
from django.forms import ModelForm
|
|
from .models import (
|
|
Membership,
|
|
CommunityPost,
|
|
AddressModel1,
|
|
MembershipPerson,
|
|
MembershipCommittee,
|
|
MembershipServices,
|
|
)
|
|
from phonenumber_field.formfields import PhoneNumberField
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django_recaptcha.fields import ReCaptchaField
|
|
from django.conf import settings
|
|
from django_recaptcha.widgets import ReCaptchaV3
|
|
|
|
class CaptchaForm(forms.Form):
|
|
captcha = ReCaptchaField(
|
|
public_key=settings.RECAPTCHA_PUBLIC_KEY,
|
|
private_key=settings.RECAPTCHA_PRIVATE_KEY,
|
|
widget=ReCaptchaV3(required_score=0.85),
|
|
)
|
|
|
|
|
|
class ChildrenForm(ModelForm):
|
|
class Meta:
|
|
model = Membership
|
|
fields = ["children"]
|
|
|
|
|
|
class AddressForm(ModelForm):
|
|
class Meta:
|
|
model = AddressModel1
|
|
fields = ["address_1", "address_2", "city", "state", "zip_code"]
|
|
|
|
class CommunityPostForm(ModelForm):
|
|
class Meta:
|
|
model = CommunityPost
|
|
fields = ['title','category','content']
|
|
|
|
class PeopleForm(ModelForm):
|
|
phone_number = PhoneNumberField(required=False)
|
|
|
|
def clean(self):
|
|
cleaned_data = super().clean()
|
|
if cleaned_data.get("phone_number"):
|
|
if (
|
|
len(cleaned_data.get("first_name")) == 0
|
|
or len(cleaned_data.get("last_name")) == 0
|
|
or len(cleaned_data.get("email")) == 0
|
|
or len(cleaned_data.get("phone_number").raw_input) == 0
|
|
):
|
|
raise ValidationError("A Field is missing")
|
|
else:
|
|
raise ValidationError("No phone number provided")
|
|
|
|
class Meta:
|
|
model = MembershipPerson
|
|
fields = ["first_name", "last_name", "phone_number", "email"]
|
|
|
|
|
|
class CommitteeForm(ModelForm):
|
|
block_captain = forms.BooleanField(
|
|
label="I can serve as a Block Captain (distribute newsletters & directories)",
|
|
required=False,
|
|
)
|
|
coordinator = forms.BooleanField(
|
|
label="I can serve as a Coordinator, SCHA Board Member Position (oversee & organize block captains)",
|
|
required=False,
|
|
)
|
|
egg_hunt = forms.BooleanField(label="Easter Egg Hunt (late March)", required=False)
|
|
spring_garage_sale = forms.BooleanField(
|
|
label="Spring Garage Sale (May/June)", required=False
|
|
)
|
|
golf_outing = forms.BooleanField(label="Golf Outing (Summer)", required=False)
|
|
ice_cream_social = forms.BooleanField(
|
|
label="Ice Creame Social (August)", required=False
|
|
)
|
|
fall_garage_sale = forms.BooleanField(
|
|
label="Fall Garage Sale (September/October)", required=False
|
|
)
|
|
halloween_party = forms.BooleanField(
|
|
label="Halloween Party (October)", required=False
|
|
)
|
|
santa_visit = forms.BooleanField(label="Santa Visits (December)", required=False)
|
|
website = forms.BooleanField(
|
|
label="SCHA Newsletter/Website (wite articles, edit, report, etc)",
|
|
required=False,
|
|
)
|
|
civic_affair = forms.BooleanField(
|
|
label="Civic Affairs Journalist (report on school board/city council mtgs)",
|
|
required=False,
|
|
)
|
|
phone_directory = forms.BooleanField(
|
|
label="Annual Phone Directory (Help compile, edit, produce our Annual Neighborhood Directory)",
|
|
required=False,
|
|
)
|
|
no_preference = forms.BooleanField(
|
|
label="No Preference. I want to help in some way . Please email me.",
|
|
required=False,
|
|
)
|
|
|
|
class Meta:
|
|
model = MembershipCommittee
|
|
fields = [
|
|
"block_captain",
|
|
"coordinator",
|
|
"egg_hunt",
|
|
"spring_garage_sale",
|
|
"golf_outing",
|
|
"ice_cream_social",
|
|
"fall_garage_sale",
|
|
"halloween_party",
|
|
"santa_visit",
|
|
"website",
|
|
"civic_affair",
|
|
"phone_directory",
|
|
"no_preference",
|
|
]
|
|
|
|
|
|
class ServicesForm(ModelForm):
|
|
babysitting = forms.BooleanField(label="Babysitting", required=False)
|
|
lawn_mowing = forms.BooleanField(label="Lawn Mowing", required=False)
|
|
snow_shoveling = forms.BooleanField(label="Snow Shoveling", required=False)
|
|
leaf_raking = forms.BooleanField(label="Leaf Raking", required=False)
|
|
petsitting = forms.BooleanField(label="Petsitting", required=False)
|
|
house_sitting = forms.BooleanField(label="Housesitting", required=False)
|
|
other = forms.BooleanField(label="Other", required=False)
|
|
|
|
class Meta:
|
|
model = MembershipServices
|
|
fields = [
|
|
"babysitting",
|
|
"lawn_mowing",
|
|
"snow_shoveling",
|
|
"leaf_raking",
|
|
"petsitting",
|
|
"house_sitting",
|
|
"other",
|
|
"other_desc",
|
|
]
|
|
|
|
|
|
class PaymentImport(ModelForm):
|
|
pass
|