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