Commit cd7a88fafdcb7f3546b29bca19142a4dfa03b84e
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
6 changed files
with
65 additions
and
14 deletions
Show diff stats
users/models.py
@@ -62,15 +62,6 @@ class User(AbstractBaseUser, PermissionsMixin): | @@ -62,15 +62,6 @@ class User(AbstractBaseUser, PermissionsMixin): | ||
62 | 62 | ||
63 | return _('Is not an admin') | 63 | return _('Is not an admin') |
64 | 64 | ||
65 | - def is_coordinator(self): | ||
66 | - return _('Is not a coordinator') | ||
67 | - | ||
68 | - def is_professor(self): | ||
69 | - return _('Is not a professor') | ||
70 | - | ||
71 | - def is_student(self): | ||
72 | - return _('Is not a student') | ||
73 | - | ||
74 | def has_dependencies(self): | 65 | def has_dependencies(self): |
75 | if self.is_staff: | 66 | if self.is_staff: |
76 | return True | 67 | return True |
users/templates/users/profile.html
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | {% load static i18n %} | 3 | {% load static i18n %} |
4 | {% load widget_tweaks %} | 4 | {% load widget_tweaks %} |
5 | -{% load django_bootstrap_breadcrumbs permission_tags%} | 5 | +{% load django_bootstrap_breadcrumbs profile_verifies %} |
6 | 6 | ||
7 | {% block breadcrumbs %} | 7 | {% block breadcrumbs %} |
8 | {{ block.super }} | 8 | {{ block.super }} |
@@ -42,15 +42,15 @@ | @@ -42,15 +42,15 @@ | ||
42 | </div> | 42 | </div> |
43 | <div class="form-group"> | 43 | <div class="form-group"> |
44 | <label class="control-form">{% trans 'Coordinator in' %}:</label> | 44 | <label class="control-form">{% trans 'Coordinator in' %}:</label> |
45 | - <input type="text" readonly="readonly" class="form-control" value="{{ user.is_coordinator }}" /> | 45 | + <input type="text" readonly="readonly" class="form-control" value="{{ user|is_coordinator }}" /> |
46 | </div> | 46 | </div> |
47 | <div class="form-group"> | 47 | <div class="form-group"> |
48 | <label class="control-form">{% trans 'Professor in' %}:</label> | 48 | <label class="control-form">{% trans 'Professor in' %}:</label> |
49 | - <input type="text" readonly="readonly" class="form-control" value="{{ user.is_professor }}" /> | 49 | + <input type="text" readonly="readonly" class="form-control" value="{{ user|is_professor }}" /> |
50 | </div> | 50 | </div> |
51 | <div class="form-group"> | 51 | <div class="form-group"> |
52 | <label class="control-form">{% trans 'Student in' %}:</label> | 52 | <label class="control-form">{% trans 'Student in' %}:</label> |
53 | - <input type="text" readonly="readonly" class="form-control" value="{{ user.is_student }}" /> | 53 | + <input type="text" readonly="readonly" class="form-control" value="{{ user|is_student }}" /> |
54 | </div> | 54 | </div> |
55 | </div> | 55 | </div> |
56 | </div> | 56 | </div> |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +from django import template | ||
2 | +from django.utils.translation import ugettext_lazy as _ | ||
3 | + | ||
4 | +from categories.models import Category | ||
5 | +from subjects.models import Subject | ||
6 | + | ||
7 | +register = template.Library() | ||
8 | + | ||
9 | +@register.filter(name = 'is_coordinator') | ||
10 | +def is_coordinator(user): | ||
11 | + cats = Category.objects.filter(coordinators = user) | ||
12 | + | ||
13 | + if len(cats) > 0: | ||
14 | + return ", ".join(cats.values_list('name', flat = True)) | ||
15 | + | ||
16 | + return _('Is not a coordinator') | ||
17 | + | ||
18 | +@register.filter(name = 'is_professor') | ||
19 | +def is_professor(user): | ||
20 | + subs = Subject.objects.filter(professor = user) | ||
21 | + | ||
22 | + if len(subs) > 0: | ||
23 | + return ", ".join(subs.values_list('name', flat = True)) | ||
24 | + | ||
25 | + return _('Is not a professor') | ||
26 | + | ||
27 | +@register.filter(name = 'is_student') | ||
28 | +def is_student(user): | ||
29 | + subs = Subject.objects.filter(students = user) | ||
30 | + | ||
31 | + if len(subs) > 0: | ||
32 | + return ", ".join(subs.values_list('name', flat = True)) | ||
33 | + | ||
34 | + return _('Is not a student') |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +# File used to store useful user functions # | ||
2 | + | ||
3 | +from categories.models import Category | ||
4 | +from subjects.models import Subject | ||
5 | + | ||
6 | +def has_dependencies(user): | ||
7 | + if user.is_staff: #Check admin function | ||
8 | + return True | ||
9 | + | ||
10 | + cats = Category.objects.filter(coordinators = user) | ||
11 | + | ||
12 | + if len(cats) > 0: #Check coordinator function | ||
13 | + return True | ||
14 | + | ||
15 | + subs = Subject.objects.filter(professor = user) | ||
16 | + | ||
17 | + if len(subs) > 0: #Check professor function | ||
18 | + return True | ||
19 | + | ||
20 | + subs = Subject.objects.filter(students = user) | ||
21 | + | ||
22 | + if len(subs) > 0: #Check student function | ||
23 | + return True | ||
24 | + | ||
25 | + return False | ||
0 | \ No newline at end of file | 26 | \ No newline at end of file |
users/views.py
@@ -10,6 +10,7 @@ from django.db.models import Q | @@ -10,6 +10,7 @@ from django.db.models import Q | ||
10 | from braces import views as braces_mixins | 10 | from braces import views as braces_mixins |
11 | 11 | ||
12 | from .models import User | 12 | from .models import User |
13 | +from .utils import has_dependencies | ||
13 | from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm | 14 | from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm |
14 | 15 | ||
15 | #RECOVER PASS IMPORTS | 16 | #RECOVER PASS IMPORTS |
@@ -168,7 +169,7 @@ class DeleteView(braces_mixins.LoginRequiredMixin, generic.DeleteView): | @@ -168,7 +169,7 @@ class DeleteView(braces_mixins.LoginRequiredMixin, generic.DeleteView): | ||
168 | success_msg = _('User removed successfully!') | 169 | success_msg = _('User removed successfully!') |
169 | error_msg = _('Could not remove the account. The user is attach to one or more functions (administrator, coordinator, professor ou student) in the system.') | 170 | error_msg = _('Could not remove the account. The user is attach to one or more functions (administrator, coordinator, professor ou student) in the system.') |
170 | 171 | ||
171 | - if user.has_dependencies(): | 172 | + if has_dependencies(user): |
172 | messages.error(self.request, error_msg) | 173 | messages.error(self.request, error_msg) |
173 | 174 | ||
174 | return redirect(error_url) | 175 | return redirect(error_url) |