1 | #-*- mode: python; mode: fold -*- |
---|
2 | from Globals import InitializeClass |
---|
3 | from AccessControl import ClassSecurityInfo |
---|
4 | |
---|
5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
6 | from Products.CMFCore.permissions import View |
---|
7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
9 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
10 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
11 | #from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
12 | #from Products.CPSCore.CPSBase import CPSBaseBTreeDocument as BaseBTreeDocument |
---|
13 | #from Products.CMFCore.DirectoryView import registerDirectory |
---|
14 | |
---|
15 | #registerDirectory('skins', globals()) |
---|
16 | #registerDirectory('skins/waeup_default', globals()) |
---|
17 | #registerDirectory('skins/waeup_faculty', globals()) |
---|
18 | |
---|
19 | import csv,re |
---|
20 | import logging |
---|
21 | import Globals |
---|
22 | p_home = Globals.package_home(globals()) |
---|
23 | i_home = Globals.INSTANCE_HOME |
---|
24 | |
---|
25 | def makeCertificateCode(code): |
---|
26 | code = code.replace('.','') |
---|
27 | code = code.replace('(','') |
---|
28 | code = code.replace(')','') |
---|
29 | code = code.replace('/','') |
---|
30 | code = code.replace(' ','') |
---|
31 | code = code.replace('_','') |
---|
32 | return code |
---|
33 | |
---|
34 | class AcademicsFolder(CPSDocument): ###( |
---|
35 | """ |
---|
36 | WAeUP AcademicsFolder containing StudyCourses |
---|
37 | """ |
---|
38 | meta_type = 'AcademicsFolder' |
---|
39 | portal_type = meta_type |
---|
40 | security = ClassSecurityInfo() |
---|
41 | use_catalog_for_folder_contents = True |
---|
42 | |
---|
43 | security.declareProtected(View,"Title") |
---|
44 | def Title(self): |
---|
45 | """compose title""" |
---|
46 | return "Academic Section" |
---|
47 | |
---|
48 | security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###( |
---|
49 | def loadFacultiesFromCSV(self): |
---|
50 | """install Universityspecific Faculies from CSV values""" |
---|
51 | #return |
---|
52 | name = 'faculty' |
---|
53 | no_import = False |
---|
54 | logger = logging.getLogger('%s_import' % name) |
---|
55 | logger.info('Start loading from %s.csv' % name) |
---|
56 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
57 | try: |
---|
58 | faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
59 | except: |
---|
60 | logger.error('Error reading %s.csv' % name) |
---|
61 | return |
---|
62 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
63 | facs = {} |
---|
64 | for f in l: |
---|
65 | facs[f.id] = f.getObject() |
---|
66 | for faculty in faculties: |
---|
67 | logger.info('processing %(Session)s %(FacultyCode)s %(Description)s %(CollegeCode)s %(FacultyKey)s %(Status)s %(degree_grade)s %(Bankcode)s' % faculty) |
---|
68 | fid = faculty['FacultyCode'] |
---|
69 | f = facs.get(fid,None) |
---|
70 | if f is None: |
---|
71 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
72 | logger.info('Creating Faculty with ID %(FacultyCode)s %(Description)s' % faculty) |
---|
73 | academics.invokeFactory('Faculty', fid) |
---|
74 | f = getattr(self,fid) |
---|
75 | d = {'Title': faculty['Description']} |
---|
76 | else: |
---|
77 | d = {} |
---|
78 | ## if not no_import: |
---|
79 | ## no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
80 | ## no_import.write('"Session","FacultyCode","Description","CollegeCode","FacultyKey","Status","degree_grade","Bankcode"\n') |
---|
81 | ## logger.info('Faculty with ID %(FacultyCode)s %(Description)s already exists' % faculty) |
---|
82 | ## no_import.write('"%(Session)s","%(FacultyCode)s","%(Description)s","%(CollegeCode)s","%(FacultyKey)s","%(Status)s","%(degree_grade)s","%(Bankcode)s"\n' % faculty) |
---|
83 | d['bank_code'] = faculty.get("Bankcode") |
---|
84 | d["degree_grade"] = faculty.get("degree_grade") |
---|
85 | d['institution_type'] = 'faculty' |
---|
86 | d['Description'] = '' |
---|
87 | d['college_code'] = faculty.get('CollegeCode') |
---|
88 | f.getContent().edit(mapping=d) |
---|
89 | return self.academics.academics_contents() |
---|
90 | ###) |
---|
91 | |
---|
92 | security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###( |
---|
93 | def yamlDumpFaculties(self): |
---|
94 | """dump Faculies to Yaml""" |
---|
95 | #return |
---|
96 | import yaml |
---|
97 | logger = logging.getLogger('dumpfaculties') |
---|
98 | logger.info('Start dumping Faculties') |
---|
99 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
100 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
101 | facs = {} |
---|
102 | for f in l: |
---|
103 | facs[f.id] = f.getObject() |
---|
104 | for fid in facs.keys(): |
---|
105 | faculty = facs.get(fid).aq_self |
---|
106 | logger.info('dumping %s %s ' % (faculty.id, faculty.title)) |
---|
107 | print yaml.dump(faculty) |
---|
108 | return self.academics.temporary_view_all() |
---|
109 | return self.temporary_view_all() |
---|
110 | |
---|
111 | ###) |
---|
112 | |
---|
113 | security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###( |
---|
114 | def loadDepartmentsFromCSV(self): |
---|
115 | """install Universityspecific Faculies from CSV values""" |
---|
116 | #return |
---|
117 | name = 'departments' |
---|
118 | no_import = False |
---|
119 | logger = logging.getLogger('loaddepartments') |
---|
120 | try: |
---|
121 | deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb")) |
---|
122 | except: |
---|
123 | logger.error('Error reading departments.csv') |
---|
124 | return |
---|
125 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
126 | facs = {} |
---|
127 | for f in l: |
---|
128 | facs[f.id] = f.getObject() |
---|
129 | for dep in deps: |
---|
130 | logger.info('Processing %(Session)s %(DeptCode)s %(Description)s %(FacultyCode)s' % dep) |
---|
131 | fid = dep['FacultyCode'] |
---|
132 | f = facs.get(fid,None) |
---|
133 | if f is None: |
---|
134 | logger.info( "No Faculty with ID: %s" % fid) |
---|
135 | if not no_import: |
---|
136 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
137 | no_import.write('"Session","DeptCode","Description","FacultyCode"\n') |
---|
138 | no_import.write( "No Faculty with ID: %s\n" % fid) |
---|
139 | no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep) |
---|
140 | else: |
---|
141 | did = dep.get('DeptCode') |
---|
142 | d = getattr(f,did,None) |
---|
143 | if d is None or d.portal_type == "Faculty": |
---|
144 | logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
145 | f.invokeFactory('Department', did) |
---|
146 | d = getattr(f,did) |
---|
147 | dict = {'Title': dep['Description']} |
---|
148 | d.getContent().edit(mapping=dict) |
---|
149 | d.invokeFactory('CoursesFolder','courses') |
---|
150 | courses = getattr(d,'courses') |
---|
151 | dict = {'Title': 'Courses'} |
---|
152 | courses.getContent().edit(mapping=dict) |
---|
153 | d.invokeFactory('CertificatesFolder','certificates') |
---|
154 | certificates = getattr(d,'certificates') |
---|
155 | dict = {'Title': 'Certificates'} |
---|
156 | certificates.getContent().edit(mapping=dict) |
---|
157 | return self.academics.academics_contents() |
---|
158 | ###) |
---|
159 | |
---|
160 | security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###( |
---|
161 | def loadCoursesFromCSV(self): |
---|
162 | """install Universityspecific Courses from CSV values""" |
---|
163 | #return |
---|
164 | name = 'courses' |
---|
165 | no_import = False |
---|
166 | logger = logging.getLogger('loadcourses') |
---|
167 | try: |
---|
168 | courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb")) |
---|
169 | except: |
---|
170 | logger.error('Error reading courses.csv') |
---|
171 | return |
---|
172 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
173 | facs = {} |
---|
174 | for f in l: |
---|
175 | facs[f.id] = f.getObject() |
---|
176 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
177 | deps = {} |
---|
178 | for d in dl: |
---|
179 | deps[d.id] = d.getObject() |
---|
180 | cl = self.portal_catalog({'meta_type': "Course"}) |
---|
181 | course_list = [ c.id for c in cl] |
---|
182 | for course in courses: |
---|
183 | logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course) |
---|
184 | ## if course.get("FORMERCODE").endswith('BITS'): |
---|
185 | ## continue |
---|
186 | depid = course.get('Dept').upper() |
---|
187 | if depid in deps.keys(): |
---|
188 | dept= deps.get(depid) |
---|
189 | ## elif depid in facs.keys(): |
---|
190 | ## dept= facs.get(depid) |
---|
191 | else: |
---|
192 | logger.info("Dep %(Dept)s for Course %(CourseCode)s not found" % course) |
---|
193 | if not no_import: |
---|
194 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
195 | no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n') |
---|
196 | no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course) |
---|
197 | no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course) |
---|
198 | continue |
---|
199 | course_id = ''.join(re.split('\W+',course.get('CourseCode'))) |
---|
200 | if len(course_id) == 3: |
---|
201 | course_id = "%s000" % course_id |
---|
202 | elif len(course_id) > 10: |
---|
203 | logger.info("invalid course_code %(CourseCode)s" % course) |
---|
204 | if not no_import: |
---|
205 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
206 | no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n') |
---|
207 | no_import.write("invalid course_code %(CourseCode)s\n" % course) |
---|
208 | no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course) |
---|
209 | continue |
---|
210 | courses = dept.courses |
---|
211 | c = getattr(courses,course_id,None) |
---|
212 | if c is None: |
---|
213 | logger.info('Creating Course %(CourseCode)s %(Description)s in Department %(Dept)s' % course) |
---|
214 | courses.invokeFactory('Course', course_id) |
---|
215 | c = getattr(courses,course_id) |
---|
216 | dict = {'Title': course['Description']} |
---|
217 | dict['code'] = course_id |
---|
218 | dict['org_code'] = course.get('CourseCode') |
---|
219 | dict['credits'] = course.get('Credits') |
---|
220 | dict['semester'] = course.get('Semester') |
---|
221 | dict['session'] = course.get('Session') |
---|
222 | dict['category'] = course.get('Category') |
---|
223 | dict['adm_status'] = course.get('AdmStatus') |
---|
224 | dict['former_code'] = course.get('FORMERCODE') |
---|
225 | pm = course.get('PassMark') |
---|
226 | if pm.find(',') > -1: |
---|
227 | pm.replace(',','.') |
---|
228 | elif pm == "": |
---|
229 | pm = "0.0" |
---|
230 | try: |
---|
231 | dict['passmark'] = int(float(pm)) |
---|
232 | except: |
---|
233 | dict['passmark'] = 0 |
---|
234 | c.getContent().edit(mapping=dict) |
---|
235 | return self.academics.academics_contents() |
---|
236 | ###) |
---|
237 | |
---|
238 | security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###( |
---|
239 | |
---|
240 | def loadCertificatesFromCSV(self): |
---|
241 | """install Universityspecific Certificates from CSV values""" |
---|
242 | #return |
---|
243 | name = 'certificates' |
---|
244 | no_import = False |
---|
245 | logger = logging.getLogger('loadcertificates') |
---|
246 | try: |
---|
247 | certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb")) |
---|
248 | except: |
---|
249 | logger.error('Error reading certificates.csv') |
---|
250 | return |
---|
251 | f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})] |
---|
252 | #d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] |
---|
253 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
254 | deps = {} |
---|
255 | for d in dl: |
---|
256 | deps[d.id] = d.getObject() |
---|
257 | for certificate in certificates: |
---|
258 | logger.info('Processing %(CertCode)s %(Description)s %(Faculty)s %(MaxPass)s %(MaxLoad)s %(session)s %(PromotionCredits)s %(Probationcredits)s %(StartLevel)s %(endLevel)s %(Nyears)s %(Ncore)s %(MaxElect)s %(MPREFIX)s %(Dept)s %(Admstatus)s %(category)s' % certificate) |
---|
259 | depid = certificate.get('Dept') |
---|
260 | facid = certificate.get('Faculty') |
---|
261 | if facid not in f_ids: |
---|
262 | logger.info('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found' % certificate) |
---|
263 | if not no_import: |
---|
264 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
265 | no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n') |
---|
266 | no_import.write('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found\n' % certificate) |
---|
267 | no_import.write('"%(CertCode)s","%(Description)s","%(Faculty)s","%(MaxPass)s","%(MaxLoad)s","%(session)s","%(PromotionCredits)s","%(Probationcredits)s","%(StartLevel)s","%(endLevel)s","%(Nyears)s","%(Ncore)s","%(MaxElect)s","%(MPREFIX)s","%(Dept)s","%(Admstatus)s","%(category)s"\n' % certificate) |
---|
268 | continue |
---|
269 | if not deps.has_key(depid): |
---|
270 | logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate) |
---|
271 | if not no_import: |
---|
272 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
273 | no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n') |
---|
274 | no_import.write('Department %(Dept)s for %(CertCode)s %(Description)s not found\n' % certificate) |
---|
275 | no_import.write('"%(CertCode)s","%(Description)s","%(Faculty)s","%(MaxPass)s","%(MaxLoad)s","%(session)s","%(PromotionCredits)s","%(Probationcredits)s","%(StartLevel)s","%(endLevel)s","%(Nyears)s","%(Ncore)s","%(MaxElect)s","%(MPREFIX)s","%(Dept)s","%(Admstatus)s","%(category)s"\n' % certificate) |
---|
276 | continue |
---|
277 | #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate |
---|
278 | dep = deps[depid] |
---|
279 | certificates = dep.certificates |
---|
280 | code = makeCertificateCode(certificate.get('CertCode')) |
---|
281 | certificate_id = code |
---|
282 | c = getattr(certificates,certificate_id,None) |
---|
283 | if c is None: |
---|
284 | #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
285 | logger.info('Creating certificate %(CertCode)s %(Description)s in Department %(Dept)s' % certificate) |
---|
286 | certificates.invokeFactory('Certificate', certificate_id) |
---|
287 | c = getattr(certificates,certificate_id) |
---|
288 | dict = {'Title': certificate['Description']} |
---|
289 | dict['code'] = code |
---|
290 | dict['faculty'] = certificate.get('Faculty') |
---|
291 | dict['department'] = certificate.get('Dept') |
---|
292 | dict['max_pass'] = certificate.get('MaxPass') |
---|
293 | dict['max_load'] = certificate.get('MaxLoad') |
---|
294 | dict['admin_status'] = certificate.get('Admstatus') |
---|
295 | dict['category'] = certificate.get('category') |
---|
296 | dict['m_prefix'] = certificate.get('MPREFIX') |
---|
297 | dict['nr_years'] = int(certificate.get('Nyears')) |
---|
298 | nc = certificate.get('Ncore','1') |
---|
299 | try: |
---|
300 | dict['n_core'] = int(nc) |
---|
301 | except: |
---|
302 | dict['n_core'] = 1 |
---|
303 | dict['start_level'] = certificate.get('StartLevel') |
---|
304 | dict['end_level'] = certificate.get('endLevel') |
---|
305 | dict['promotion_credits'] = certificate.get('PromotionCredits') |
---|
306 | dict['probation_credits'] = certificate.get('ProbationCredits') |
---|
307 | else: |
---|
308 | dict = {} |
---|
309 | dict['original_code'] = certificate.get('CertCode') |
---|
310 | print |
---|
311 | c.getContent().edit(mapping=dict) |
---|
312 | return self.academics.academics_contents() |
---|
313 | ###) |
---|
314 | |
---|
315 | security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromCSV")###( |
---|
316 | def loadCertificateCoursesFromCSV(self): |
---|
317 | """install Certificate Courses from CSV values""" |
---|
318 | #return |
---|
319 | logger = logging.getLogger('loadcertificatecourses') |
---|
320 | name = 'certificate_courses' |
---|
321 | no_import = False |
---|
322 | try: |
---|
323 | cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb")) |
---|
324 | except: |
---|
325 | logger.error('Error reading course_level_courses.csv') |
---|
326 | return |
---|
327 | d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] |
---|
328 | c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})] |
---|
329 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
330 | certs = {} |
---|
331 | for f in l: |
---|
332 | certs[f.id] = f.getObject() |
---|
333 | for cert_course in cert_courses: |
---|
334 | logger.info('Processing %(CosCode)s %(CertCode)s %(Session)s %(Level)s %(Core)s %(Elective)s %(Mandatory)s %(AdmStatus)s %(Dept)s %(Semester)s' % cert_course) |
---|
335 | depid = cert_course.get('Dept') |
---|
336 | course_code = cert_course.get('CosCode') |
---|
337 | code = cert_course.get('CertCode') |
---|
338 | code = code.replace('.','') |
---|
339 | code = code.replace('(','') |
---|
340 | code = code.replace(')','') |
---|
341 | code = code.replace('/','') |
---|
342 | code = code.replace(' ','') |
---|
343 | code = code.replace('_','') |
---|
344 | ## if cert_course.get('Session') != '2002/2003': |
---|
345 | ## continue |
---|
346 | ## certificate = self.portal_catalog({'meta_type': "Certificate", |
---|
347 | ## 'SearchableText': code}) |
---|
348 | ## if not certificate: |
---|
349 | if not code in certs.keys(): |
---|
350 | #print code |
---|
351 | em = 'CertCode %(CertCode)s for %(CosCode)s not found\n' % cert_course |
---|
352 | logger.info(em) |
---|
353 | if not no_import: |
---|
354 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
355 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
356 | no_import.write(em) |
---|
357 | no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course) |
---|
358 | continue |
---|
359 | certificate = certs[code] |
---|
360 | certificate_code = certificate.getId() |
---|
361 | if course_code not in c_ids: |
---|
362 | em = 'CorseCode %(CosCode)s for %(CertCode)s not found in Courses\n' % cert_course |
---|
363 | logger.info(em) |
---|
364 | if not no_import: |
---|
365 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
366 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
367 | no_import.write(em) |
---|
368 | no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course) |
---|
369 | continue |
---|
370 | if depid not in d_ids: |
---|
371 | em = 'Department %(Dept)s for %(CertCode)s not found\n' % cert_course |
---|
372 | logger.info(em) |
---|
373 | if not no_import: |
---|
374 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
375 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
376 | no_import.write(em) |
---|
377 | no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course) |
---|
378 | continue |
---|
379 | level = cert_course.get('Level') |
---|
380 | l = getattr(certificate,level,None) |
---|
381 | if l is None: |
---|
382 | #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
383 | logger.info('Creating Level %(Level)s in certificate %(CertCode)s' % cert_course) |
---|
384 | certificate.invokeFactory('StudyLevel', level) |
---|
385 | l = getattr(certificate, level) |
---|
386 | l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
387 | l.invokeFactory('Semester','first') |
---|
388 | l.invokeFactory('Semester','second') |
---|
389 | certificate.orderObjects('id') |
---|
390 | first_s = getattr(l,'first') |
---|
391 | first_s.getContent().edit(mapping={'Title': 'First Semester'}) |
---|
392 | second_s = getattr(l,'second') |
---|
393 | second_s.getContent().edit(mapping={'Title': 'Second Semester'}) |
---|
394 | if cert_course.get('Semester') == '1': |
---|
395 | semester = first_s |
---|
396 | else: |
---|
397 | semester = second_s |
---|
398 | if hasattr(semester,course_code): |
---|
399 | logger.info('Duplicate %(CosCode)s in Level %(Level)s' % cert_course) |
---|
400 | if not no_import: |
---|
401 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
402 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
403 | ## no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course) |
---|
404 | ## no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course) |
---|
405 | continue |
---|
406 | semester.invokeFactory('CertificateCourse',course_code) |
---|
407 | cc = getattr(semester,course_code) |
---|
408 | dict = {} |
---|
409 | dict['code'] = cert_course.get('CosCode') |
---|
410 | dict['certificate_code'] = code |
---|
411 | dict['certificate_code_org'] = cert_course.get('CertCode') |
---|
412 | dict['department'] = cert_course.get('Dept') |
---|
413 | dict['admin_status'] = cert_course.get('Admstatus') |
---|
414 | dict['session'] = cert_course.get('Session') |
---|
415 | if cert_course.get('Core') != '': |
---|
416 | dict['core_or_elective'] = True |
---|
417 | else: |
---|
418 | dict['core_or_elective'] = False |
---|
419 | dict['level'] = cert_course.get('Level') |
---|
420 | cc.getContent().edit(mapping=dict) |
---|
421 | return self.academics.academics_contents() |
---|
422 | ###) |
---|
423 | |
---|
424 | InitializeClass(AcademicsFolder) |
---|
425 | |
---|
426 | def addAcademicsFolder(container, id, REQUEST=None, **kw): |
---|
427 | """Add a AcademicsFolder.""" |
---|
428 | ob = AcademicsFolder(id, **kw) |
---|
429 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
430 | |
---|
431 | ###) |
---|
432 | |
---|
433 | class Certificate(CPSDocument): ###( |
---|
434 | """ |
---|
435 | WAeUP Certificate |
---|
436 | """ |
---|
437 | meta_type = 'Certificate' |
---|
438 | portal_type = meta_type |
---|
439 | security = ClassSecurityInfo() |
---|
440 | |
---|
441 | def __init__(self, id, **kw): |
---|
442 | CPSDocument.__init__(self, id, **kw) |
---|
443 | |
---|
444 | ## security.declareProtected(View,"Title") |
---|
445 | ## def Title(self): |
---|
446 | ## """compose title""" |
---|
447 | ## return "Certificate of %s" % (self.title) |
---|
448 | |
---|
449 | InitializeClass(Certificate) |
---|
450 | |
---|
451 | def addCertificate(container, id, REQUEST=None, **kw): |
---|
452 | """Add a Certificate.""" |
---|
453 | ob = Certificate(id, **kw) |
---|
454 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
455 | |
---|
456 | ###) |
---|
457 | |
---|
458 | class StudyLevel(CPSDocument): ###( |
---|
459 | """ |
---|
460 | WAeUP StudyLevel containing the courses and students |
---|
461 | """ |
---|
462 | meta_type = 'StudyLevel' |
---|
463 | portal_type = meta_type |
---|
464 | security = ClassSecurityInfo() |
---|
465 | |
---|
466 | security.declareProtected(View,"Title") |
---|
467 | def Title(self): |
---|
468 | """compose title""" |
---|
469 | return "Level %s" % self.aq_parent.getId() |
---|
470 | |
---|
471 | |
---|
472 | InitializeClass(StudyLevel) |
---|
473 | |
---|
474 | def addStudyLevel(container, id, REQUEST=None, **kw): |
---|
475 | """Add a StudyLevel.""" |
---|
476 | ob = StudyLevel(id, **kw) |
---|
477 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
478 | |
---|
479 | ###) |
---|
480 | |
---|
481 | class CertificateCourse(CPSDocument): ###( |
---|
482 | """ |
---|
483 | WAeUP CertificateCourse |
---|
484 | """ |
---|
485 | meta_type = 'CertificateCourse' |
---|
486 | portal_type = meta_type |
---|
487 | security = ClassSecurityInfo() |
---|
488 | |
---|
489 | def getCourseEntry(self,cid): |
---|
490 | res = self.portal_catalog({'meta_type': "Course", |
---|
491 | 'id': cid}) |
---|
492 | if res: |
---|
493 | return res[-1] |
---|
494 | else: |
---|
495 | return None |
---|
496 | |
---|
497 | security.declareProtected(View,"Title") |
---|
498 | def Title(self): |
---|
499 | """compose title""" |
---|
500 | ce = self.getCourseEntry(self.id.upper()) |
---|
501 | #print self.id, self.aq_parent.id |
---|
502 | if ce: |
---|
503 | return "%s" % ce.Title |
---|
504 | return "No such course" |
---|
505 | |
---|
506 | security.declareProtected(View,"credits") |
---|
507 | def credits(self): |
---|
508 | """credits from course""" |
---|
509 | ce = self.getCourseEntry(self.id) |
---|
510 | if ce: |
---|
511 | return "%s" % ce.credits |
---|
512 | return "0" |
---|
513 | |
---|
514 | security.declareProtected(View,"passmark") |
---|
515 | def passmark(self): |
---|
516 | """passmark from course""" |
---|
517 | ce = self.getCourseEntry(self.id) |
---|
518 | if ce is not None and hasattr(ce,"passmark"): |
---|
519 | return ce.passmark |
---|
520 | |
---|
521 | |
---|
522 | security.declareProtected(View,"coursepath") |
---|
523 | def coursepath(self): |
---|
524 | """coursepath from course""" |
---|
525 | ce = self.getCourseEntry(self.id) |
---|
526 | if ce: |
---|
527 | return ce.getPath() |
---|
528 | return "?" |
---|
529 | |
---|
530 | |
---|
531 | InitializeClass(CertificateCourse) |
---|
532 | |
---|
533 | def addCertificateCourse(container, id, REQUEST=None, **kw): |
---|
534 | """Add a CertificateCourse.""" |
---|
535 | ob = CertificateCourse(id, **kw) |
---|
536 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
537 | ###) |
---|
538 | |
---|
539 | class Faculty(CPSDocument): ###( |
---|
540 | """ |
---|
541 | WAeUP Faculty containing Departments |
---|
542 | """ |
---|
543 | meta_type = 'Faculty' |
---|
544 | portal_type = meta_type |
---|
545 | security = ClassSecurityInfo() |
---|
546 | |
---|
547 | ## def __init__(self, id, **kw): |
---|
548 | ## CPSDocument.__init__(self, id, **kw) |
---|
549 | |
---|
550 | security.declareProtected(View,"Title") |
---|
551 | def Title(self): |
---|
552 | """compose title""" |
---|
553 | return "%s" % (self.title) |
---|
554 | |
---|
555 | |
---|
556 | security.declareProtected(View,"LongTitle") |
---|
557 | def LongTitle(self): |
---|
558 | """compose long_title""" |
---|
559 | prefix = getattr(self,'title_prefix',None) |
---|
560 | if prefix is None: |
---|
561 | prefix = getattr(self,'institution_type','faculty') |
---|
562 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
563 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Faculty of") |
---|
564 | return "%s %s" % (itype,self.title) |
---|
565 | |
---|
566 | InitializeClass(Faculty) |
---|
567 | |
---|
568 | def addFaculty(container, id, REQUEST=None, **kw): |
---|
569 | """Add a Faculty.""" |
---|
570 | ob = Faculty(id, **kw) |
---|
571 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
572 | |
---|
573 | ###) |
---|
574 | |
---|
575 | class Department(CPSDocument): ###( |
---|
576 | """ |
---|
577 | WAeUP Department containing the courses and students |
---|
578 | """ |
---|
579 | meta_type = 'Department' |
---|
580 | portal_type = meta_type |
---|
581 | security = ClassSecurityInfo() |
---|
582 | |
---|
583 | security.declareProtected(View,"LongTitle") |
---|
584 | def LongTitle(self): |
---|
585 | """compose long_title""" |
---|
586 | prefix = getattr(self,'title_prefix',None) |
---|
587 | if prefix is None: |
---|
588 | prefix = getattr(self,'institution_type','department') |
---|
589 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
590 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Department of") |
---|
591 | return "%s %s" % (itype,self.title) |
---|
592 | |
---|
593 | InitializeClass(Department) |
---|
594 | |
---|
595 | def addDepartment(container, id, REQUEST=None, **kw): |
---|
596 | """Add a Department.""" |
---|
597 | object = Department(id, **kw) |
---|
598 | id = object.getId() |
---|
599 | container._setObject(id, object) |
---|
600 | ## dep = getattr(container,id).getEditableContent() #getContent() |
---|
601 | ## dep.invokeFactory('CoursesFolder','Courses') |
---|
602 | ## o = getattr(dep,'Courses') |
---|
603 | ## dict = {'Title': 'Courses'} |
---|
604 | ## o.getContent().edit(mapping=dict) |
---|
605 | ## dep.invokeFactory('CertificatesFolder','Certificates') |
---|
606 | ## o = getattr(dep,'Certificates') |
---|
607 | ## dict = {'Title': 'Certificates'} |
---|
608 | ## o.geetContent().edit(mapping=dict) |
---|
609 | if REQUEST is not None: |
---|
610 | url = container.absolute_url() |
---|
611 | REQUEST.RESPONSE.redirect('%s/manage_main' % url) |
---|
612 | |
---|
613 | ###) |
---|
614 | |
---|
615 | class Course(CPSDocument): ###( |
---|
616 | """ |
---|
617 | WAeUP Course |
---|
618 | """ |
---|
619 | meta_type = 'Course' |
---|
620 | portal_type = meta_type |
---|
621 | security = ClassSecurityInfo() |
---|
622 | |
---|
623 | security.declareProtected(View,"Title") |
---|
624 | def Title(self): |
---|
625 | """compose title""" |
---|
626 | return self.title |
---|
627 | |
---|
628 | InitializeClass(Course) |
---|
629 | |
---|
630 | def addCourse(container, id, REQUEST=None, **kw): |
---|
631 | """Add a Course.""" |
---|
632 | ob = Course(id, **kw) |
---|
633 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
634 | ###) |
---|
635 | |
---|
636 | |
---|