[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 | |
---|
[3753] | 15 | #from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[3611] | 16 | mtool = context.portal_membership |
---|
| 17 | member = mtool.getAuthenticatedMember() |
---|
| 18 | lec_id = member_id = str(member) |
---|
| 19 | if mtool.isAnonymousUser(): |
---|
| 20 | return None |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | def cmpsemester(a,b): |
---|
| 24 | if a.semester == b.semester: |
---|
| 25 | return 0 |
---|
| 26 | if a.semester > b.semester: |
---|
| 27 | return 1 |
---|
| 28 | return -1 |
---|
| 29 | |
---|
| 30 | request = context.REQUEST |
---|
| 31 | |
---|
| 32 | path_info = request.get('PATH_INFO').split('/') |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | info = {} |
---|
| 36 | info['lec_id'] = lec_id |
---|
| 37 | |
---|
| 38 | res = context.courses_catalog(lecturer=lec_id) |
---|
[3753] | 39 | #query = Eq('lecturer',lec_id) |
---|
| 40 | #res = context.courses_catalog.evalAdvancedQuery(query) #works both with lecturer as TextIndex |
---|
[3611] | 41 | items = [ brain for brain in res] |
---|
| 42 | items.sort(cmpsemester) |
---|
| 43 | rows = [] |
---|
| 44 | for r in items: |
---|
| 45 | row = {} |
---|
| 46 | code = getattr(r,'code',None) |
---|
| 47 | if code is None: |
---|
| 48 | continue |
---|
| 49 | #ro = getattr(context,code) |
---|
| 50 | row['id'] = code |
---|
| 51 | row['title'] = r['title'] |
---|
| 52 | row['semester'] = r['semester'] |
---|
| 53 | row['course_url'] = "%s/campus/academics/%s/%s/courses/%s" % (context.portal_url(),r['faculty'],r['department'],code) |
---|
| 54 | row['list_url'] = "%s/getLecturerCourseResults?course_id=%s" % (context.portal_url(),code) |
---|
| 55 | #row['review_state'] = wf.getInfoFor(ro,'review_state','None') |
---|
| 56 | #row['is_editable'] = mtool.checkPermission('Modify portal content', ro) |
---|
| 57 | rows.append(row) |
---|
| 58 | rows.sort(cmp=lambda x,y: cmp("%(semester)s%(id)s" % x, |
---|
| 59 | "%(semester)s%(id)s" % y)) |
---|
| 60 | info['courses'] = rows |
---|
| 61 | return info |
---|