Changeset 2448 for WAeUP_SRP/base/skins/waeup_student/course_edit.py
- Timestamp:
- 27 Oct 2007, 12:03:25 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/skins/waeup_student/course_edit.py
r2053 r2448 10 10 """ 11 11 """ 12 wf = context.portal_workflow 12 try: 13 from Products.zdb import set_trace 14 except: 15 def set_trace(): 16 pass 13 17 from urllib import urlencode 14 18 from Products.CPSDocument.utils import getFormUidUrlArg 19 from Products.AdvancedQuery import Eq, Between, Le,In 15 20 import DateTime 16 21 current = DateTime.DateTime() 17 22 import logging 18 23 logger = logging.getLogger('Skins.course_edit') 24 wf = context.portal_workflow 25 request = REQUEST 26 edit = "edit" in request.form.keys() 27 mtool = context.portal_membership 28 member = mtool.getAuthenticatedMember() 29 member_id = str(member) 30 requested_id = context.getStudentId() 31 if requested_id and not context.isStaff() and member_id != requested_id: 32 logger.info('%s tried to access personal object of %s' % (member_id,requested_id)) 33 student_id = requested_id 34 return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) 35 elif context.isStaff(): 36 student_id = requested_id 37 else: 38 student_id = member_id 39 40 level_id = context.getId() 41 course_id = traverse_subpath[0] 42 query = Eq('student_id',student_id) &\ 43 Eq('level_id', level_id) &\ 44 Eq('code', course_id) 19 45 20 info = context.getCourseResultInfo() 46 course_results = context.course_results.evalAdvancedQuery(query) 47 mode = 'edit' 48 object = {} 49 course = course_results[0] 50 for field in context.course_results.schema(): 51 object[field] = getattr(course,field) 52 lt = context.portal_layouts 53 res,psm, ds = lt.renderLayout(schema_id = 'student_course_result', 54 layout_id = 'student_course_result_fe', 55 layout_mode = mode, 56 context=context, 57 mapping=edit and REQUEST, 58 ob=object, 59 commit = False) 21 60 22 if info is None: 23 logger.info('Anonymous user tried to access %s' % REQUEST.get('URL0')) 24 return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) 61 while True: 62 if psm == 'invalid': 63 psm = "Please correct your input" 64 break 65 elif psm == '': 66 break 67 if edit: 68 data = {} 69 dm = ds.getDataModel() 70 for field in context.course_results.schema(): 71 if dm.has_key("%s" % field): 72 data[field] = dm.get(field) 73 data['key'] = object['key'] 74 context.course_results.modifyRecord(**data) 75 logger.info('%s edited course result data %s' % (student_id, course_id)) 76 psm = 'psm_content_changed' 77 break 25 78 26 student = info['student'] 27 #per = info['per'] 28 course_doc = info['course_doc'] 29 state = info['review_state'] 30 result_state = wf.getInfoFor(context,'review_state',None) 31 if result_state == "closed": 32 try: 33 context.portal_workflow.doActionFor(context,'open') 34 except: 35 pass 79 return context.course_edit_form(rendered = res, 80 psm = psm, 81 mode = mode, 82 ds = ds, 83 ) 36 84 37 is_valid, ds = course_doc.validate(request=REQUEST,38 schema_id = 'student_course_result',39 layout_id = 'student_course_result_fe',40 proxy=context,41 use_session=True)42 43 psm = ""44 args = {}45 action = "/course_edit_form"46 base_url = context.absolute_url()47 48 if is_valid:49 if cpsdocument_edit_button:50 #name = "%(firstname)s %(middlename)s %(lastname)s" % ds51 #name = name.strip()52 #name = name.replace(' ',' ')53 #email = ds.get('email')54 #phone = ds.get('phone')55 #student_id = context.getStudentId()56 #context.students_catalog.modifyRecord(id = student_id,57 # name = name,58 # email = email,59 # phone = phone,60 # sex = ds.get('sex'),61 # )62 logger.info('%s (%s) edited course result data %s' % (info['id'],info['review_state'],context.id))63 #action = ""64 #base_url = student.absolute_url()65 #url = base_url + action66 psm = 'psm_content_changed'67 else:68 psm = 'psm_content_error'69 args = getFormUidUrlArg(REQUEST)70 71 args['portal_status_message'] = psm72 url = base_url + action + '?' + urlencode(args)73 REQUEST.RESPONSE.redirect(url)
Note: See TracChangeset for help on using the changeset viewer.