Changeset 13217 for main/waeup.kofa/trunk/src
- Timestamp:
- 24 Aug 2015, 06:34:28 (9 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r13215 r13217 92 92 def containers(self): 93 93 if self.layout.isAuthenticated(): 94 return self.context.values() 95 return [value for value in self.context.values() if not value.hidden] 94 values = sorted([container for container in self.context.values()], 95 key=lambda value: value.enddate) 96 return values 97 values = sorted([container for container in self.context.values() 98 if not container.hidden], 99 key=lambda value: value.enddate) 100 return values 96 101 97 102 class ApplicantsSearchPage(KofaPage): … … 352 357 @property 353 358 def showApplicants(self): 354 if len(self.context) < 5000:359 if self.context.counts[1] < 1000: 355 360 return True 356 361 return False … … 469 474 self.redirect( 470 475 self.url(self.context[applicant.application_number], 'index')) 476 return 477 478 class ApplicantsContainerPrefillFormPage(KofaAddFormPage): 479 """Add-form to pre-fill applicants containers. 480 """ 481 grok.context(IApplicantsContainer) 482 grok.require('waeup.manageApplication') 483 grok.name('prefill') 484 grok.template('prefill_container') 485 label = _('Pre-fill container') 486 pnav = 3 487 doclink = DOCLINK + '/applicants.html' 488 489 def update(self): 490 if self.context.mode == 'update': 491 self.flash(_('Container must be in create mode to be pre-filled.'), 492 type='danger') 493 self.redirect(self.url(self.context)) 494 return 495 super(ApplicantsContainerPrefillFormPage, self).update() 496 return 497 498 @action(_('Pre-fill now'), style='primary') 499 def addApplicants(self, **data): 500 form = self.request.form 501 if 'number' in form and form['number']: 502 number = int(form['number']) 503 for i in range(number): 504 applicant = createObject(u'waeup.Applicant') 505 self.context.addApplicant(applicant) 506 self.flash(_('%s application records created.' % number)) 507 self.context.writeLogMessage(self, '%s applicants created' % (number)) 508 self.redirect(self.url(self.context, 'index')) 509 return 510 511 @action(_('Cancel'), validator=NullValidator) 512 def cancel(self, **data): 513 self.redirect(self.url(self.context)) 471 514 return 472 515 … … 1150 1193 return 1151 1194 if self.context.mode == 'create': 1152 # Check if there are unused records which can be taken 1153 cat = getUtility(ICatalog, name='applicants_catalog') 1154 results = list( 1155 cat.searchResults(record_used=(False, False))) 1156 if results: 1157 applicant = results[0] 1158 else: 1195 # Check if there are unused records in this container which 1196 # can be taken 1197 applicant = self.context.first_unused 1198 if applicant is None: 1159 1199 # Add applicant 1160 1200 applicant = createObject(u'waeup.Applicant') -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantscontainermanagepage.pt
r11254 r13217 35 35 </div> 36 36 <div id="tab2" class="tab-pane"> 37 <br /> 38 This container contains <span tal:replace="python: context.counts[0]-context.counts[1]">UNUSED</span> unused pre-filled records.<br /> 37 39 <tal:showApplicants condition="view/showApplicants"> 38 40 <br /> … … 53 55 </thead> 54 56 <tbody> 55 <tr tal:repeat="appl context/values">57 <tr tal:repeat="appl python:[appl for appl in context.values() if appl.container_code.endswith('+')]"> 56 58 <td> 57 59 <input type="checkbox" name="val_id" tal:attributes="value appl/__name__" /> -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantsrootmanagepage.pt
r11254 r13217 54 54 <th i18n:translate="">Records 55 55 </th> 56 <th i18n:translate="">Application Deadline 57 </th> 56 58 </tr> 57 59 </thead> … … 65 67 tal:content="entry/__name__">CODE</a> </td> 66 68 <td tal:content="entry/title">TITLE</td> 67 <td tal:content="python:len(entry)">YEAR</td> 69 <td tal:content="python: len(entry)">RECORDS</td> 70 <td><span tal:content="python: layout.formatDatetime(entry.enddate)"> 71 END</span></td> 68 72 </tr> 69 73 </tbody> -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py
r13077 r13217 27 27 from zope.component.factory import Factory 28 28 from zope.component.interfaces import IFactory 29 from zope.catalog.interfaces import ICatalog 29 30 from waeup.kofa.interfaces import MessageFactory as _ 30 31 from waeup.kofa.applicants.interfaces import ( … … 67 68 applicant.applicant_id = applicant_id 68 69 self[applicant.application_number] = applicant 70 return 71 72 @property 73 def counts(self): 74 total = len(self) 75 code = self.code + '+' 76 cat = getUtility(ICatalog, name='applicants_catalog') 77 results = list( 78 cat.searchResults(container_code=(code, code))) 79 return len(self), len(results) 80 81 @property 82 def first_unused(self): 83 code = self.code + '-' 84 cat = getUtility(ICatalog, name='applicants_catalog') 85 results = list( 86 cat.searchResults(container_code=(code, code))) 87 if results: 88 return results[0] 69 89 return 70 90 -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r13215 r13217 467 467 return 468 468 469 def test_prefill_container(self): 470 # Managers can pre-fill containers in create mode 471 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 472 self.prefill_path = self.container_path + '/prefill' 473 self.container_manage_path = self.container_path + '/@@manage' 474 self.browser.open(self.container_manage_path) 475 self.browser.getLink("Pre-fill").click() 476 self.assertEqual(self.browser.headers['Status'], '200 Ok') 477 self.assertEqual(self.browser.url, self.prefill_path) 478 self.browser.getControl(name="number").value = ['10'] 479 self.browser.getControl("Pre-fill").click() 480 self.assertTrue('10 application records created.' in self.browser.contents) 481 self.browser.open(self.container_manage_path) 482 self.assertTrue('This container contains 10 unused pre-filled records.' 483 in self.browser.contents) 484 self.assertEqual(self.applicantscontainer.counts[0], 11) 485 self.assertEqual(self.applicantscontainer.counts[1], 1) 486 # In update mode we can't pre-fill the container 487 self.applicantscontainer.mode = 'update' 488 self.browser.open(self.container_manage_path) 489 self.browser.getLink("Pre-fill").click() 490 self.assertTrue('Container must be in create mode to be pre-filled.' 491 in self.browser.contents) 492 self.browser.open(self.manage_root_path) 493 # Number of total records is 11 494 self.assertTrue('<td>11</td>' in self.browser.contents) 495 # The statistics have not changed 496 self.browser.open(self.container_path) 497 self.browser.getLink("Container statistics").click() 498 self.assertTrue('<td>1</td>' in self.browser.contents) 499 self.assertEqual(self.applicantscontainer.statistics[0], 500 {'not admitted': 0, 'started': 0, 'created': 0, 501 'admitted': 0, 'submitted': 0, 'initialized': 1, 'paid': 0}) 502 return 503 469 504 class ApplicantUITests(ApplicantsFullSetup): 470 505 # Tests for uploading/browsing the passport image of appplicants … … 1235 1270 uu_applicant = createObject('waeup.Applicant') 1236 1271 self.app['applicants'][container_name_1].addApplicant(uu_applicant) 1237 self.assert False(uu_applicant.record_used)1272 self.assertEqual(uu_applicant.container_code, container_name_1 + '-') 1238 1273 self.assertEqual(len(self.app['applicants'][container_name_1]), 2) 1239 1274 self.browser.open(self.container_path) … … 1251 1286 # ... and the existing, formerly unused record has been used instead 1252 1287 self.assertEqual(uu_applicant.lastname, 'Kurios') 1253 self.assert True(uu_applicant.record_used)1288 self.assertEqual(uu_applicant.container_code, container_name_1 + '+') 1254 1289 return 1255 1290 -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py
r13108 r13217 116 116 target = 'addapplicant' 117 117 118 class ApplicantsContainerPrefillActionButton(AddActionButton): 119 grok.order(2) 120 grok.context(IApplicantsContainer) 121 grok.view(ApplicantsContainerManageFormPage) 122 grok.require('waeup.manageApplication') 123 icon = 'actionicon_bucketfill.png' 124 text = _('Pre-fill container') 125 target = 'prefill' 126 118 127 class ApplicantsContainerStatisticsActionButton(ManageActionButton): 119 grok.order( 2)128 grok.order(3) 120 129 grok.context(IApplicantsContainer) 121 130 grok.view(ApplicantsContainerManageFormPage) … … 127 136 class ApplicantsContainerStatisticsActionButton2( 128 137 ApplicantsContainerStatisticsActionButton): 129 grok.order( 3)138 grok.order(4) 130 139 grok.view(ApplicantsContainerPage) 131 140
Note: See TracChangeset for help on using the changeset viewer.