Changeset 13959


Ignore:
Timestamp:
21 Jun 2016, 04:46:56 (8 years ago)
Author:
Henrik Bettermann
Message:

Count mandates on configuration page and provide 'Purge' button.

Location:
main/waeup.kofa/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r13950 r13959  
    441.4.2.dev0 (unreleased)
    55=======================
     6
     7* Count mandates on configuration page and provide 'Purge' button.
    68
    79* Start `ApplicantExporter` and `ApplicantPaymentExporter` at the same
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r13908 r13959  
    10491049    pnav = 0
    10501050    label = _(u'Edit portal configuration')
    1051     taboneactions = [_('Save'), _('Update plugins')]
     1051    taboneactions = [_('Save'), _('Update plugins'), _('Purge mandates')]
    10521052    tabtwoactions = [
    10531053        _('Add session configuration'),
     
    11001100        grok.getSite().updatePlugins()
    11011101        self.flash(_('Plugins were updated. See log file for details.'))
     1102        return
     1103
     1104    @action(_('Purge mandates'),
     1105              tooltip=_('For experts only!'),
     1106              validator=NullValidator)
     1107    def purgeMandates(self, **data):
     1108        num = grok.getSite()['mandates'].removeExpired()
     1109        self.flash(_('${a} mandate(s) were purged.', mapping = {'a': num}))
    11021110        return
    11031111
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/configurationmanagepage.pt

    r13394 r13959  
    1616        <tbody>
    1717          <tal:widgets content="structure provider:widgets" />
     18          <tr>
     19            <td>Mandates:</td>
     20            <td>
     21              <span tal:content="python:layout.site['mandates'].count[0]"></span>
     22              <span i18n:translate="">active</span>,
     23              <span tal:content="python:layout.site['mandates'].count[0]"></span>
     24              <span i18n:translate="">expired</span>,
     25              <span tal:content="python:layout.site['mandates'].count[0]"></span>
     26              <span i18n:translate="">total</span>
     27            </td>
     28          </tr>
    1829        </tbody>
    1930      </table>
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/container.py

    r11946 r13959  
    3030    grok.implements(IMandatesContainer)
    3131    grok.provides(IMandatesContainer)
     32
     33    @property
     34    def count(self):
     35        """Count active and expired mandates.
     36        """
     37        now = datetime.utcnow()
     38        total = len(self)
     39        expired = len([i for i in self.values() if i.expires < now])
     40        active = total - expired
     41        return active, expired, total
    3242
    3343    def addMandate(self, mandate):
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/interfaces.py

    r8910 r13959  
    2525    """
    2626
     27    count = Attribute('Count active and expired mandates.')
     28
    2729    def addMandate(mandate):
    2830        """Add mandate.
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py

    r11681 r13959  
    153153        self.app['mandates'].addMandate(mandate2)
    154154        self.assertEqual(len(self.app['mandates'].keys()), 2)
     155        self.assertEqual(self.app['mandates'].count, (1, 1, 2))
    155156        num_deleted = self.app['mandates'].removeExpired()
    156157        self.assertEqual(num_deleted, 1)
     
    158159        self.assertEqual(len(self.app['mandates'].keys()), 1)
    159160        self.assertEqual([i for i in self.app['mandates'].keys()], [u'23456'])
     161
     162    def test_purge_mandates(self):
     163        # mandate1 is an old mandate which just expired.
     164        mandate1 = PasswordMandate(days=0)
     165        self.app['mandates'].addMandate(mandate1)
     166        # mandate2 is a new mandate with default time delta.
     167        mandate2 = PasswordMandate(mandate_id='23456')
     168        self.app['mandates'].addMandate(mandate2)
     169        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     170        self.browser.open('http://localhost/app/configuration')
     171        self.assertEqual(self.app['mandates'].count, (1, 1, 2))
     172        self.assertTrue('<span>expired</span>' in self.browser.contents)
     173        self.browser.getControl("Purge mandates").click()
     174        self.assertTrue('1 mandate(s) were purged' in self.browser.contents)
     175        self.assertEqual(self.app['mandates'].count, (1, 0, 1))
     176        return
    160177
    161178    def test_browser(self):
Note: See TracChangeset for help on using the changeset viewer.