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