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