Commit 600590deeb462a4a59d571afee48b631e5d59346
1 parent
413e0a5d
Exists in
master
and in
3 other branches
Resolvendo bug do tipo Retrabalho com upload de arquivo em caso de erro no preen…
…chimento de um formulário para as UC's de usuario
Showing
2 changed files
with
36 additions
and
18 deletions
Show diff stats
amadeus/settings.py
@@ -56,6 +56,7 @@ INSTALLED_APPS = [ | @@ -56,6 +56,7 @@ INSTALLED_APPS = [ | ||
56 | 'django_crontab', | 56 | 'django_crontab', |
57 | 'django_cron', | 57 | 'django_cron', |
58 | 'channels', | 58 | 'channels', |
59 | + 'resubmit', # Utilizado para salvar arquivos na cache, para caso o formulario não seja preenchido corretamente o usuário não precise fazer o upload outra vez dos arquivos | ||
59 | 60 | ||
60 | 'amadeus', | 61 | 'amadeus', |
61 | 'users', | 62 | 'users', |
@@ -120,6 +121,17 @@ TEMPLATES = [ | @@ -120,6 +121,17 @@ TEMPLATES = [ | ||
120 | }, | 121 | }, |
121 | ] | 122 | ] |
122 | 123 | ||
124 | + | ||
125 | +CACHES = { | ||
126 | + 'default': { | ||
127 | + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
128 | + }, | ||
129 | + "resubmit": { | ||
130 | + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', | ||
131 | + "LOCATION": os.path.join(BASE_DIR, 'data/cache/resubmit'), | ||
132 | + }, | ||
133 | +} | ||
134 | + | ||
123 | WSGI_APPLICATION = 'amadeus.wsgi.application' | 135 | WSGI_APPLICATION = 'amadeus.wsgi.application' |
124 | 136 | ||
125 | SESSION_SECURITY_WARN_AFTER = 1140 | 137 | SESSION_SECURITY_WARN_AFTER = 1140 |
@@ -357,11 +369,11 @@ SUMMERNOTE_CONFIG = { | @@ -357,11 +369,11 @@ SUMMERNOTE_CONFIG = { | ||
357 | # Set `upload_to` function for attachments. | 369 | # Set `upload_to` function for attachments. |
358 | #'attachment_upload_to': my_custom_upload_to_func(), | 370 | #'attachment_upload_to': my_custom_upload_to_func(), |
359 | 371 | ||
360 | - | 372 | + |
361 | 373 | ||
362 | } | 374 | } |
363 | 375 | ||
364 | try: | 376 | try: |
365 | from .local_settings import * | 377 | from .local_settings import * |
366 | except ImportError: | 378 | except ImportError: |
367 | - pass | ||
368 | \ No newline at end of file | 379 | \ No newline at end of file |
380 | + pass |
users/forms.py
@@ -5,6 +5,9 @@ from rolepermissions.shortcuts import assign_role | @@ -5,6 +5,9 @@ from rolepermissions.shortcuts import assign_role | ||
5 | from django.contrib.auth import update_session_auth_hash | 5 | from django.contrib.auth import update_session_auth_hash |
6 | from django.core.validators import validate_email | 6 | from django.core.validators import validate_email |
7 | from django.core.exceptions import ValidationError | 7 | from django.core.exceptions import ValidationError |
8 | + | ||
9 | +from resubmit.widgets import ResubmitFileWidget | ||
10 | + | ||
8 | from .models import User | 11 | from .models import User |
9 | 12 | ||
10 | class Validation(forms.ModelForm): | 13 | class Validation(forms.ModelForm): |
@@ -19,7 +22,7 @@ class Validation(forms.ModelForm): | @@ -19,7 +22,7 @@ class Validation(forms.ModelForm): | ||
19 | return email | 22 | return email |
20 | except ValidationError: | 23 | except ValidationError: |
21 | self._errors['email'] = [_('You must insert an email address')] | 24 | self._errors['email'] = [_('You must insert an email address')] |
22 | - | 25 | + |
23 | return ValueError | 26 | return ValueError |
24 | 27 | ||
25 | def clean_image(self): | 28 | def clean_image(self): |
@@ -37,13 +40,13 @@ class Validation(forms.ModelForm): | @@ -37,13 +40,13 @@ class Validation(forms.ModelForm): | ||
37 | def clean_password2(self): | 40 | def clean_password2(self): |
38 | password = self.cleaned_data.get("new_password") | 41 | password = self.cleaned_data.get("new_password") |
39 | password2 = self.cleaned_data.get("password2") | 42 | password2 = self.cleaned_data.get("password2") |
40 | - | 43 | + |
41 | if password and password2 and password != password2: | 44 | if password and password2 and password != password2: |
42 | self._errors['password2'] = [_('The confirmation password is incorrect.')] | 45 | self._errors['password2'] = [_('The confirmation password is incorrect.')] |
43 | 46 | ||
44 | return ValueError | 47 | return ValueError |
45 | - | ||
46 | - return password2 | 48 | + |
49 | + return password2 | ||
47 | 50 | ||
48 | class RegisterUserForm(Validation): | 51 | class RegisterUserForm(Validation): |
49 | new_password = forms.CharField(label=_('Password'), widget = forms.PasswordInput(render_value = True, attrs = {'placeholder': _('Password') + ' *'})) | 52 | new_password = forms.CharField(label=_('Password'), widget = forms.PasswordInput(render_value = True, attrs = {'placeholder': _('Password') + ' *'})) |
@@ -53,11 +56,11 @@ class RegisterUserForm(Validation): | @@ -53,11 +56,11 @@ class RegisterUserForm(Validation): | ||
53 | 56 | ||
54 | def save(self, commit=True): | 57 | def save(self, commit=True): |
55 | super(RegisterUserForm, self).save(commit=False) | 58 | super(RegisterUserForm, self).save(commit=False) |
56 | - | 59 | + |
57 | self.instance.set_password(self.cleaned_data['new_password']) | 60 | self.instance.set_password(self.cleaned_data['new_password']) |
58 | 61 | ||
59 | self.instance.save() | 62 | self.instance.save() |
60 | - | 63 | + |
61 | return self.instance | 64 | return self.instance |
62 | 65 | ||
63 | class Meta: | 66 | class Meta: |
@@ -68,6 +71,7 @@ class RegisterUserForm(Validation): | @@ -68,6 +71,7 @@ class RegisterUserForm(Validation): | ||
68 | 'username': forms.TextInput(attrs = {'placeholder': _('Name') + ' *'}), | 71 | 'username': forms.TextInput(attrs = {'placeholder': _('Name') + ' *'}), |
69 | 'last_name': forms.TextInput(attrs = {'placeholder': _('Last Name') + ' *'}), | 72 | 'last_name': forms.TextInput(attrs = {'placeholder': _('Last Name') + ' *'}), |
70 | 'social_name': forms.TextInput(attrs = {'placeholder': _('Social Name')}), | 73 | 'social_name': forms.TextInput(attrs = {'placeholder': _('Social Name')}), |
74 | + 'image': ResubmitFileWidget(attrs={'accept':'image/*'}), | ||
71 | } | 75 | } |
72 | 76 | ||
73 | class ProfileForm(Validation): | 77 | class ProfileForm(Validation): |
@@ -75,9 +79,9 @@ class ProfileForm(Validation): | @@ -75,9 +79,9 @@ class ProfileForm(Validation): | ||
75 | 79 | ||
76 | def save(self, commit=True): | 80 | def save(self, commit=True): |
77 | super(ProfileForm, self).save(commit=False) | 81 | super(ProfileForm, self).save(commit=False) |
78 | - | 82 | + |
79 | self.instance.save() | 83 | self.instance.save() |
80 | - | 84 | + |
81 | return self.instance | 85 | return self.instance |
82 | 86 | ||
83 | class Meta: | 87 | class Meta: |
@@ -86,7 +90,8 @@ class ProfileForm(Validation): | @@ -86,7 +90,8 @@ class ProfileForm(Validation): | ||
86 | widgets = { | 90 | widgets = { |
87 | 'description': forms.Textarea, | 91 | 'description': forms.Textarea, |
88 | 'username': forms.TextInput(attrs = {'readonly': 'readonly'}), | 92 | 'username': forms.TextInput(attrs = {'readonly': 'readonly'}), |
89 | - 'last_name': forms.TextInput(attrs = {'readonly': 'readonly'}) | 93 | + 'last_name': forms.TextInput(attrs = {'readonly': 'readonly'}), |
94 | + 'image': ResubmitFileWidget(attrs={'accept':'image/*'}), | ||
90 | } | 95 | } |
91 | 96 | ||
92 | class UserForm(Validation): | 97 | class UserForm(Validation): |
@@ -98,19 +103,19 @@ class UserForm(Validation): | @@ -98,19 +103,19 @@ class UserForm(Validation): | ||
98 | super(UserForm, self).__init__(*args, **kwargs) | 103 | super(UserForm, self).__init__(*args, **kwargs) |
99 | 104 | ||
100 | self.is_edit = is_update | 105 | self.is_edit = is_update |
101 | - | 106 | + |
102 | new_password = forms.CharField(label = _('Password'), widget = forms.PasswordInput(render_value = True), required = False) | 107 | new_password = forms.CharField(label = _('Password'), widget = forms.PasswordInput(render_value = True), required = False) |
103 | password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput(render_value = True), required = False) | 108 | password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput(render_value = True), required = False) |
104 | 109 | ||
105 | 110 | ||
106 | def save(self, commit=True): | 111 | def save(self, commit=True): |
107 | super(UserForm, self).save(commit=False) | 112 | super(UserForm, self).save(commit=False) |
108 | - | 113 | + |
109 | if not self.is_edit or self.cleaned_data['new_password'] != '': | 114 | if not self.is_edit or self.cleaned_data['new_password'] != '': |
110 | self.instance.set_password(self.cleaned_data['new_password']) | 115 | self.instance.set_password(self.cleaned_data['new_password']) |
111 | 116 | ||
112 | self.instance.save() | 117 | self.instance.save() |
113 | - | 118 | + |
114 | return self.instance | 119 | return self.instance |
115 | 120 | ||
116 | class Meta: | 121 | class Meta: |
@@ -118,6 +123,7 @@ class UserForm(Validation): | @@ -118,6 +123,7 @@ class UserForm(Validation): | ||
118 | fields = ['email', 'username', 'last_name', 'social_name', 'description', 'show_email', 'image', 'is_staff', 'is_active',] | 123 | fields = ['email', 'username', 'last_name', 'social_name', 'description', 'show_email', 'image', 'is_staff', 'is_active',] |
119 | widgets = { | 124 | widgets = { |
120 | 'description': forms.Textarea, | 125 | 'description': forms.Textarea, |
126 | + 'image': ResubmitFileWidget(attrs={'accept':'image/*'}), | ||
121 | } | 127 | } |
122 | 128 | ||
123 | class ChangePassForm(Validation): | 129 | class ChangePassForm(Validation): |
@@ -143,13 +149,13 @@ class ChangePassForm(Validation): | @@ -143,13 +149,13 @@ class ChangePassForm(Validation): | ||
143 | 149 | ||
144 | def save(self, commit=True): | 150 | def save(self, commit=True): |
145 | super(ChangePassForm, self).save(commit=False) | 151 | super(ChangePassForm, self).save(commit=False) |
146 | - | 152 | + |
147 | self.instance.set_password(self.cleaned_data['new_password']) | 153 | self.instance.set_password(self.cleaned_data['new_password']) |
148 | 154 | ||
149 | update_session_auth_hash(self.request, self.instance) | 155 | update_session_auth_hash(self.request, self.instance) |
150 | 156 | ||
151 | self.instance.save() | 157 | self.instance.save() |
152 | - | 158 | + |
153 | return self.instance | 159 | return self.instance |
154 | 160 | ||
155 | class Meta: | 161 | class Meta: |
@@ -173,7 +179,7 @@ class PassResetRequest(forms.Form): | @@ -173,7 +179,7 @@ class PassResetRequest(forms.Form): | ||
173 | return email | 179 | return email |
174 | except ValidationError: | 180 | except ValidationError: |
175 | self._errors['email'] = [_('You must insert a valid email address')] | 181 | self._errors['email'] = [_('You must insert a valid email address')] |
176 | - | 182 | + |
177 | return ValueError | 183 | return ValueError |
178 | 184 | ||
179 | class SetPasswordForm(Validation): | 185 | class SetPasswordForm(Validation): |
@@ -184,4 +190,4 @@ class SetPasswordForm(Validation): | @@ -184,4 +190,4 @@ class SetPasswordForm(Validation): | ||
184 | 190 | ||
185 | class Meta: | 191 | class Meta: |
186 | model = User | 192 | model = User |
187 | - fields = [] | ||
188 | \ No newline at end of file | 193 | \ No newline at end of file |
194 | + fields = [] |