Untitled
unknown
python
2 years ago
6.1 kB
5
Indexable
from datetime import date from turtle import width from django import forms from .models import Student, Deposit, Dailylog from django.core.exceptions import ValidationError class DateInput(forms.DateInput): input_type = "date" class Studentform(forms.ModelForm): class Meta: model = Student fields = "__all__" exclude = ["is_deleted"] def __init__(self, *args, **kwargs): super(Studentform, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class DailylogForm(forms.ModelForm): description = forms.CharField(max_length=500) description.widget = forms.Textarea() class Meta: model = Dailylog fields = "__all__" exclude = ["trainer_id"] def __init__(self, *args, **kwargs): super(DailylogForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class EnrollmentForm(forms.Form): school = forms.ModelChoiceField(queryset=None) school.widget = forms.Select( attrs={"hx-get": "/getschoolclasses", "hx-target": "#id_student_class"} ) student_class = forms.CharField(label="Class") student_class.widget = forms.Select( { "hx-get": "/getstudents", "hx-target": "#id_student", "hx-include": "[name='school']", } ) student = forms.CharField(label="Student") student.widget = forms.Select( { "hx-get": "/getcourses", "hx-target": "#id_course", "hx-include": "[name='enrollmentForm']", } ) course = forms.CharField(label="Course") course.widget = forms.Select() def __init__(self, *args, **kwargs): super(EnrollmentForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class DuplicateSMSForm(forms.Form): school = forms.ModelChoiceField(queryset=None) school.widget = forms.Select( attrs={"hx-get": "/getschoolclasses", "hx-target": "#id_student_class"} ) student_class = forms.CharField(label="Class") student_class.widget = forms.Select( { "hx-get": "/getstudents", "hx-target": "#id_student", "hx-include": "[name='school']", } ) student = forms.CharField(label="Student") student.widget = forms.Select( { "hx-get": "/getstudentpayments", "hx-target": "#id_payment", "hx-include": "[name='enrollmentForm']", } ) payment = forms.CharField(label="Payment") payment.widget = forms.Select() def __init__(self, *args, **kwargs): super(DuplicateSMSForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class PaymentForm(forms.Form): YEAR_OPTIONS = [ ("2019", "2019-2020"), ("2020", "2020-2021"), ("2021", "2021-2022"), ("2022", "2022-2023"), ("2023", "2023-2024"), ("2024", "2024-2025"), ] PAYMENT_CHOICES = [ ("CAS", "Cash"), ("CHQ", "Cheque"), ("ONL", "Online"), ("UPI", "UPI"), ("NFT", "NEFT"), ] school = forms.ModelChoiceField(queryset=None) school.widget = forms.Select( attrs={"hx-get": "/getschoolclasses", "hx-target": "#id_student_class"} ) session = forms.ChoiceField(choices=YEAR_OPTIONS) student_class = forms.CharField(label="Class") student_class.widget = forms.Select( { "hx-get": "/getstudents", "hx-target": "#id_student", "hx-include": "[name='school']", } ) student = forms.CharField(label="Student") student.widget = forms.Select( { "hx-get": "/getenrolledcourses", "hx-target": "#id_course", "hx-include": "[name='enrollmentForm']", } ) course = forms.CharField(label="Course") course.widget = forms.Select() mode = forms.ChoiceField(choices=PAYMENT_CHOICES) chq_no = forms.CharField(max_length=10,required=False) amount = forms.IntegerField() remarks = forms.CharField(max_length=50,required=False) def __init__(self, *args, **kwargs): super(PaymentForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class DepositForm(forms.ModelForm): class Meta: model = Deposit fields = "__all__" exclude = ["trainer_id"] widgets = {"date_of_deposit": DateInput()} def __init__(self, *args, **kwargs): super(DepositForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" class CsvImportForm(forms.Form): csv_upload = forms.FileField() class PasswordChangeForm(forms.Form): password1 = forms.CharField(label="New Password", widget=forms.PasswordInput) password2 = forms.CharField( label="Password confirmation", widget=forms.PasswordInput ) def __init__(self, *args, **kwargs): super(PasswordChangeForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): visible.field.widget.attrs["class"] = "form-control" def clean_password2(self): # Check that the two password entries match password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise ValidationError("Passwords don't match") return password2
Editor is loading...