utils.py
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Copyright 2016, 2017 UFPE - Universidade Federal de Pernambuco
Este arquivo é parte do programa Amadeus Sistema de Gestão de Aprendizagem, ou simplesmente Amadeus LMS
O Amadeus LMS é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença.
Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENSE", junto com este programa, se não, escreva para a Fundação do Software Livre (FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
"""
# File used to store useful subject functions #
from categories.models import Category
from .models import Subject
from django.db.models import Q
def has_student_profile(user, category):
for subject in category.subject_category.all():
if subject.students.filter(id = user.id).exists() and subject.visible:
return True
return False
def has_professor_profile(user, category):
for subject in category.subject_category.all():
if subject.professor.filter(id = user.id).exists() and subject.visible:
return True
return False
def get_category_page(categories, slug, per_page):
total = 1
for category in categories:
if category.slug == slug:
return total / per_page + 1
total += 1
return 1
def count_subjects( user, all_subs = True):
total = 0
pk = user.pk
"""for category in categories:
if not all_subs:
for subject in category.subject_category.all():
if user in subject.students.all() or user in subject.professor.all() or user in subject.category.coordinators.all():
total += 1
else:
total += category.subject_category.count()"""
if all_subs:
#total += Category.objects.filter(Q(coordinators__pk = pk) | Q(visible=True) ).distinct().count()
total = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk) | Q(visible = True)).distinct().count()
else:
total = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk)).distinct().count()
return total