Ignore:
Timestamp:
24 Aug 2015, 06:34:28 (9 years ago)
Author:
Henrik Bettermann
Message:

Add pre-fill UI components.

Take unused records first during self-registration.

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  
    9292    def containers(self):
    9393        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
    96101
    97102class ApplicantsSearchPage(KofaPage):
     
    352357    @property
    353358    def showApplicants(self):
    354         if len(self.context) < 5000:
     359        if self.context.counts[1] < 1000:
    355360            return True
    356361        return False
     
    469474        self.redirect(
    470475            self.url(self.context[applicant.application_number], 'index'))
     476        return
     477
     478class 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))
    471514        return
    472515
     
    11501193            return
    11511194        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:
    11591199                # Add applicant
    11601200                applicant = createObject(u'waeup.Applicant')
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantscontainermanagepage.pt

    r11254 r13217  
    3535    </div>
    3636    <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 />
    3739    <tal:showApplicants  condition="view/showApplicants">
    3840      <br />
     
    5355        </thead>
    5456        <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('+')]">
    5658            <td>
    5759              <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  
    5454            <th i18n:translate="">Records
    5555            </th>
     56            <th i18n:translate="">Application Deadline
     57            </th>
    5658          </tr>
    5759        </thead>
     
    6567                tal:content="entry/__name__">CODE</a> </td>
    6668            <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>
    6872          </tr>
    6973        </tbody>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py

    r13077 r13217  
    2727from zope.component.factory import Factory
    2828from zope.component.interfaces import IFactory
     29from zope.catalog.interfaces import ICatalog
    2930from waeup.kofa.interfaces import MessageFactory as _
    3031from waeup.kofa.applicants.interfaces import (
     
    6768            applicant.applicant_id = applicant_id
    6869        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]
    6989        return
    7090
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r13215 r13217  
    467467        return
    468468
     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
    469504class ApplicantUITests(ApplicantsFullSetup):
    470505    # Tests for uploading/browsing the passport image of appplicants
     
    12351270        uu_applicant = createObject('waeup.Applicant')
    12361271        self.app['applicants'][container_name_1].addApplicant(uu_applicant)
    1237         self.assertFalse(uu_applicant.record_used)
     1272        self.assertEqual(uu_applicant.container_code, container_name_1 + '-')
    12381273        self.assertEqual(len(self.app['applicants'][container_name_1]), 2)
    12391274        self.browser.open(self.container_path)
     
    12511286        # ... and the existing, formerly unused record has been used instead
    12521287        self.assertEqual(uu_applicant.lastname, 'Kurios')
    1253         self.assertTrue(uu_applicant.record_used)
     1288        self.assertEqual(uu_applicant.container_code, container_name_1 + '+')
    12541289        return
    12551290
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py

    r13108 r13217  
    116116    target = 'addapplicant'
    117117
     118class 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
    118127class ApplicantsContainerStatisticsActionButton(ManageActionButton):
    119     grok.order(2)
     128    grok.order(3)
    120129    grok.context(IApplicantsContainer)
    121130    grok.view(ApplicantsContainerManageFormPage)
     
    127136class ApplicantsContainerStatisticsActionButton2(
    128137        ApplicantsContainerStatisticsActionButton):
    129     grok.order(3)
     138    grok.order(4)
    130139    grok.view(ApplicantsContainerPage)
    131140
Note: See TracChangeset for help on using the changeset viewer.