## Script (Python) "getCoursesInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getCoursesInfo.py 2633 2007-11-12 18:46:13Z joachim $ """ return Info about the Faculties """ def cmpsemester(a,b): if a.semester == b.semester: return 0 if a.semester > b.semester: return 1 return -1 request = context.REQUEST wf = context.portal_workflow path_info = request.get('PATH_INFO').split('/') mtool = context.portal_membership info = {} #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] dep_id = context.aq_parent.getId() info['action'] = "%s" % context.absolute_url() info['choosen_ids'] = request.get('ids',[]) info['doc'] = context.getContent() res = context.portal_catalog(meta_type="Department",id = dep_id) info['courses'] = [] if not res: return info brain = res[-1] cp = brain.getPath() info['container_path'] = cp info['dep_id'] = dep_id res = context.courses_catalog(department=dep_id) items = [ brain for brain in res] items.sort(cmpsemester) rows = [] for r in items: row = {} code = getattr(r,'code',None) if code is None: continue ro = getattr(context,code) row['id'] = code row['title'] = r['title'] row['semester'] = r['semester'] row['url'] = "%s/%s" % (context.absolute_url(),code) row['review_state'] = wf.getInfoFor(ro,'review_state','None') row['is_editable'] = mtool.checkPermission('Modify portal content', ro) rows.append(row) rows.sort(cmp=lambda x,y: cmp("%(semester)s%(id)s" % x, "%(semester)s%(id)s" % y)) info['courses'] = rows return info