-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContent.py
executable file
·34 lines (26 loc) · 1.02 KB
/
Content.py
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
# Returns True if the contents groups and the users groups overlap
def ContentIsAllowed(content_groups, user_groups):
# Always return True if the user is admin
if "admin" in user_groups:
return True
# Always return True if the content is for everyone
if "everyone" in content_groups:
return True
# Check if the contets groups and the users groups overlap
if content_groups.intersection(user_groups):
return True
else:
return False
# Returns the weight property of a given content element
def ReturnWeight(element):
return element[4]
# Sorts content by decreasing weight
def SortContent(content):
return sorted(content, key = ReturnWeight, reverse = True)
# Returns contents to be displayed to the user, sorted by decreasing weight
def Content(contents, user_groups):
allowed_content = list()
for content in contents:
if ContentIsAllowed(content[2], user_groups):
allowed_content.append(content)
return SortContent(allowed_content)