[845] | 1 | ## Script (Python) "getCoursesInfo" |
---|
[556] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=student=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: getCoursesInfo.py 1988 2007-07-05 11:14:12Z joachim $ |
---|
[556] | 11 | """ |
---|
| 12 | return Info about the Faculties |
---|
| 13 | """ |
---|
[1366] | 14 | def cmpsemester(a,b): |
---|
| 15 | if a.semester == b.semester: |
---|
| 16 | return 0 |
---|
| 17 | if a.semester > b.semester: |
---|
| 18 | return 1 |
---|
| 19 | return -1 |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
[556] | 23 | request = context.REQUEST |
---|
| 24 | |
---|
| 25 | wf = context.portal_workflow |
---|
[603] | 26 | path_info = request.get('PATH_INFO').split('/') |
---|
[556] | 27 | mtool = context.portal_membership |
---|
| 28 | |
---|
| 29 | info = {} |
---|
[1988] | 30 | dep_id = path_info[-2] |
---|
| 31 | #dep_id = context.aq_parent.getId() |
---|
[573] | 32 | info['action'] = "%s" % context.absolute_url() |
---|
[556] | 33 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 34 | info['doc'] = context.getContent() |
---|
[1988] | 35 | # res = context.portal_catalog(meta_type="Department",id = dep_id) |
---|
| 36 | # info['courses'] = [] |
---|
| 37 | # if not res: |
---|
| 38 | # return info |
---|
| 39 | # brain = res[-1] |
---|
| 40 | # cp = brain.getPath() |
---|
| 41 | cp = '/'.join(path_info[:-2]) |
---|
[556] | 42 | info['container_path'] = cp |
---|
| 43 | info['dep_id'] = dep_id |
---|
| 44 | |
---|
[1366] | 45 | res = context.courses_catalog(department=dep_id) |
---|
| 46 | items = [ brain for brain in res] |
---|
| 47 | items.sort(cmpsemester) |
---|
| 48 | rows = [] |
---|
| 49 | for r in items: |
---|
| 50 | row = {} |
---|
| 51 | code = getattr(r,'code',None) |
---|
| 52 | if code is None: |
---|
| 53 | continue |
---|
| 54 | ro = getattr(context,code) |
---|
| 55 | row['id'] = code |
---|
| 56 | row['title'] = r['title'] |
---|
| 57 | row['semester'] = r['semester'] |
---|
| 58 | row['url'] = "%s/%s" % (context.absolute_url(),code) |
---|
| 59 | row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 60 | row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 61 | rows.append(row) |
---|
| 62 | #from Products.zdb import set_trace;set_trace() |
---|
| 63 | ##res = context.portal_catalog(container_path="%s/courses" % cp) |
---|
| 64 | ##items = [] |
---|
| 65 | ##for sem in ('1','2'): |
---|
| 66 | ## for r in res: |
---|
| 67 | ## row = {} |
---|
| 68 | ## ro = r.getObject() |
---|
| 69 | ## rd = ro.getContent() |
---|
| 70 | ## if rd.semester != sem: |
---|
| 71 | ## continue |
---|
| 72 | ## row['id'] = r.getId |
---|
| 73 | ## row['title'] = rd.Title() |
---|
| 74 | ## row['semester'] = rd.semester |
---|
| 75 | ## row['url'] = ro.absolute_url() |
---|
| 76 | ## row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 77 | ## row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 78 | ## items.append(row) |
---|
| 79 | info['courses'] = rows |
---|
[556] | 80 | return info |
---|