[3611] | 1 | ## Script (Python) "getLecturerCoursesInfo" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters= |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: getCoursesInfo.py 3482 2008-05-01 05:54:53Z henrik $ |
---|
| 11 | """ |
---|
| 12 | return Info about the Courses |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | mtool = context.portal_membership |
---|
| 16 | member = mtool.getAuthenticatedMember() |
---|
| 17 | lec_id = member_id = str(member) |
---|
| 18 | if mtool.isAnonymousUser(): |
---|
| 19 | return None |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | def cmpsemester(a,b): |
---|
| 23 | if a.semester == b.semester: |
---|
| 24 | return 0 |
---|
| 25 | if a.semester > b.semester: |
---|
| 26 | return 1 |
---|
| 27 | return -1 |
---|
| 28 | |
---|
| 29 | request = context.REQUEST |
---|
| 30 | |
---|
| 31 | path_info = request.get('PATH_INFO').split('/') |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | info = {} |
---|
| 35 | info['lec_id'] = lec_id |
---|
| 36 | |
---|
| 37 | res = context.courses_catalog(lecturer=lec_id) |
---|
| 38 | items = [ brain for brain in res] |
---|
| 39 | items.sort(cmpsemester) |
---|
| 40 | rows = [] |
---|
| 41 | for r in items: |
---|
| 42 | row = {} |
---|
| 43 | code = getattr(r,'code',None) |
---|
| 44 | if code is None: |
---|
| 45 | continue |
---|
| 46 | #ro = getattr(context,code) |
---|
| 47 | row['id'] = code |
---|
| 48 | row['title'] = r['title'] |
---|
| 49 | row['semester'] = r['semester'] |
---|
| 50 | row['course_url'] = "%s/campus/academics/%s/%s/courses/%s" % (context.portal_url(),r['faculty'],r['department'],code) |
---|
| 51 | row['list_url'] = "%s/getLecturerCourseResults?course_id=%s" % (context.portal_url(),code) |
---|
| 52 | #row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 53 | #row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 54 | rows.append(row) |
---|
| 55 | rows.sort(cmp=lambda x,y: cmp("%(semester)s%(id)s" % x, |
---|
| 56 | "%(semester)s%(id)s" % y)) |
---|
| 57 | info['courses'] = rows |
---|
| 58 | return info |
---|