From d2aac186eb175a2059c5862675d14a4002a2cb69 Mon Sep 17 00:00:00 2001 From: IDK Date: Fri, 30 Apr 2021 11:04:02 +0200 Subject: [PATCH 1/6] do_formsemestre_inscription_listinscrits: json, xml, ... --- ZNotes.py | 29 ++++++++++++++--------------- sco_utils.py | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ZNotes.py b/ZNotes.py index f78684d97..cc35d2baf 100644 --- a/ZNotes.py +++ b/ZNotes.py @@ -191,15 +191,13 @@ class ZNotes(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Impl # Affecte aussi cache inscriptions self.get_formsemestre_inscription_cache().inval_cache( key=formsemestre_id - ) # > + ) else: self._getNotesCache().inval_cache( self, formsemestre_id=formsemestre_id, pdfonly=pdfonly - ) # > + ) # Affecte aussi cache inscriptions - self.get_formsemestre_inscription_cache().inval_cache( - key=formsemestre_id - ) # > + self.get_formsemestre_inscription_cache().inval_cache(key=formsemestre_id) security.declareProtected(ScoView, "clearcache") @@ -1807,18 +1805,19 @@ class ZNotes(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Impl security.declareProtected(ScoView, "do_formsemestre_inscription_listinscrits") - def do_formsemestre_inscription_listinscrits(self, formsemestre_id): + def do_formsemestre_inscription_listinscrits( + self, formsemestre_id, format=None, REQUEST=None + ): """Liste les inscrits (état I) à ce semestre et cache le résultat""" cache = self.get_formsemestre_inscription_cache() r = cache.get(formsemestre_id) - if r != None: - return r - # retreive list - r = self.do_formsemestre_inscription_list( - args={"formsemestre_id": formsemestre_id, "etat": "I"} - ) - cache.set(formsemestre_id, r) - return r + if r is None: + # retreive list + r = self.do_formsemestre_inscription_list( + args={"formsemestre_id": formsemestre_id, "etat": "I"} + ) + cache.set(formsemestre_id, r) + return scu.sendResult(REQUEST, r, format=format, name="inscrits") security.declareProtected(ScoImplement, "do_formsemestre_inscription_edit") @@ -1831,7 +1830,7 @@ class ZNotes(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Impl ) # > modif inscription semestre (demission ?) # Cache inscriptions semestres - def get_formsemestre_inscription_cache(self): + def get_formsemestre_inscription_cache(self, format=None): u = self.GetDBConnexionString() if CACHE_formsemestre_inscription.has_key(u): return CACHE_formsemestre_inscription[u] diff --git a/sco_utils.py b/sco_utils.py index 6a30c3cb2..a947f46e9 100644 --- a/sco_utils.py +++ b/sco_utils.py @@ -582,7 +582,7 @@ def sendXML(REQUEST, data, tagname=None, force_outer_xml_tag=True): def sendResult(REQUEST, data, name=None, format=None, force_outer_xml_tag=True): - if format is None: + if (format is None) or (format == "html"): return data elif format == "xml": # name is outer tagname return sendXML( From db781d71e33404210d583cd4f1d53deede537f59 Mon Sep 17 00:00:00 2001 From: IDK Date: Sat, 1 May 2021 14:50:34 +0200 Subject: [PATCH 2/6] Modified list_dept --- ZScoDoc.py | 36 ++++++++++++++++++++++++++---------- sco_find_etud.py | 2 +- sco_formsemestre.py | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ZScoDoc.py b/ZScoDoc.py index 59a26a6ca..d7f709a3a 100644 --- a/ZScoDoc.py +++ b/ZScoDoc.py @@ -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