|
2 | 2 |
|
3 | 3 | from django import forms |
4 | 4 |
|
5 | | -from .models import Refund |
| 5 | +from .models import Proposal, Refund |
6 | 6 |
|
7 | 7 | UUID_LAST_DIGITS = 12 |
8 | 8 |
|
9 | 9 |
|
| 10 | +class ProposalForm(forms.ModelForm): |
| 11 | + class Meta: |
| 12 | + model = Proposal |
| 13 | + fields = [ |
| 14 | + "name", |
| 15 | + "surname", |
| 16 | + "email", |
| 17 | + "title", |
| 18 | + "description", |
| 19 | + ] |
| 20 | + |
| 21 | + def __init__(self, event, *args, **kwargs): |
| 22 | + super().__init__(*args, **kwargs) |
| 23 | + self.fields["name"].widget.attrs.update( |
| 24 | + { |
| 25 | + "id": "cfp-name", |
| 26 | + "size": "20", |
| 27 | + "placeholder": "Tu nombre", |
| 28 | + "class": "input is-rounded", |
| 29 | + } |
| 30 | + ) |
| 31 | + self.fields["surname"].widget.attrs.update( |
| 32 | + { |
| 33 | + "id": "cfp-surname", |
| 34 | + "size": "40", |
| 35 | + "placeholder": "Tus apellidos", |
| 36 | + "class": "input is-rounded", |
| 37 | + } |
| 38 | + ) |
| 39 | + self.fields["email"].widget.attrs.update( |
| 40 | + { |
| 41 | + "id": "cfp-email", |
| 42 | + "size": "40", |
| 43 | + "placeholder": "Tu email", |
| 44 | + "class": "input is-rounded", |
| 45 | + } |
| 46 | + ) |
| 47 | + self.fields["title"].widget.attrs.update( |
| 48 | + { |
| 49 | + "id": "cfp-title", |
| 50 | + "size": "60", |
| 51 | + "placeholder": "El título de tu maravillosa charla", |
| 52 | + "class": "input is-rounded", |
| 53 | + } |
| 54 | + ) |
| 55 | + self.fields["description"].widget.attrs.update( |
| 56 | + { |
| 57 | + "id": "cfp-title", |
| 58 | + "cols": "60", |
| 59 | + "rows": "20", |
| 60 | + "placeholder": ("El texto de tu maravillosa charla. " |
| 61 | + "¿Aceptamos markdown? ¡Por supuesto!"), |
| 62 | + "class": "textarea", |
| 63 | + } |
| 64 | + ) |
| 65 | + self.event = event |
| 66 | + |
| 67 | + def save(self): |
| 68 | + proposal = super().save(commit=False) |
| 69 | + proposal.event = self.event |
| 70 | + proposal.save() |
| 71 | + return proposal |
| 72 | + |
| 73 | + |
10 | 74 | class EmailForm(forms.Form): |
11 | | - email = forms.EmailField(label='Tu email', max_length=192) |
| 75 | + email = forms.EmailField(label="Tu email", max_length=192) |
12 | 76 |
|
13 | 77 |
|
14 | 78 | class WaitingListForm(forms.Form): |
15 | | - email = forms.EmailField(label='Tu email', max_length=192) |
16 | | - name = forms.CharField(label='Nombre', max_length=256) |
17 | | - surname = forms.CharField(label='Apellidos', max_length=256) |
18 | | - phone = forms.CharField(label='Teléfono', max_length=32) |
| 79 | + email = forms.EmailField(label="Tu email", max_length=192) |
| 80 | + name = forms.CharField(label="Nombre", max_length=256) |
| 81 | + surname = forms.CharField(label="Apellidos", max_length=256) |
| 82 | + phone = forms.CharField(label="Teléfono", max_length=32) |
19 | 83 |
|
20 | 84 |
|
21 | 85 | class RefundForm(forms.Form): |
22 | | - email = forms.EmailField(label='Tu email', max_length=192) |
| 86 | + email = forms.EmailField(label="Tu email", max_length=192) |
23 | 87 | uuid = forms.CharField() |
24 | 88 |
|
25 | 89 | def __init__(self, event, *args, **kwargs): |
26 | | - logging.error('Llamada al metodo __init__ de RefundForm') |
| 90 | + logging.error("Llamada al metodo __init__ de RefundForm") |
27 | 91 | super().__init__(*args, **kwargs) |
28 | 92 | self.event = event |
29 | 93 |
|
30 | 94 | def clean_uuid(self): |
31 | 95 | email = self.cleaned_data["email"] |
32 | 96 | uuid = self.cleaned_data["uuid"] |
33 | | - if uuid == 'tu puta madre': |
34 | | - raise forms.ValidationError('Cuida ese vocabulario') |
| 97 | + if uuid == "tu puta madre": |
| 98 | + raise forms.ValidationError("Cuida ese vocabulario") |
35 | 99 |
|
36 | 100 | if len(uuid) < UUID_LAST_DIGITS: |
37 | 101 | raise forms.ValidationError( |
38 | | - 'Necesito los últimos () letras o dígitos ' |
39 | | - 'del código'.format(UUID_LAST_DIGITS) |
40 | | - ) |
| 102 | + "Necesito los últimos () letras o dígitos " |
| 103 | + "del código".format(UUID_LAST_DIGITS) |
| 104 | + ) |
41 | 105 | uuid = uuid[-UUID_LAST_DIGITS:] |
42 | 106 | tickets = list( |
43 | 107 | self.event.all_tickets() |
44 | 108 | .filter(customer_email=email) |
45 | 109 | .filter(keycode__iendswith=uuid) |
46 | | - ) |
| 110 | + ) |
47 | 111 | if len(tickets) != 1: |
48 | 112 | raise forms.ValidationError( |
49 | | - 'El correo o las últimos {} letras o dígitos del' |
50 | | - ' codigo están mal.'.format(UUID_LAST_DIGITS) |
51 | | - ) |
| 113 | + "El correo o las últimos {} letras o dígitos del" |
| 114 | + " codigo están mal.".format(UUID_LAST_DIGITS) |
| 115 | + ) |
52 | 116 | self.ticket = tickets[0] |
53 | 117 | if Refund.exists(self.event, self.ticket): |
54 | 118 | raise forms.ValidationError( |
55 | | - 'Ya se ha solicitado una devolución del' |
56 | | - ' importe para ese ticket' |
57 | | - ) |
| 119 | + "Ya se ha solicitado una devolución del" " importe para ese ticket" |
| 120 | + ) |
58 | 121 | return uuid |
0 commit comments