django/base/forms.py

62 lines
2.1 KiB
Python
Executable File

from django import forms
from django.forms import ModelForm
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']
class VendorEditForm(ModelForm):
class Meta:
model = VendorsData
fields = ['vendorCoverAmount', 'vendorPaidNotification', 'vendorPayWindow', 'vendorWebName', 'vendorWebAddr', 'vendorNetworkFee']
class VendorAddrAddForm(ModelForm):
class Meta:
model = VendorsAddresses
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)