Commit 59782ae94461bc59aeb9c7138f231684536c4a16
Exists in
master
and in
5 other branches
Merge branch 'master' of https://github.com/amadeusproject/amadeuslms
Showing
12 changed files
with
143 additions
and
34 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -58,6 +58,9 @@ MIDDLEWARE_CLASSES = [ |
58 | 58 | 'django.contrib.messages.middleware.MessageMiddleware', |
59 | 59 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
60 | 60 | 'django.middleware.locale.LocaleMiddleware', |
61 | + | |
62 | + #libs-middleware | |
63 | + | |
61 | 64 | ] |
62 | 65 | |
63 | 66 | ROOT_URLCONF = 'amadeus.urls' | ... | ... |
app/templates/home_student.html
... | ... | @@ -4,12 +4,10 @@ |
4 | 4 | |
5 | 5 | {% block breadcrumbs %} |
6 | 6 | <div class="row"> |
7 | - <div class="col-md-12"> | |
8 | - <ul class="breadcrumb"> | |
9 | - <li><a href="{% url 'core:home' %}">{% trans 'Home' %} {{ logged }}</a></li> | |
10 | - </ul> | |
11 | - </div> | |
12 | - </div> | |
7 | + {% for breadcrumb in breadcrumbs %} | |
8 | + <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a> | |
9 | + {% endfor %} | |
10 | + </div> | |
13 | 11 | {% endblock %} |
14 | 12 | |
15 | 13 | {% block sidebar %} |
... | ... | @@ -29,6 +27,16 @@ |
29 | 27 | |
30 | 28 | {% block content %} |
31 | 29 | <h3>{% trans 'Notifications' %}</h3> |
30 | + {% if messages %} | |
31 | + {% for message in messages %} | |
32 | + <div class="alert alert-success alert-dismissible" role="alert"> | |
33 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
34 | + <span aria-hidden="true">×</span> | |
35 | + </button> | |
36 | + <p>{{ message }}</p> | |
37 | + </div> | |
38 | + {% endfor %} | |
39 | + {% endif %} | |
32 | 40 | <div class="panel panel-default"> |
33 | 41 | <div class="panel-body"> |
34 | 42 | His course has notified a new activity! | ... | ... |
core/forms.py
1 | 1 | from django import forms |
2 | - | |
2 | +from django.utils.translation import ugettext_lazy as _ | |
3 | 3 | from users.models import User |
4 | 4 | |
5 | 5 | class RegisterUserForm(forms.ModelForm): |
... | ... | @@ -12,7 +12,7 @@ class RegisterUserForm(forms.ModelForm): |
12 | 12 | def clean_email(self): |
13 | 13 | email = self.cleaned_data['email'] |
14 | 14 | if User.objects.filter(email = email).exists(): |
15 | - raise forms.ValidationError('Ja existe um usuario cadastrado com este E-mail') | |
15 | + raise forms.ValidationError(_('There is already a registered User with this e-mail')) | |
16 | 16 | return email |
17 | 17 | |
18 | 18 | def clean_password(self): |
... | ... | @@ -20,13 +20,13 @@ class RegisterUserForm(forms.ModelForm): |
20 | 20 | |
21 | 21 | # At least MIN_LENGTH long |
22 | 22 | if len(password) < self.MIN_LENGTH: |
23 | - raise forms.ValidationError("A senha deve conter no minimo %d caracteres." % self.MIN_LENGTH) | |
23 | + raise forms.ValidationError(_("The password must contain at least % d characters." % self.MIN_LENGTH)) | |
24 | 24 | |
25 | 25 | # At least one letter and one non-letter |
26 | 26 | first_isalpha = password[0].isalpha() |
27 | 27 | if all(c.isalpha() == first_isalpha for c in password): |
28 | - raise forms.ValidationError("A senha deve conter pelo menos uma letra e pelo menos um digito ou "\ | |
29 | - "um caractere de pontuacao.") | |
28 | + raise forms.ValidationError(_('The password must contain at least one letter and at least one digit or '\ | |
29 | + "a punctuation character.")) | |
30 | 30 | |
31 | 31 | return password |
32 | 32 | |
... | ... | @@ -35,7 +35,7 @@ class RegisterUserForm(forms.ModelForm): |
35 | 35 | password2 = self.cleaned_data.get("password2") |
36 | 36 | |
37 | 37 | if password and password2 and password != password2: |
38 | - raise forms.ValidationError('A confirmacao da senha esta incorreta') | |
38 | + raise forms.ValidationError(_('The confirmation password is incorrect.')) | |
39 | 39 | return password2 |
40 | 40 | |
41 | 41 | def save(self, commit=True): | ... | ... |
core/static/css/base/amadeus.css
core/templates/index.html
... | ... | @@ -11,11 +11,16 @@ |
11 | 11 | |
12 | 12 | {% block content %} |
13 | 13 | <div class="row logo-row"> |
14 | - <div class="col-md-offset-4 col-md-4 col-xs-4 col-xs-offset-4 logoLogin"> | |
15 | - <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus"> | |
16 | - </div> | |
14 | + <div class="col-lg-offset-2 col-lg-9"> | |
15 | + <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus" id="logo"> | |
17 | 16 | </div> |
18 | 17 | |
18 | + <div class="row"> | |
19 | + {% for breadcrumb in breadcrumbs %} | |
20 | + <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a> | |
21 | + {% endfor %} | |
22 | + </div> | |
23 | + | |
19 | 24 | <div class="row "> |
20 | 25 | <div class="col-md-8 col-md-offset-2 col-sm-6 col-sm-offset-3"> |
21 | 26 | <div class="card"> | ... | ... |
core/templates/register_user.html
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | </div> |
15 | 15 | {% endif %} |
16 | 16 | <div class="row logo-row"> |
17 | - <div class="col-lg-offset-4 col-md-4"> | |
17 | + <div class="col-lg-offset-2 col-lg-9"> | |
18 | 18 | <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus" id="logo"> |
19 | 19 | </div> |
20 | 20 | </div> |
... | ... | @@ -28,11 +28,26 @@ |
28 | 28 | {% csrf_token %} |
29 | 29 | <legend>{% trans 'User Register' %}</legend> |
30 | 30 | {% for field in form %} |
31 | - <div class="form-group is-empy{% if form.has_error %} has-error {% endif %}"> | |
31 | + <div class="form-group is-empy{% if form.has_error %} has-error {% endif %} is-fileinput"> | |
32 | 32 | <label for="{{ field.auto_id }}" class="col-md-4 control-label">{{ field.label }}</label> |
33 | 33 | <div class="col-md-8"> |
34 | - {% render_field field class='form-control input-sm' %} | |
35 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
34 | + {% if field.auto_id == 'id_birth_date' %} | |
35 | + {% render_field field class='form-control input-sm' type='date' %} | |
36 | + <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
37 | + {% elif field.auto_id == 'id_image' %} | |
38 | + {% render_field field class='form-control input-sm' %} | |
39 | + <div class="input-group"> | |
40 | + <input type="text" readonly="" class="form-control" placeholder="Choose your photo..."> | |
41 | + <span class="input-group-btn input-group-sm"> | |
42 | + <button type="button" class="btn btn-fab btn-fab-mini"> | |
43 | + <i class="material-icons">attach_file</i> | |
44 | + </button> | |
45 | + </span> | |
46 | + </div> | |
47 | + {% else %} | |
48 | + {% render_field field class='form-control input-sm' %} | |
49 | + <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
50 | + {% endif %} | |
36 | 51 | </div> |
37 | 52 | |
38 | 53 | {% if field.errors %} |
... | ... | @@ -49,9 +64,12 @@ |
49 | 64 | {% endif %} |
50 | 65 | </div> |
51 | 66 | {% endfor %} |
52 | - <div class="col-md-offset-4"> | |
67 | + <div class="col-md-offset-4 col-md-2 col-sm-2 col-xs-2"> | |
53 | 68 | <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> |
54 | 69 | </div> |
70 | + <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2"> | |
71 | + <a href="{% url 'core:home' %}" class="btn btn-sm btn-success" >{% trans 'Login' %}</a> | |
72 | + </div> | |
55 | 73 | |
56 | 74 | </form> |
57 | 75 | </div> | ... | ... |
core/tests.py
... | ... | @@ -75,7 +75,7 @@ class RegisterUserTestCase(TestCase): |
75 | 75 | 'gender': 'F', |
76 | 76 | } |
77 | 77 | response = self.client.post(self.url, data) |
78 | - self.assertFormError(response, 'form', 'password2', 'A confirmacão da senha está incorreta') | |
78 | + self.assertFormError(response, 'form', 'password2', 'The confirmation password is incorrect.') | |
79 | 79 | |
80 | 80 | data = { |
81 | 81 | 'username': 'testeamadeus', |
... | ... | @@ -87,6 +87,7 @@ class RegisterUserTestCase(TestCase): |
87 | 87 | 'state': 'PE', |
88 | 88 | 'gender': 'F', |
89 | 89 | } |
90 | + | |
90 | 91 | response = self.client.post(self.url, data) |
91 | 92 | self.assertFormError(response, 'form', 'email', 'Insira um endereço de email válido.') |
92 | 93 | |
... | ... | @@ -141,9 +142,25 @@ class UpdateUserTestCase(TestCase): |
141 | 142 | def setUp(self): |
142 | 143 | self.client = Client() |
143 | 144 | |
144 | - self.url = reverse('users:update_user') | |
145 | + self.user = User.objects.create_user( | |
146 | + username = 'test', | |
147 | + email = 'testing@amadeus.com', | |
148 | + is_staff = False, | |
149 | + is_active = True, | |
150 | + password = 'testing1' | |
151 | + ) | |
152 | + | |
153 | + assign_role(self.user, 'student') | |
154 | + | |
155 | + self.url = reverse('users:update_profile') | |
156 | + | |
157 | + def test_update_ok(self): | |
158 | + #LOGGING USER TO TEST | |
159 | + data = {'username': 'test', 'password': 'testing1'} | |
160 | + response = self.client.post(reverse('core:home'), data) | |
161 | + self.assertRedirects(response, reverse('app:index')) | |
162 | + | |
145 | 163 | |
146 | - def test_get_post(self): | |
147 | 164 | data={ |
148 | 165 | 'username': 'testeamadeus', |
149 | 166 | 'email': 'teste@amadeus.com', |
... | ... | @@ -153,7 +170,52 @@ class UpdateUserTestCase(TestCase): |
153 | 170 | 'gender': 'F', |
154 | 171 | } |
155 | 172 | # self.assertRedirects(response1, reverse('app:index')) |
173 | + response = self.client.get(self.url) | |
174 | + self.assertEqual(response.status_code, 200) | |
156 | 175 | response = self.client.post(self.url, data) |
157 | 176 | self.assertEqual(response.status_code, 302) |
177 | + | |
178 | + def test_update_error(self): | |
179 | + | |
180 | + #LOGING USER TO TEST | |
181 | + data = {'username': 'test', 'password': 'testing1'} | |
182 | + response = self.client.post(reverse('core:home'), data) | |
183 | + self.assertRedirects(response, reverse('app:index')) | |
184 | + | |
158 | 185 | response = self.client.get(self.url) |
159 | - self.assertEqual(response.status_code, 302) | |
186 | + self.assertEquals(response.status_code, 200) | |
187 | + | |
188 | + data = { | |
189 | + 'username': '', | |
190 | + 'email': 'teste@amadeus.com', | |
191 | + 'name': 'Teste Amadeus', | |
192 | + 'city': 'Praia', | |
193 | + 'state': 'PE', | |
194 | + 'gender': 'F', | |
195 | + } | |
196 | + response = self.client.post(self.url, data) | |
197 | + self.assertFormError(response, 'form', 'username', 'Este campo é obrigatório.') | |
198 | + | |
199 | + | |
200 | +class DeleteUserTestCase(TestCase): | |
201 | + def setUp(self): | |
202 | + self.client = Client() | |
203 | + | |
204 | + self.user = User.objects.create_user( | |
205 | + username = 'test', | |
206 | + email = 'testing@amadeus.com', | |
207 | + is_staff = True, | |
208 | + is_active = True, | |
209 | + password = 'testing' | |
210 | + ) | |
211 | + | |
212 | + assign_role(self.user, 'student') | |
213 | + self.url = reverse('core:home') | |
214 | + | |
215 | + def tearDown(test): | |
216 | + User.objects.get(email='testing@amadeus.com').delete() | |
217 | + | |
218 | + def test_delete_ok(self): | |
219 | + pass | |
220 | + | |
221 | + | ... | ... |
requirements.txt
1 | +click==6.6 | |
1 | 2 | Django==1.10 |
2 | -django-autoslug==1.9.3 | |
3 | 3 | django-discover-runner==1.0 |
4 | 4 | django-role-permissions==1.2.1 |
5 | 5 | django-widget-tweaks==1.4.1 |
6 | 6 | djangorestframework==3.4.6 |
7 | +itsdangerous==0.24 | |
8 | +Jinja2==2.8 | |
9 | +MarkupSafe==0.23 | |
7 | 10 | Pillow==3.3.1 |
8 | 11 | psycopg2==2.6.2 |
9 | 12 | six==1.10.0 |
10 | 13 | slugify==0.0.1 |
14 | +Werkzeug==0.11.11 | |
15 | +wheel==0.24.0 | ... | ... |
users/templates/users/edit_profile.html
... | ... | @@ -22,12 +22,6 @@ |
22 | 22 | {% endblock %} |
23 | 23 | |
24 | 24 | {% block content %} |
25 | - <div class="alert alert-info alert-dismissible" role="alert"> | |
26 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
27 | - <span aria-hidden="true">×</span> | |
28 | - </button> | |
29 | - <p>{% trans 'All fields are required' %}</p> | |
30 | - </div> | |
31 | 25 | {% if messages %} |
32 | 26 | {% for message in messages %} |
33 | 27 | <div class="alert alert-success alert-dismissible" role="alert"> | ... | ... |
users/templates/users/profile.html
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | <a href="{% url 'users:profile' %}" class="list-group-item active"> |
16 | 16 | {% trans 'Profile' %} |
17 | 17 | </a> |
18 | - <a href="{% url 'users:edit_profile' user.id %}" class="list-group-item"> | |
18 | + <a href="{% url 'users:update_profile' %}" class="list-group-item"> | |
19 | 19 | {% trans 'Edit Profile' %} |
20 | 20 | </a> |
21 | 21 | </div> | ... | ... |
users/urls.py
... | ... | @@ -10,5 +10,6 @@ urlpatterns = [ |
10 | 10 | url(r'^profile/$', views.Profile.as_view(), name='profile'), |
11 | 11 | url(r'^profile/editar/(?P<username>[\w_-]+)/$', views.EditProfile.as_view(), name='edit_profile'), |
12 | 12 | # |
13 | - url(r'^profile/update/$', views.UpdateUser.as_view(), name='update_user'), | |
13 | + url(r'^profile/update/$', views.UpdateUser.as_view(), name='update_profile'), | |
14 | + url(r'^profile/delete/$', views.DeleteUser.as_view(), name='delete_profile'), | |
14 | 15 | ] | ... | ... |
users/views.py
... | ... | @@ -133,10 +133,11 @@ class EditProfile(LoginRequiredMixin, generic.UpdateView): |
133 | 133 | |
134 | 134 | return super(EditProfile, self).form_valid(form) |
135 | 135 | |
136 | + | |
136 | 137 | class UpdateUser(LoginRequiredMixin, generic.edit.UpdateView): |
137 | 138 | allowed_roles = ['student'] |
138 | 139 | login_url = reverse_lazy("core:home") |
139 | - # template_name = 'users/edit_profile.html' | |
140 | + template_name = 'users/edit_profile.html' | |
140 | 141 | form_class = UpdateUserForm |
141 | 142 | success_url = reverse_lazy('app:index') |
142 | 143 | |
... | ... | @@ -149,3 +150,14 @@ class UpdateUser(LoginRequiredMixin, generic.edit.UpdateView): |
149 | 150 | messages.success(self.request, _('Profile edited successfully!')) |
150 | 151 | |
151 | 152 | return super(UpdateUser, self).form_valid(form) |
153 | + | |
154 | +class DeleteUser(LoginRequiredMixin, generic.edit.DeleteView): | |
155 | + allowed_roles = ['student'] | |
156 | + login_url = reverse_lazy("core:home") | |
157 | + model = User | |
158 | + success_url = reverse_lazy('core:index') | |
159 | + success_message = "Deleted Successfully" | |
160 | + | |
161 | + def get_queryset(self): | |
162 | + user = get_object_or_404(User, username = self.request.user.username) | |
163 | + return user | ... | ... |