Changeset 6146 for main/waeup.sirp/trunk
- Timestamp:
- 19 May 2011, 13:50:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r6126 r6146 21 21 from zope.app.security.interfaces import ( 22 22 IAuthentication, IUnauthenticatedPrincipal, ILogout) 23 from zope.securitypolicy.interfaces import IPrincipalRoleManager, IPrincipalRoleMap 23 from zope.securitypolicy.interfaces import ( 24 IPrincipalRoleManager, IPrincipalRoleMap) 24 25 from zope.component import ( 25 26 getUtility, createObject,getAllUtilitiesRegisteredFor) … … 32 33 WAeUPDisplayFormPage, NullValidator) 33 34 from waeup.sirp.browser.interfaces import ( 34 IUniversity, IFacultyContainer, IFaculty, IFacultyAdd, 35 IUniversity, IFacultyContainer, IFaculty, IFacultyAdd, 35 36 IDepartment, IDepartmentAdd, ICourse, ICourseAdd, ICertificate, 36 37 ICertificateAdd, ICertificateCourse, ICertificateCourseAdd) … … 38 39 from waeup.sirp.interfaces import( 39 40 IWAeUPObject, IUserContainer, IUserAccount, IDataCenter, 40 IWAeUPXMLImporter, IWAeUPXMLExporter, IBatchProcessor) 41 IWAeUPXMLImporter, IWAeUPXMLExporter, IBatchProcessor, 42 ILocalRolesAssignable) 41 43 from waeup.sirp.university.catalog import search 42 from waeup.sirp.university.faculty import local_roles as faculty_local_roles43 44 from waeup.sirp.university.vocabularies import course_levels 44 45 from waeup.sirp.widgets.restwidget import ReSTDisplayWidget … … 99 100 grok.require('waeup.Public') 100 101 grok.name('logout') 101 102 102 103 def update(self): 103 104 if not IUnauthenticatedPrincipal.providedBy(self.request.principal): … … 119 120 grok.context(IUniversity) 120 121 pnav = 0 121 122 122 123 form_fields = grok.AutoFields(IUniversity) 123 124 form_fields['frontpage'].custom_widget = ReSTDisplayWidget … … 145 146 self.flash('Settings have been saved.') 146 147 return 147 148 148 149 @grok.action('Save and return') 149 150 def saveAndReturn(self, **data): … … 164 165 self.redirect(self.url(self.context)) 165 166 return 166 167 167 168 #class RemoveFormPage(WAeUPPage): 168 169 # grok.require('waeup.manageUniversity') … … 237 238 def entries(self): 238 239 return () 239 240 240 241 # 241 242 # User container pages... 242 243 # 243 244 244 245 class UserContainerPage(WAeUPPage): 245 246 """Overview page for all local users. … … 249 250 grok.name('index') 250 251 title = 'Portal Users' 251 252 252 253 def update(self, userid=None, adduser=None, edit=None, delete=None): 253 254 if edit is not None and userid is not None: … … 290 291 grok.context(IUserAccount) 291 292 grok.name('index') 292 293 293 294 form_fields = grok.AutoFields(IUserAccount) 294 295 grok.require('waeup.manageUsers') … … 301 302 self.flash('User settings have been saved.') 302 303 return 303 304 304 305 @grok.action('Save and return') 305 306 def saveAndReturn(self, **data): … … 350 351 self.hitlist = search(query=self.query, view=self) 351 352 return 352 353 353 354 # 354 355 # Contact forms... … … 360 361 grok.require('waeup.Public') 361 362 pnav = 2 362 363 363 364 def title(self): 364 365 """Return True if the calling user is authenticated. … … 366 367 userid = self.request.principal.id 367 368 if userid != 'zope.anybody': 368 tt = u'Contact' 369 tt = u'Contact' 369 370 else: 370 tt = u'Enquiries' 371 return tt 372 371 tt = u'Enquiries' 372 return tt 373 373 374 def update(self, *args, **kw): 374 375 form = self.request.form … … 381 382 if not (fullname and email and descr): 382 383 self.flash('Error: All fields must be filled!') 383 return 384 return 384 385 if not re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", 385 386 email): … … 394 395 msg = MIMEText(text % (fullname,regno,descr)) 395 396 msg['From'] = '%s <%s>' % (fullname,email) 396 397 397 398 # These parameters should be part of the portal configuration. 398 399 msg['To'] = 'contact@waeup.org' … … 404 405 server = smtplib.SMTP('localhost') 405 406 server.sendmail(email,'contact@waeup.org',msg.as_string()) 406 407 407 408 server.quit() 408 409 self.flash('Your message has been sent.') 409 return 410 return 410 411 411 412 # … … 426 427 title = u'Data Center Upload' 427 428 pnav = 0 428 429 429 430 def update(self, uploadfile=None, CANCEL=None, SUBMIT=None): 430 431 if CANCEL is not None: … … 480 481 continue 481 482 yield file 482 483 483 484 def update(self, filename=None, select=None, cancel=None): 484 485 if cancel is not None: … … 512 513 reader = csv.reader(open(self.fullpath, 'rb')) 513 514 return reader.next() 514 515 515 516 def getPreviewBody(self): 516 517 """Get the first 5 rows of attached CSV file. … … 553 554 session = ISession(self.request)['waeup.sirp'] 554 555 self.filename = session.get('import_filename', None) 555 556 556 557 if self.filename is None or back1 is not None: 557 558 self.redirect(self.url(self.context, '@@import1')) … … 588 589 mode = None 589 590 importername = None 590 591 591 592 @property 592 593 def nextstep(self): … … 598 599 reader = csv.reader(open(self.fullpath, 'rb')) 599 600 return reader.next() 600 601 601 602 def getPreviewBody(self): 602 603 """Get the first 5 rows of attached CSV file. … … 636 637 result.append(fatal) 637 638 return result 638 639 639 640 @property 640 641 def nextstep(self): … … 646 647 self.mode = session.get('import_mode', None) 647 648 self.importername = session.get('import_importer', None) 648 649 649 650 if None in (self.filename, self.mode, self.importername): 650 651 self.redirect(self.url(self.context, '@@import2')) … … 665 666 self.redirect(self.url(self.context, '@@import4')) 666 667 return 667 668 668 669 self.importer = getUtility(IBatchProcessor, name=self.importername) 669 670 self.reader = csv.DictReader(open(self.fullpath, 'rb')) … … 697 698 self.importername = session.get('import_importer', None) 698 699 self.headerfields = session.get('import_headerfields', None) 699 700 700 701 if None in (self.filename, self.mode, self.importername, 701 702 self.headerfields): … … 708 709 self.redirect(self.url(self.context, '@@show')) 709 710 return 710 711 711 712 self.fullpath = os.path.join(self.context.storage, self.filename) 712 713 self.importer = getUtility(IBatchProcessor, name=self.importername) … … 804 805 grok.name('export.xml') 805 806 grok.require('waeup.manageUniversity') 806 807 807 808 def render(self): 808 809 exporter = IWAeUPXMLExporter(self.context) … … 865 866 # try: 866 867 # del self.context[code] 867 # self.flash('Faculty %s successfully removed.' % code) 868 # self.flash('Faculty %s successfully removed.' % code) 868 869 # except: 869 870 # self.flash('Could not delete %s.' % code) 870 871 871 872 872 873 class FacultyContainerManageFormPage(WAeUPEditFormPage): 873 874 """Manage the basic properties of a `Faculty` instance. … … 885 886 def label(self): 886 887 return 'Manage academic section' 887 888 888 889 def update(self): 889 890 tabs.need() … … 908 909 if len(deleted): 909 910 self.flash('Successfully removed: %s' % ', '.join(deleted)) 910 self.redirect(self.url(self.context, '@@manage')+'#tab-1') 911 return 911 self.redirect(self.url(self.context, '@@manage')+'#tab-1') 912 return 912 913 913 914 @grok.action('Add faculty', validator=NullValidator) 914 915 def addFaculty(self, **data): 915 916 self.redirect(self.url(self.context, '@@add')) 916 return 917 917 return 918 918 919 @grok.action('Cancel', validator=NullValidator) 919 920 def cancel(self, **data): 920 921 self.redirect(self.url(self.context)) 921 922 return 922 923 923 924 924 925 class FacultyAddFormPage(WAeUPAddFormPage): … … 948 949 return 949 950 self.redirect(self.url(self.context, u'@@manage')+'#tab-1') 950 951 951 952 @grok.action('Cancel') 952 953 def cancel(self, **data): … … 954 955 955 956 #class RemoveFacultyFormPage(RemoveFormPage): 956 # """ Remove Faculty Page 957 # """ Remove Faculty Page 957 958 # """ 958 959 # grok.context(IFacultyContainer) … … 974 975 def title(self): 975 976 return self.context.longtitle() 976 977 977 978 @property 978 979 def label(self): … … 984 985 # try: 985 986 # del self.context[code] 986 # self.flash('Department %s successfully removed.' % code) 987 # self.flash('Department %s successfully removed.' % code) 987 988 # except: 988 989 # self.flash('Could not delete %s.' % code) 989 990 990 991 class FacultyManageFormPage(WAeUPEditFormPage): 991 992 """Manage the basic properties of a `Faculty` instance. … … 1006 1007 def label(self): 1007 1008 return 'Manage faculty' 1008 1009 1009 1010 @property 1010 1011 def title(self): … … 1012 1013 1013 1014 def getLocalRoles(self): 1014 #import pdb; pdb.set_trace()1015 return faculty_local_roles1016 1015 roles = ILocalRolesAssignable(self.context) 1016 return roles() 1017 1017 1018 def getUsers(self): 1018 1019 """Get a list of all users. … … 1032 1033 self.applyData(self.context, **data) 1033 1034 return 1034 1035 1035 1036 # ToDo: Show warning message before deletion 1036 1037 @grok.action('Remove selected') … … 1050 1051 if len(deleted): 1051 1052 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1052 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1053 return 1053 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1054 return 1054 1055 1055 1056 @grok.action('Add department', validator=NullValidator) 1056 1057 def addDepartment(self, **data): 1057 1058 self.redirect(self.url(self.context, '@@add')) 1058 return 1059 1059 return 1060 1060 1061 @grok.action('Cancel', validator=NullValidator) 1061 1062 def cancel(self, **data): 1062 1063 self.redirect(self.url(self.context)) 1063 1064 return 1064 1065 1065 1066 @grok.action('Add local role', validator=NullValidator) 1066 1067 def addLocalRole(self, **data): … … 1088 1089 def title(self): 1089 1090 return self.context.longtitle() 1090 1091 1091 1092 @grok.action('Add department') 1092 1093 def addDepartment(self, **data): … … 1104 1105 return 1105 1106 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1106 1107 1107 1108 @grok.action('Cancel') 1108 1109 def cancel(self, **data): … … 1112 1113 1113 1114 #class RemoveDepartmentFormPage(RemoveFormPage): 1114 # """ Remove Department Page 1115 # """ Remove Department Page 1115 1116 # """ 1116 1117 # grok.context(IFaculty) … … 1134 1135 def title(self): 1135 1136 return self.context.longtitle() 1136 1137 1137 1138 def update(self): 1138 1139 tabs.need() 1139 datatable.need() 1140 datatable.need() 1140 1141 super(DepartmentPage, self).update() 1141 1142 return 1142 1143 1143 1144 def getCourses(self): 1144 1145 """Get a list of all stored courses. … … 1146 1147 for key, val in self.context.courses.items(): 1147 1148 url = self.url(val) 1148 yield(dict(url=url, name=key, container=val)) 1149 yield(dict(url=url, name=key, container=val)) 1149 1150 1150 1151 def getCertificates(self): … … 1153 1154 for key, val in self.context.certificates.items(): 1154 1155 url = self.url(val) 1155 yield(dict(url=url, name=key, container=val)) 1156 yield(dict(url=url, name=key, container=val)) 1156 1157 1157 1158 class DepartmentManageFormPage(WAeUPEditFormPage): … … 1170 1171 def label(self): 1171 1172 return 'Manage department' 1172 1173 @property 1174 def title(self): 1175 return self.context.longtitle() 1176 1173 1174 @property 1175 def title(self): 1176 return self.context.longtitle() 1177 1177 1178 def getCourses(self): 1178 1179 """Get a list of all stored courses. … … 1180 1181 for key, val in self.context.courses.items(): 1181 1182 url = self.url(val) 1182 yield(dict(url=url, name=key, container=val)) 1183 yield(dict(url=url, name=key, container=val)) 1183 1184 1184 1185 def getCertificates(self): … … 1187 1188 for key, val in self.context.certificates.items(): 1188 1189 url = self.url(val) 1189 yield(dict(url=url, name=key, container=val)) 1190 yield(dict(url=url, name=key, container=val)) 1190 1191 1191 1192 def update(self): 1192 1193 tabs.need() 1193 datatable.need() 1194 datatable.need() 1194 1195 super(DepartmentManageFormPage, self).update() 1195 1196 return … … 1201 1202 self.applyData(self.context, **data) 1202 1203 return 1203 1204 1204 1205 # ToDo: Show warning message before deletion 1205 1206 @grok.action('Remove selected courses') … … 1219 1220 if len(deleted): 1220 1221 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1221 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1222 return 1223 1224 @grok.action('Remove selected certificates') 1222 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1223 return 1224 1225 @grok.action('Remove selected certificates') 1225 1226 def delCertificates(self, **data): 1226 1227 form = self.request.form … … 1238 1239 if len(deleted): 1239 1240 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1240 self.redirect(self.url(self.context, u'@@manage')+'#tab-3') 1241 return 1241 self.redirect(self.url(self.context, u'@@manage')+'#tab-3') 1242 return 1242 1243 1243 1244 @grok.action('Add course', validator=NullValidator) 1244 1245 def addCourse(self, **data): 1245 1246 self.redirect(self.url(self.context, 'addcourse')) 1246 return 1247 1247 return 1248 1248 1249 @grok.action('Add certificate', validator=NullValidator) 1249 1250 def addCertificate(self, **data): 1250 1251 self.redirect(self.url(self.context, 'addcertificate')) 1251 return 1252 1252 return 1253 1253 1254 @grok.action('Cancel', validator=NullValidator) 1254 1255 def cancel(self, **data): … … 1265 1266 form_fields = grok.AutoFields(ICourseAdd) 1266 1267 pnav = 1 1267 1268 @property 1269 def title(self): 1270 return self.context.longtitle() 1271 1268 1269 @property 1270 def title(self): 1271 return self.context.longtitle() 1272 1272 1273 @grok.action('Add course') 1273 1274 def addCourse(self, **data): … … 1284 1285 'in the database') 1285 1286 return 1286 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1287 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1287 1288 1288 1289 @grok.action('Cancel', validator=NullValidator) … … 1300 1301 form_fields = grok.AutoFields(ICertificateAdd) 1301 1302 pnav = 1 1302 1303 @property 1304 def title(self): 1305 return self.context.longtitle() 1306 1303 1304 @property 1305 def title(self): 1306 return self.context.longtitle() 1307 1307 1308 @grok.action('Add certificate') 1308 1309 def addCertificate(self, **data): 1309 1310 certificate = createObject(u'waeup.Certificate') 1310 1311 self.applyData(certificate, **data) 1311 1312 1312 1313 #try: 1313 1314 # self.applyData(certificate, **data) … … 1317 1318 # 'available in workflow.') 1318 1319 # return 1319 1320 1320 1321 try: 1321 1322 self.context.certificates.addCertificate(certificate) … … 1328 1329 'in the database') 1329 1330 return 1330 self.redirect(self.url(self.context, u'@@manage')+'#tab-3') 1331 self.redirect(self.url(self.context, u'@@manage')+'#tab-3') 1331 1332 1332 1333 @grok.action('Cancel', validator=NullValidator) … … 1361 1362 1362 1363 form_fields = grok.AutoFields(ICourse) 1363 1364 1364 1365 @property 1365 1366 def title(self): … … 1370 1371 self.applyData(self.context, **data) 1371 1372 return 1372 1373 1373 1374 @grok.action('Save and return') 1374 1375 def saveAndReturn(self, **data): … … 1398 1399 def title(self): 1399 1400 return "Certificate: %s (%s)" % (self.context.title, self.context.code) 1400 1401 1401 1402 def update(self): 1402 1403 tabs.need() 1403 1404 #warning.need() 1404 datatable.need() 1405 datatable.need() 1405 1406 return super(CertificatePage, self).update() 1406 1407 … … 1413 1414 pnav = 1 1414 1415 label = 'Edit certificate' 1415 1416 1416 1417 form_fields = grok.AutoFields(ICertificate) 1417 1418 1418 1419 pnav = 1 1419 1420 grok.template('certificatemanagepage') … … 1424 1425 def label(self): 1425 1426 return 'Manage certificate' 1426 1427 @property 1428 def title(self): 1429 return "Certificate: %s (%s)" % (self.context.title, self.context.code) 1427 1428 @property 1429 def title(self): 1430 return "Certificate: %s (%s)" % (self.context.title, self.context.code) 1430 1431 1431 1432 def update(self): 1432 1433 tabs.need() 1433 1434 #warning.need() 1434 datatable.need() 1435 datatable.need() 1435 1436 return super(CertificateManageFormPage, self).update() 1436 1437 1437 1438 form_fields = grok.AutoFields(ICertificate) 1438 1439 … … 1441 1442 self.applyData(self.context, **data) 1442 1443 return 1443 1444 1444 1445 # ToDo: Show warning message before deletion 1445 1446 @grok.action('Remove selected course referrers') … … 1459 1460 if len(deleted): 1460 1461 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1461 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1462 return 1463 1462 self.redirect(self.url(self.context, u'@@manage')+'#tab-2') 1463 return 1464 1464 1465 1465 1466 @grok.action('Add course referrer', validator=NullValidator) 1466 1467 def addCertificateCourse(self, **data): 1467 1468 self.redirect(self.url(self.context, 'addcertificatecourse')) 1468 return 1469 1469 return 1470 1470 1471 @grok.action('Cancel', validator=NullValidator) 1471 1472 def cancel(self, **data): 1472 1473 self.redirect(self.url(self.context)) 1473 1474 return 1474 1475 1475 1476 1476 1477 class CertificateCourseAddFormPage(WAeUPAddFormPage): 1477 1478 """Add-page to add a course ref to a certificate … … 1483 1484 pnav = 1 1484 1485 label = 'Add course referrer' 1485 1486 1486 1487 @property 1487 1488 def title(self): … … 1523 1524 def title(self): 1524 1525 return 'Course Referrer: %s' % (self.context.longtitle()) 1525 1526 @property 1526 1527 @property 1527 1528 def leveltitle(self): 1528 1529 return course_levels.getTerm(self.context.level).title … … 1537 1538 label = 'Edit course referrer' 1538 1539 pnav = 1 1539 1540 1540 1541 @property 1541 1542 def title(self): 1542 1543 return 'Course Referrer: %s' % (self.context.__name__) 1543 1544 1544 1545 @grok.action('Save and return') 1545 1546 def saveAndReturn(self, **data):
Note: See TracChangeset for help on using the changeset viewer.