Commit f35e39d700a33e80ad7829e376d4e87c35d73ad7
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
4 changed files
with
23 additions
and
18 deletions
Show diff stats
subjects/templates/subjects/initial.html
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | </div> |
17 | 17 | |
18 | 18 | <div class="col-md-12 cards-content"> |
19 | - <h2 class=" my-subjects-title"><b><i>{% trans "Meus Assuntos" %}</i></b></h2> | |
19 | + <h2 class=" my-subjects-title"><b><i>{% trans "Meus Assuntos" %}</i></b></h2> | |
20 | 20 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> |
21 | 21 | {% for subject in subjects %} |
22 | 22 | {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} | ... | ... |
subjects/templates/subjects/subject_card.html
... | ... | @@ -57,7 +57,7 @@ |
57 | 57 | {% endif %} |
58 | 58 | </div> |
59 | 59 | </div> |
60 | -{% elif request.user in subject.professor.all or request.user in category.coordinators.all %} | |
60 | +{% elif request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} | |
61 | 61 | <div class="panel panel-info subject-panel-invisible"> |
62 | 62 | <div class="panel-heading panel-invisible"> |
63 | 63 | <div class="row"> | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +# File used to store useful subject functions # | |
2 | + | |
3 | +def has_student_profile(user, category): | |
4 | + for subject in category.subject_category.all(): | |
5 | + if user in subject.students.all(): | |
6 | + return True | |
7 | + | |
8 | + return False | |
9 | + | |
10 | +def has_professor_profile(user, category): | |
11 | + for subject in category.subject_category.all(): | |
12 | + if user in subject.professor.all(): | |
13 | + return True | |
14 | + | |
15 | + return False | |
0 | 16 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -25,6 +25,7 @@ from .models import Tag |
25 | 25 | import time |
26 | 26 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
27 | 27 | from .forms import CreateSubjectForm |
28 | +from .utils import has_student_profile, has_professor_profile | |
28 | 29 | from users.models import User |
29 | 30 | |
30 | 31 | |
... | ... | @@ -38,14 +39,12 @@ class HomeView(LoginRequiredMixin, ListView): |
38 | 39 | |
39 | 40 | def get_queryset(self): |
40 | 41 | if self.request.user.is_staff: |
41 | - subjects = Subject.objects.all() | |
42 | + subjects = Subject.objects.all().order_by("name") | |
42 | 43 | else: |
43 | - subjects = Subject.objects.all() | |
44 | + subjects = Subject.objects.all().order_by("name") | |
44 | 45 | subjects = [subject for subject in subjects if self.request.user in subject.students.all() or self.request.user in subject.professor.all() or self.request.user in subject.category.coordinators.all()] |
45 | 46 | |
46 | - | |
47 | - paginator = Paginator(subjects, 10) | |
48 | - | |
47 | + print(subjects) | |
49 | 48 | |
50 | 49 | return subjects |
51 | 50 | |
... | ... | @@ -75,10 +74,8 @@ class IndexView(LoginRequiredMixin, ListView): |
75 | 74 | if not self.kwargs.get('option'): |
76 | 75 | categories = Category.objects.all() |
77 | 76 | |
78 | - for category in categories: | |
79 | - category.subjects = Subject.objects.filter(category= category) | |
80 | - | |
81 | - categories = [category for category in categories if category.subjects.count() > 0 or self.request.user in category.coordinators.all()] | |
77 | + categories = [category for category in categories if self.request.user in category.coordinators.all() \ | |
78 | + or has_professor_profile(self.request.user, category) or has_student_profile(self.request.user, category)] | |
82 | 79 | #So I remove all categories that doesn't have the possibility for the user to be on |
83 | 80 | |
84 | 81 | return categories |
... | ... | @@ -166,11 +163,9 @@ class SubjectCreateView(CreateView): |
166 | 163 | return super(SubjectCreateView, self).form_valid(form) |
167 | 164 | |
168 | 165 | def get_success_url(self): |
169 | - | |
170 | 166 | if not self.object.category.visible: |
171 | 167 | self.object.visible = False |
172 | 168 | self.object.save() |
173 | - | |
174 | 169 | |
175 | 170 | messages.success(self.request, _('Subject "%s" was registered on "%s" successfully!')%(self.object.name, self.object.category.name )) |
176 | 171 | return reverse_lazy('subjects:index') |
... | ... | @@ -192,17 +187,13 @@ class SubjectUpdateView(LogMixin, UpdateView): |
192 | 187 | return context |
193 | 188 | |
194 | 189 | def get_success_url(self): |
195 | - | |
196 | 190 | if not self.object.category.visible: |
197 | 191 | self.object.visible = False |
198 | 192 | self.object.save() |
199 | - | |
200 | 193 | |
201 | 194 | messages.success(self.request, _('Subject "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) |
202 | 195 | return reverse_lazy('subjects:index') |
203 | 196 | |
204 | - | |
205 | - | |
206 | 197 | class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
207 | 198 | |
208 | 199 | login_url = reverse_lazy("users:login") |
... | ... | @@ -228,7 +219,6 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
228 | 219 | def get_success_url(self): |
229 | 220 | |
230 | 221 | messages.success(self.request, _('Subject removed successfully!')) |
231 | - | |
232 | 222 | |
233 | 223 | return reverse_lazy('subjects:index') |
234 | 224 | ... | ... |