- Timestamp:
- 6 Sep 2012, 16:50:17 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/accesscodes/browser.py
r8387 r9166 23 23 from hurry.workflow.interfaces import InvalidTransitionError 24 24 from waeup.kofa.browser.resources import datatable 25 from waeup.kofa.browser import KofaPage, KofaAddFormPage, NullValidator25 from waeup.kofa.browser.layout import KofaPage, KofaAddFormPage, NullValidator 26 26 from waeup.kofa.browser.breadcrumbs import Breadcrumb 27 27 from waeup.kofa.browser.viewlets import ( -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/applicants/browser.py
r8742 r9166 38 38 INITIALIZED, STARTED, PAID, SUBMITTED, ADMITTED) 39 39 from waeup.kofa.browser import ( 40 KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage,40 # KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, 41 41 DEFAULT_PASSPORT_IMAGE_PATH) 42 from waeup.kofa.browser.layout import ( 43 KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage) 42 44 from waeup.kofa.browser.interfaces import ICaptchaManager 43 45 from waeup.kofa.browser.breadcrumbs import Breadcrumb -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/__init__.py
r7819 r9166 1 1 import os 2 2 3 from waeup.kofa.browser.layout import (4 KofaPage, KofaForm, KofaLayout, KofaDisplayFormPage, KofaEditFormPage,5 KofaAddFormPage, NullValidator)6 from waeup.kofa.browser.pages import ContactAdminForm3 #from waeup.kofa.browser.layout import ( 4 # KofaPage, KofaForm, KofaLayout, KofaDisplayFormPage, KofaEditFormPage, 5 # KofaAddFormPage, NullValidator) 6 #from waeup.kofa.browser.pages import ContactAdminForm 7 7 8 8 IMAGE_PATH = os.path.join( -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/breadcrumbs.py
r7819 r9166 26 26 IConfigurationContainer, ISessionConfiguration) 27 27 from waeup.kofa.interfaces import MessageFactory as _ 28 from waeup.kofa.browser import interfaces 29 from waeup.kofa.browser.interfaces import (IBreadcrumb, 30 IBreadcrumbIgnorable, IBreadcrumbContainer) 28 from waeup.kofa.browser.interfaces import ( 29 IBreadcrumb, IBreadcrumbIgnorable, IBreadcrumbContainer, IKofaObject, 30 IUniversity, IFacultiesContainer, IUsersContainer, IDataCenter, IFaculty, 31 IDepartment, ICourse, ICertificate, ICoursesContainer, ICertificateCourse, 32 ICertificatesContainer, 33 ) 31 34 32 35 class Breadcrumb(grok.Adapter): … … 34 37 """ 35 38 grok.provides(IBreadcrumb) 36 grok.context( interfaces.IKofaObject)39 grok.context(IKofaObject) 37 40 grok.name('index') 38 41 … … 87 90 """A breadcrumb for university index pages. 88 91 """ 89 grok.context( interfaces.IUniversity)92 grok.context(IUniversity) 90 93 title = _(u'Home') 91 94 parent = None … … 100 103 itself is bound to. 101 104 """ 102 grok.context( interfaces.IUniversity)105 grok.context(IUniversity) 103 106 grok.name('manage') 104 107 title = _(u'Portal Settings') … … 113 116 """A breadcrumb for faculty containers. 114 117 """ 115 grok.context( interfaces.IFacultiesContainer)118 grok.context(IFacultiesContainer) 116 119 title = _(u'Academics') 117 120 … … 119 122 """A breadcrumb for administration areas of University instances. 120 123 """ 121 grok.context( interfaces.IUniversity)124 grok.context(IUniversity) 122 125 grok.name('administration') 123 126 title = _(u'Administration') … … 145 148 """A breadcrumb for user containers. 146 149 """ 147 grok.context( interfaces.IUsersContainer)150 grok.context(IUsersContainer) 148 151 title = _(u'Portal Users') 149 152 parent_viewname = 'administration' … … 152 155 """A breadcrumb for data centers. 153 156 """ 154 grok.context( interfaces.IDataCenter)157 grok.context(IDataCenter) 155 158 title = _(u'Data Center') 156 159 parent_viewname = 'administration' … … 159 162 """A breadcrumb for faculties. 160 163 """ 161 grok.context( interfaces.IFaculty)164 grok.context(IFaculty) 162 165 163 166 @property … … 168 171 """A breadcrumb for departments. 169 172 """ 170 grok.context( interfaces.IDepartment)173 grok.context(IDepartment) 171 174 172 175 class CourseBreadcrumb(FacultyBreadcrumb): 173 176 """A breadcrumb for courses. 174 177 """ 175 grok.context( interfaces.ICourse)178 grok.context(ICourse) 176 179 177 180 class CertificateBreadcrumb(FacultyBreadcrumb): 178 181 """A breadcrumb for certificates. 179 182 """ 180 grok.context( interfaces.ICertificate)183 grok.context(ICertificate) 181 184 182 185 class CoursesContainerBreadcrumb(Breadcrumb): 183 186 """ We don't want course container breadcrumbs. 184 187 """ 185 grok.context( interfaces.ICoursesContainer)188 grok.context(ICoursesContainer) 186 189 grok.implements(IBreadcrumbIgnorable) 187 190 … … 189 192 """ We don't want course container breadcrumbs. 190 193 """ 191 grok.context( interfaces.ICertificatesContainer)194 grok.context(ICertificatesContainer) 192 195 grok.implements(IBreadcrumbIgnorable) 193 196 … … 195 198 """ We don't want course container breadcrumbs. 196 199 """ 197 grok.context( interfaces.ICertificateCourse)200 grok.context(ICertificateCourse) 198 201 @property 199 202 def title(self): -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/captcha.py
r8127 r9166 28 28 from zope.interface import Interface 29 29 from zope.publisher.interfaces.http import IHTTPRequest 30 from waeup.kofa.browser import KofaPage, resources 30 from waeup.kofa.browser import resources 31 from waeup.kofa.browser.layout import KofaPage 31 32 from waeup.kofa.browser.interfaces import ( 32 33 ICaptchaRequest, ICaptchaResponse, ICaptcha, ICaptchaConfig, -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/pages.py
r9003 r9166 39 39 IPrincipalRoleManager, IPrincipalRoleMap) 40 40 from zope.session.interfaces import ISession 41 from waeup.kofa.browser import (41 from waeup.kofa.browser.layout import ( 42 42 KofaPage, KofaForm, KofaEditFormPage, KofaAddFormPage, 43 43 KofaDisplayFormPage, NullValidator) … … 48 48 ICaptchaManager, IChangePassword) 49 49 from waeup.kofa.browser.layout import jsaction, action, UtilityView 50 from waeup.kofa.browser.resources import warning, datepicker, tabs, datatable 50 from waeup.kofa.browser.resources import ( 51 warning, datepicker, tabs, datatable, page_reloader, page_not_reloader) 51 52 from waeup.kofa.interfaces import MessageFactory as _ 52 53 from waeup.kofa.interfaces import( … … 54 55 IKofaXMLImporter, IKofaXMLExporter, IBatchProcessor, 55 56 ILocalRolesAssignable, DuplicationError, IConfigurationContainer, 56 ISessionConfiguration, ISessionConfigurationAdd, 57 ISessionConfiguration, ISessionConfigurationAdd, IJobManager, 57 58 IPasswordValidator, IContactForm, IKofaUtils, ICSVExporter,) 58 59 from waeup.kofa.permissions import ( 59 60 get_users_with_local_roles, get_all_roles, get_all_users) 61 60 62 from waeup.kofa.students.catalog import search as searchstudents 61 63 from waeup.kofa.university.catalog import search … … 1330 1332 label = _('Download portal data as CSV file') 1331 1333 pnav = 0 1332 export_button = _(u'Download') 1334 export_button = _(u'Create CSV file') 1335 _running_exports = None 1333 1336 1334 1337 def getExporters(self): … … 1338 1341 return sorted(title_name_tuples) 1339 1342 1340 def update(self, export=None, exporter=None): 1341 if None in (export, exporter): 1342 return 1343 self.redirect( 1344 self.url(self.context, 'export.csv') + '?exporter=%s' % exporter) 1343 def job_finished(self, status): 1344 return status == 'completed' 1345 1346 def getRunningExports(self): 1347 """Returns running exports as list of tuples. 1348 1349 Only exports triggered by the current user (identified by 1350 principal.id) are returned. 1351 1352 Each tuple has the form (<STATUS>, <STATUS_TITLE>, <EXPORTER_NAME>). 1353 1354 ``STATUS``: 1355 the status as machine readable string (something like 1356 ``'completed'``) 1357 1358 ``STATUS_TITLE``: 1359 status of export as translated string. 1360 1361 ``EXPORTER_NAME``: 1362 string representing the exporter title used when triggering 1363 the export job. 1364 1365 Calling this method also installs a JavaScript page reloader 1366 that reloads the page after some time (1.5 secs), if there is 1367 a running export that is not completed yet. 1368 1369 The method caches results. 1370 """ 1371 if self._running_exports is None: 1372 self._running_exports = self._getRunningExports() 1373 return self._running_exports 1374 1375 def _getRunningExports(self): 1376 result = self.context.get_export_jobs_status(self.user_id) 1377 uncompleted = [x for x in result if x[0] != 'completed'] 1378 #if len(uncompleted): 1379 # page_reloader.need() 1380 #else: 1381 # page_not_reloader.need() 1382 return result 1383 1384 def update(self, export=None, start_export=None, exporter=None, 1385 discard=None, download=None): 1386 self.user_id = self.request.principal.id 1387 if discard: 1388 myjobs = self.context.get_running_export_jobs(self.user_id) 1389 for entry in myjobs: 1390 self.context.delete_export_entry(entry) 1391 self.flash(_('Discarded export result')) 1392 return 1393 if download: 1394 myjobs = self.context.get_running_export_jobs(self.user_id) 1395 if not len(myjobs): 1396 self.flash(_('This export was already discarded.')) 1397 return 1398 job_id = myjobs[0][0] 1399 self.redirect( 1400 self.url(self.context, 'export.csv') + '?job_id=%s' % job_id) 1401 return 1402 if None in (start_export, exporter): 1403 return 1404 job_id = self.context.start_export_job( 1405 exporter, self.request.principal.id) 1406 self.redirect(self.url(self.context, 'export')) 1345 1407 return 1346 1408 … … 1350 1412 grok.require('waeup.manageDataCenter') 1351 1413 1352 def render(self, exporter=None): 1353 if exporter is None: 1354 return 1355 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 1356 self.context.logger.info( 1357 '%s - exported: %s' % (ob_class, exporter)) 1358 exporter = getUtility(ICSVExporter, name=exporter) 1359 csv_data = exporter.export_all(grok.getSite()) 1360 #csv_data.seek(0) 1414 def render(self, exporter=None, job_id=None): 1415 1416 manager = getUtility(IJobManager) 1417 job = manager.get(job_id) 1418 if job is None: 1419 return 1420 if hasattr(job.result, 'traceback'): 1421 # XXX: Some error happened. Do something more approriate here... 1422 return 1423 path = job.result 1424 if not os.path.exists(path): 1425 # XXX: Do something more appropriate here... 1426 return 1427 result = open(path, 'rb').read() 1361 1428 self.response.setHeader( 1362 1429 'Content-Type', 'text/csv; charset=UTF-8') 1363 return csv_data 1430 # remove job and running_exports entry from context 1431 self.context.delete_export_entry( 1432 self.context.entry_from_job_id(job_id)) 1433 return result 1364 1434 1365 1435 class ExportXMLPage(grok.View): -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/resources.py
r8126 r9166 302 302 waeup_kofa, 'recaptcha_white.js' 303 303 ) 304 305 #: A page reloader (reloads after 3 secs) 306 page_reloader = ResourceInclusion( 307 waeup_kofa, 'page_reloader.js', depends=[jquery]) 308 309 #: Disables page reloader (which is triggered by a JavaScript timer). 310 page_not_reloader = ResourceInclusion( 311 waeup_kofa, 'page_not_reloader.js', depends=[jquery]) 312 313 loadbar = ResourceInclusion( 314 waeup_kofa, 'loadbar.js', depends=[jquery]) -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/templates/datacenterexportpage.pt
r9110 r9166 10 10 </p> 11 11 <p i18n:translate=""> 12 The file will be generated and then be made available for you to 13 download. 12 The file will be generated and then be made available for you 13 to download. You must download or discard any existing export 14 file before creating a new one. 14 15 </p> 15 16 </div> … … 48 49 </div> 49 50 </div> 51 52 <div> 53 <tal:loading_bar content="structure provider:loadingbar" /> 54 </div> 50 55 </div> 51 56 -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/tests/test_browser.py
r8755 r9166 26 26 import os 27 27 import grok 28 from zc.async.testing import wait_for_result 28 29 from zope.event import notify 29 from zope.component import createObject, queryUtility 30 from zope.component import createObject, queryUtility, getUtility 30 31 from zope.component.hooks import setSite, clearSite 31 32 from zope.catalog.interfaces import ICatalog … … 36 37 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 37 38 from waeup.kofa.app import University 39 from waeup.kofa.interfaces import IJobManager 40 from waeup.kofa.tests.test_async import FunctionalAsyncTestCase 38 41 from waeup.kofa.university.faculty import Faculty 39 42 from waeup.kofa.university.department import Department 43 44 45 40 46 41 47 SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'test_file.csv') … … 106 112 shutil.rmtree(self.dc_root) 107 113 108 109 114 class DataCenterUITests(UniversitySetup): 110 115 # Tests for DataCenter class views and pages … … 149 154 return 150 155 151 def test_export(self): 156 157 class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase): 158 # Tests for DataCenter class views and pages 159 160 layer = FunctionalLayer 161 162 def wait_for_export_job_completed(self): 163 # helper function waiting until the current export job is completed 164 manager = getUtility(IJobManager) 165 job_id = self.app['datacenter'].running_exports[0][0] 166 job = manager.get(job_id) 167 wait_for_result(job) 168 return job_id 169 170 def stored_in_datacenter(self, job_id): 171 # tell whether job_id is stored in datacenter's running jobs list 172 for entry in list(self.app['datacenter'].running_exports): 173 if entry[0] == job_id: 174 return True 175 return False 176 177 def test_export_start(self): 178 # we can trigger export file creation 152 179 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 153 180 self.browser.open(self.datacenter_path) … … 156 183 self.browser.getLink("Export CSV file").click() 157 184 self.browser.getControl(name="exporter").value = ['faculties'] 185 self.browser.getControl("Create CSV file").click() 186 self.assertEqual(self.browser.headers['Status'], '200 Ok') 187 return 188 189 def test_export_download(self): 190 # we can download a generated export result 191 self.test_export_start() 192 # while the export file is created, we get a reload button 193 # (or a loading bar if javascript is enabled)... 194 self.browser.getControl("Reload").click() 195 # ...which is displayed as long as the job is not finished. 196 # When the job is finished and we reload the page... 197 job_id = self.wait_for_export_job_completed() 198 try: 199 self.browser.getControl("Reload").click() 200 except LookupError: 201 # if the job completed very fast, we will get the download 202 # link immediately 203 pass 204 # ...we can download the result 158 205 self.browser.getControl("Download").click() 159 self.assertEqual(self.browser.headers['Status'], '200 Ok')160 206 self.assertEqual(self.browser.headers['Content-Type'], 161 207 'text/csv; charset=UTF-8') 162 208 self.assertEqual(self.browser.contents, 163 209 'code,title,title_prefix\r\nfac1,Unnamed Faculty,faculty\r\n') 164 logfile = os.path.join( 165 self.app['datacenter'].storage, 'logs', 'datacenter.log') 166 logcontent = open(logfile).read() 167 self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 168 'exported: faculties' in logcontent) 169 return 210 211 # after download, the job and the result file are removed 212 manager = getUtility(IJobManager) 213 result = manager.get(job_id) 214 self.assertEqual(result, None) 215 self.assertEqual(self.stored_in_datacenter(job_id), False) 216 #logfile = os.path.join( 217 # self.app['datacenter'].storage, 'logs', 'datacenter.log') 218 #logcontent = open(logfile).read() 219 #self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 220 # 'exported: faculties' in logcontent) 221 return 222 223 def test_export_discard(self): 224 # we can discard a generated export result 225 self.test_export_start() 226 self.wait_for_export_job_completed() 227 self.browser.open(self.datacenter_path + '/@@export') 228 self.browser.getControl("Discard").click() 229 self.assertTrue('Discarded export result' in self.browser.contents) 230 return -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/hostels/browser.py
r8685 r9166 22 22 from zope.i18n import translate 23 23 from zope.component import getUtility 24 from waeup.kofa.browser import (24 from waeup.kofa.browser.layout import ( 25 25 KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, 26 26 NullValidator) -
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/browser.py
r8780 r9166 33 33 invalidate_accesscode, get_access_code) 34 34 from waeup.kofa.accesscodes.workflow import USED 35 from waeup.kofa.browser import (35 from waeup.kofa.browser.layout import ( 36 36 KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, 37 ContactAdminForm, KofaForm, NullValidator) 37 KofaForm, NullValidator) 38 from waeup.kofa.browser.pages import ContactAdminForm 38 39 from waeup.kofa.browser.breadcrumbs import Breadcrumb 39 40 from waeup.kofa.browser.resources import datepicker, datatable, tabs, warning
Note: See TracChangeset for help on using the changeset viewer.