Changeset 12620 for main/waeup.kofa
- Timestamp:
- 16 Feb 2015, 11:27:24 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py
r10685 r12620 120 120 return 121 121 122 def moveCertificate(self, fac , dep):122 def moveCertificate(self, facname, depname, newcode): 123 123 self.moved = True 124 124 cert = self 125 del self.__parent__[cert.code] 126 grok.getSite()['faculties'][fac][dep].certificates[cert.code] = cert 127 self.__parent__._p_changed = True 125 oldcode = cert.code 126 cert.code = newcode 127 del self.__parent__[oldcode] 128 newdep = grok.getSite()['faculties'][facname][depname] 129 newdep.certificates[newcode] = cert 130 #self.__parent__._p_changed = True 128 131 cat = getUtility(ICatalog, name='students_catalog') 129 results = cat.searchResults(certcode=( cert.code, cert.code))132 results = cat.searchResults(certcode=(oldcode, oldcode)) 130 133 for student in results: 131 134 notify(grok.ObjectModifiedEvent(student)) 132 135 student.__parent__.logger.info( 133 136 '%s - Certificate moved' % student.__name__) 134 135 137 return 136 138 -
main/waeup.kofa/trunk/src/waeup/kofa/university/department.py
r12609 r12620 102 102 """ 103 103 self.moved = True 104 fac = grok.getSite()['faculties'][facname]104 newfac = grok.getSite()['faculties'][facname] 105 105 oldcode = self.code 106 fac[depname] = self 107 del self.__parent__[oldcode] 108 fac[depname].code = depname 106 oldfac = self.__parent__ 107 newfac[depname] = self 108 del oldfac[oldcode] 109 newfac[depname].code = depname 109 110 #self.__parent__._p_changed = True 110 111 cat = getUtility(ICatalog, name='students_catalog') -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_move.py
r12614 r12620 22 22 from zope.catalog.interfaces import ICatalog 23 23 from zope.component import queryUtility 24 from waeup.kofa.university.faculty import Faculty 24 25 from waeup.kofa.university.department import Department 25 26 from waeup.kofa.students.tests.test_browser import StudentsFullSetup … … 28 29 29 30 def test_move_department(self): 31 self.app['faculties']['fac2'] = Faculty(code=u'fac2') 30 32 self.assertEqual( 31 33 self.app['faculties']['fac1']['dep1'].certificates['CERT1'], … … 36 38 # We move the depart using the UtilityView 37 39 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 38 self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac 1&dep=newdep')40 self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac2&dep=newdep') 39 41 40 42 # New department is created and old department is removed 41 43 self.assertEqual( 42 [key for key in self.app['faculties']['fac 1']], ['newdep'])44 [key for key in self.app['faculties']['fac2']], ['newdep']) 43 45 44 46 # All subobjects have been moved too 45 47 self.assertEqual( 46 self.app['faculties']['fac 1']['newdep'].courses['COURSE1'],48 self.app['faculties']['fac2']['newdep'].courses['COURSE1'], 47 49 self.course) 48 50 self.assertEqual( 49 self.app['faculties']['fac 1']['newdep'].certificates['CERT1'],51 self.app['faculties']['fac2']['newdep'].certificates['CERT1'], 50 52 self.certificate) 51 53 self.assertEqual( 52 [key for key in self.app['faculties']['fac 1'][54 [key for key in self.app['faculties']['fac2'][ 53 55 'newdep'].certificates['CERT1'].keys()], 54 56 [u'COURSE1_100']) … … 67 69 assert len(results) == 1 68 70 assert results[0] is self.course 71 69 72 # We can still find the certificatecourse in the catalog 70 73 cat = queryUtility(ICatalog, name='certcourses_catalog') … … 72 75 results = [x for x in results] 73 76 assert len(results) == 1 74 assert results[0] is self.app['faculties']['fac 1'][77 assert results[0] is self.app['faculties']['fac2'][ 75 78 'newdep'].certificates['CERT1']['COURSE1_100'] 76 79 … … 91 94 self.app['datacenter'].storage, 'logs', 'main.log') 92 95 logcontent = open(logfile).read() 93 self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac 1/newdep'96 self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac2/newdep' 94 97 in logcontent) 95 98 96 99 97 100 def test_move_certificate(self): 101 self.app['faculties']['fac2'] = Faculty(code=u'fac2') 102 self.app['faculties']['fac2']['dep2'] = Department(code=u'dep2') 98 103 self.assertEqual( 99 104 self.app['faculties']['fac1']['dep1'].certificates['CERT1'], 100 105 self.certificate) 101 self.app['faculties']['fac1']['dep2'] = Department(code=u'dep2') 102 self.certificate.moveCertificate('fac1', 'dep2') 106 107 #self.certificate.moveCertificate('fac2', 'dep2', 'NEWCODE') 108 109 # We move the depart using the UtilityView 110 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 111 self.browser.open('http://localhost/app/faculties/fac1/dep1/certificates/CERT1/move_certificate?fac=fac2&dep=dep2&cert=NEWCODE') 112 103 113 self.assertEqual( 104 self.app['faculties']['fac 1']['dep2'].certificates['CERT1'],114 self.app['faculties']['fac2']['dep2'].certificates['NEWCODE'], 105 115 self.certificate) 106 116 self.assertEqual( 107 [key for key in self.app['faculties']['fac1'][ 108 'dep2'].certificates['CERT1'].keys()], 109 [u'COURSE1_100']) 117 [key for key in self.app['faculties']['fac2'][ 118 'dep2'].certificates['NEWCODE'].keys()], [u'COURSE1_100']) 110 119 self.assertEqual( 111 120 self.student['studycourse'].certificate, 112 121 self.certificate) 113 122 114 # We can still find thecertificate in the catalog123 # We can find the moved certificate in the catalog 115 124 cat = queryUtility(ICatalog, name='certificates_catalog') 116 results = cat.searchResults(code=(' CERT1','CERT1'))125 results = cat.searchResults(code=('NEWCODE','NEWCODE')) 117 126 results = [x for x in results] # Turn results generator into list 118 127 assert len(results) == 1 … … 124 133 results = [x for x in results] # Turn results generator into list 125 134 assert len(results) == 1 126 assert results[0] is self.app['faculties']['fac 1'][127 'dep2'].certificates[' CERT1']['COURSE1_100']135 assert results[0] is self.app['faculties']['fac2'][ 136 'dep2'].certificates['NEWCODE']['COURSE1_100'] 128 137 129 138 # We can find the student studying in the new department … … 133 142 assert len(results) == 1 134 143 assert results[0] is self.app['students'][self.student_id] 144 145 # We can find the student studying the new course ... 146 cat = queryUtility(ICatalog, name='students_catalog') 147 results = cat.searchResults(certcode=('NEWCODE','NEWCODE')) 148 results = [x for x in results] # Turn results generator into list 149 assert len(results) == 1 150 assert results[0] is self.app['students'][self.student_id] 151 # ... but not the old course 152 results = cat.searchResults(certcode=('CERT1','CERT1')) 153 assert len(results) == 0 154 135 155 logfile = os.path.join( 136 156 self.app['datacenter'].storage, 'logs', 'students.log') 137 157 logcontent = open(logfile).read() 138 self.assertTrue('INFO - system- K1000000 - Certificate moved'158 self.assertTrue('INFO - zope.mgr - K1000000 - Certificate moved' 139 159 in logcontent) 160 logfile = os.path.join( 161 self.app['datacenter'].storage, 'logs', 'main.log') 162 logcontent = open(logfile).read() 163 self.assertTrue('INFO - zope.mgr - Certificate CERT1 moved to fac2/dep2/NEWCODE' 164 in logcontent) -
main/waeup.kofa/trunk/src/waeup/kofa/utils/browser.py
r12610 r12620 25 25 from waeup.kofa.interfaces import IObjectHistory 26 26 from waeup.kofa.interfaces import IUniversity 27 from waeup.kofa.university.interfaces import IDepartment 27 from waeup.kofa.university.interfaces import IDepartment, ICertificate 28 28 29 29 def replaceStudentMessages(old, new): … … 227 227 self.redirect(self.url(self.context, '@@index')) 228 228 return 229 230 class MoveCertificate(UtilityView, grok.View): 231 """ View to move a certificate. 232 233 """ 234 grok.context(ICertificate) 235 grok.name('move_certificate') 236 grok.require('waeup.managePortal') 237 238 def update(self,fac=None, dep=None, cert=None): 239 if None in (fac, dep, cert): 240 self.flash('Syntax: /move_certificate?fac=[new faculty code]&dep=[new department code]&cert=[new certificate code]') 241 return 242 oldcode = self.context.code 243 try: 244 self.context.moveCertificate(fac, dep, cert) 245 except: 246 self.flash('Error') 247 return 248 grok.getSite().logger.info( 249 "Certificate %s moved to %s/%s/%s" % (oldcode, fac, dep, cert)) 250 self.flash('Finished') 251 return 252 253 def render(self): 254 self.redirect(self.url(self.context, '@@index')) 255 return
Note: See TracChangeset for help on using the changeset viewer.