Commit 95c79c3fd35d17f2fa249cd19ce1823b3063ca08
1 parent
ed2cd2be
Exists in
master
and in
3 other branches
Updating dependencies check in account deletion
Showing
2 changed files
with
27 additions
and
1 deletions
Show diff stats
... | ... | @@ -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 | 26 | \ No newline at end of file | ... | ... |
users/views.py
... | ... | @@ -10,6 +10,7 @@ from django.db.models import Q |
10 | 10 | from braces import views as braces_mixins |
11 | 11 | |
12 | 12 | from .models import User |
13 | +from .utils import has_dependencies | |
13 | 14 | from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm |
14 | 15 | |
15 | 16 | #RECOVER PASS IMPORTS |
... | ... | @@ -168,7 +169,7 @@ class DeleteView(braces_mixins.LoginRequiredMixin, generic.DeleteView): |
168 | 169 | success_msg = _('User removed successfully!') |
169 | 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 | 173 | messages.error(self.request, error_msg) |
173 | 174 | |
174 | 175 | return redirect(error_url) | ... | ... |