-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
78 lines (48 loc) · 2.01 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from django import forms
from .models import *
class BuyPackageForm(forms.ModelForm):
number_phone = forms.CharField(max_length=25)
transaction = forms.CharField(required=False, max_length=25)
subscription = forms.CharField(required=False, max_length=1000)
class Meta:
model = Subscription
fields = ['package', ]
# def clean_transaction(self):
# transaction = self.data['transaction']
# transaction = ''.join(transaction.split(' '))
def clean_number_phone(self):
phone = self.data['number_phone']
phone = ''.join(phone.split(' '))
if len(phone) == 9:
pass
else:
self.add_error("number_phone", "number phone must contain 9 digits.")
if phone.startswith('06') or phone.startswith('05'):
pass
else:
# N° de téléphone invalide
self.add_error("number_phone", "number phone must begin by 05 or 06")
if phone.isdigit():
pass
else:
self.add_error("number_phone", "number phone must contain only digits.")
return phone
def clean_subscription(self):
id_subscription = self.data.get('subscription')
if id_subscription:
if Subscription.objects.filter(id=id_subscription).exists():
pass
else:
self.add_error('subscription', 'There are errors!')
class CheckTransactionForm(forms.ModelForm):
subscription = forms.IntegerField()
class Meta:
model = Transaction
fields = ['uuid_transaction', ]
def clean_uuid_transaction(self):
id_transaction = self.data.get('uuid_transaction')
if id_transaction:
if Transaction.objects.filter(uuid_transaction=id_transaction).exists():
pass
else:
self.add_error('uuid_transaction', "Cet ID de transaction n'existe pas.")