1
0
forked from ScoDoc/ScoDoc

Modified list_dept

This commit is contained in:
IDK 2021-05-01 14:50:34 +02:00
parent d2aac186eb
commit db781d71e3
3 changed files with 28 additions and 12 deletions

View File

@ -273,10 +273,26 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
security.declareProtected("View", "list_depts")
def list_depts(self, REQUEST=None):
"""List departments folders
(returns a list of Zope folders containing a ZScolar instance)
def list_depts(self, viewable=True, format=None, REQUEST=None):
"""List departments
If viewable, list only depts viewable the current user.
"""
authuser = REQUEST.AUTHENTICATED_USER
viewable = int(viewable)
return scu.sendResult(
REQUEST,
[
d.id
for d in self._list_depts()
if (not viewable) or authuser.has_permission(ScoView, d.Scolarite)
],
name="depts",
format=format,
)
def _list_depts(self, REQUEST=None): # not published
# List departments folders
# (returns a list of Zope folders containing a ZScolar instance)
folders = self.objectValues("Folder")
# select folders with Scolarite object:
r = []
@ -327,7 +343,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
if e:
return e
if not force and DeptId not in [x.id for x in self.list_depts()]:
if not force and DeptId not in [x.id for x in self._list_depts()]:
raise ValueError("nom de departement invalide")
self.manage_delObjects(ids=[DeptId])
@ -391,7 +407,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
def index_html(self, REQUEST=None, message=None):
"""Top level page for ScoDoc"""
authuser = REQUEST.AUTHENTICATED_USER
deptList = self.list_depts()
deptList = self._list_depts()
self._fix_users_folder() # fix our exUserFolder
isAdmin = not self._check_admin_perm(REQUEST)
try:
@ -406,7 +422,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
# Si l'URL indique que l'on est dans un folder, affiche page login du departement
try:
deptfoldername = REQUEST.URL0.split("ScoDoc")[1].split("/")[1]
if deptfoldername in [x.id for x in self.list_depts()]:
if deptfoldername in [x.id for x in self._list_depts()]:
return self.index_dept(deptfoldername=deptfoldername, REQUEST=REQUEST)
except:
pass
@ -453,7 +469,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp
dest_folder = "/Scolarite"
else:
dest_folder = ""
for deptFolder in self.list_depts():
for deptFolder in self._list_depts():
if authuser.has_permission(ScoView, deptFolder.Scolarite):
link_cls = "link_accessible"
else:
@ -868,7 +884,7 @@ subversion: %(svn_version)s
% self.absolute_url(),
]
deptList = [x.id for x in self.list_depts()] # definis dans Zope
deptList = [x.id for x in self._list_depts()] # definis dans Zope
deptIds = set(self._list_depts_ids()) # definis sur le filesystem
existingDepts = set(deptList)
addableDepts = deptIds - existingDepts
@ -897,7 +913,7 @@ subversion: %(svn_version)s
<select name="DeptId">
"""
)
for deptFolder in self.list_depts():
for deptFolder in self._list_depts():
H.append(
'<option value="%s">%s</option>' % (deptFolder.id, deptFolder.id)
)
@ -932,7 +948,7 @@ subversion: %(svn_version)s
"""Returns the dept id (eg "GEII") of an etud (identified by etudid, INE or NIP in REQUEST).
Warning: This function is inefficient and its result should be cached.
"""
depts = self.list_depts()
depts = self._list_depts()
depts_etud = [] # liste des depts où l'etud est defini
for dept in depts:
etuds = dept.Scolarite.getEtudInfo(REQUEST=REQUEST)

View File

@ -276,7 +276,7 @@ def search_etud_in_accessible_depts(context, expnom=None, code_nip=None, REQUEST
"""
result = []
accessible_depts = []
deptList = context.list_depts() # definis dans Zope
deptList = context._list_depts() # definis dans Zope
for dept in deptList:
# log('%s searching %s' % (str(REQUEST.AUTHENTICATED_USER),dept))
if can_view_dept(dept, REQUEST):

View File

@ -495,7 +495,7 @@ def sem_est_courant(context, sem):
def scodoc_get_all_unlocked_sems(context):
"""Liste de tous les semestres non verrouillés de tous les départements"""
depts = context.list_depts()
depts = context._list_depts()
semdepts = []
for dept in depts:
semdepts += [