django/base/forms.py

62 lines
2.1 KiB
Python
Raw Normal View History

2023-12-05 14:46:34 +00:00
from django import forms
2023-05-05 20:16:08 +00:00
from django.forms import ModelForm
2023-12-05 14:46:34 +00:00
from users.models import User
from .models import VendorsData, VendorsAddresses, InvoiceCreation, ApiPaymentCreation
from django.contrib.auth.forms import SetPasswordForm, PasswordResetForm
class InvoiceCreationForm(ModelForm):
class Meta:
model = InvoiceCreation
fields = ['invoiceID', 'invoiceAmount', 'invoiceCoin', 'invoiceCallbackLink', 'invoiceReturnLink', 'invoiceCoin']
class ApiPaymentCreationForm(ModelForm):
class Meta:
model = ApiPaymentCreation
fields = ['userUUID', 'usercallbackUrl','userIP','userCoin','statusFlag','paidFlag','ourAddr']
2023-05-05 20:16:08 +00:00
class VendorEditForm(ModelForm):
class Meta:
model = VendorsData
2023-05-30 09:30:00 +00:00
fields = ['vendorCoverAmount', 'vendorPaidNotification', 'vendorPayWindow', 'vendorWebName', 'vendorWebAddr', 'vendorNetworkFee']
class VendorAddrAddForm(ModelForm):
class Meta:
model = VendorsAddresses
2023-12-05 14:46:34 +00:00
fields = ['coin', 'address']
class UserRegistrationForm(ModelForm):
MIN_LENGTH = 8
class Meta:
model = User
fields = ['first_name', 'last_name', 'email', 'password']
def clean_email(self):
email = self.cleaned_data.get('email')
if User.objects.filter(email=email).exists():
raise forms.ValidationError('Email used, try reseting the password if thats you.')
return email
def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('password')
if len(password) < self.MIN_LENGTH:
raise forms.ValidationError('The password you are trying to use is too short')
class SetPasswordForm(SetPasswordForm):
class Meta:
model = User()
fields = ['new_password1', 'new_password2']
def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('new_password1')
password2 = cleaned_data.get('new_password2')
class PasswordResetForm(PasswordResetForm):
class Meta:
model = User()
fields = ['email']
def __init__(self, *args, **kwargs):
super(PasswordResetForm, self).__init__(*args, **kwargs)