1 | ## Script (Python) "getCoursesInfo" |
---|
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 | ## |
---|
10 | # $Id: getCoursesInfo.py 1366 2007-01-27 15:40:19Z joachim $ |
---|
11 | """ |
---|
12 | return Info about the Faculties |
---|
13 | """ |
---|
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 | |
---|
23 | request = context.REQUEST |
---|
24 | |
---|
25 | wf = context.portal_workflow |
---|
26 | path_info = request.get('PATH_INFO').split('/') |
---|
27 | mtool = context.portal_membership |
---|
28 | |
---|
29 | info = {} |
---|
30 | #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] |
---|
31 | dep_id = context.aq_parent.getId() |
---|
32 | info['action'] = "%s" % context.absolute_url() |
---|
33 | info['choosen_ids'] = request.get('ids',[]) |
---|
34 | info['doc'] = context.getContent() |
---|
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 | info['container_path'] = cp |
---|
42 | info['dep_id'] = dep_id |
---|
43 | |
---|
44 | res = context.courses_catalog(department=dep_id) |
---|
45 | items = [ brain for brain in res] |
---|
46 | items.sort(cmpsemester) |
---|
47 | rows = [] |
---|
48 | for r in items: |
---|
49 | row = {} |
---|
50 | code = getattr(r,'code',None) |
---|
51 | if code is None: |
---|
52 | continue |
---|
53 | ro = getattr(context,code) |
---|
54 | row['id'] = code |
---|
55 | row['title'] = r['title'] |
---|
56 | row['semester'] = r['semester'] |
---|
57 | row['url'] = "%s/%s" % (context.absolute_url(),code) |
---|
58 | row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
59 | row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
60 | rows.append(row) |
---|
61 | #from Products.zdb import set_trace;set_trace() |
---|
62 | ##res = context.portal_catalog(container_path="%s/courses" % cp) |
---|
63 | ##items = [] |
---|
64 | ##for sem in ('1','2'): |
---|
65 | ## for r in res: |
---|
66 | ## row = {} |
---|
67 | ## ro = r.getObject() |
---|
68 | ## rd = ro.getContent() |
---|
69 | ## if rd.semester != sem: |
---|
70 | ## continue |
---|
71 | ## row['id'] = r.getId |
---|
72 | ## row['title'] = rd.Title() |
---|
73 | ## row['semester'] = rd.semester |
---|
74 | ## row['url'] = ro.absolute_url() |
---|
75 | ## row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
76 | ## row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
77 | ## items.append(row) |
---|
78 | info['courses'] = rows |
---|
79 | return info |
---|