Changeset 8665 for main/waeup.kofa/trunk


Ignore:
Timestamp:
10 Jun 2012, 08:59:49 (13 years ago)
Author:
Henrik Bettermann
Message:

Add expired property to be used in views and viewlets.

If strict_deadline is set, applicants are not allowed to open the edit form when application period has expired.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r8664 r8665  
    1919"""
    2020import os
    21 import pytz
    2221import sys
    2322import grok
     
    914913
    915914    def update(self):
    916         if self.context.locked:
     915        if self.context.locked or (
     916            self.context.__parent__.expired and
     917            self.context.__parent__.strict_deadline):
    917918            self.emit_lock_message()
    918919            return
     
    963964        if state != PAID:
    964965            self.flash(_('The form cannot be submitted. Wrong state!'))
    965             return
    966         cond1 = self.context.__parent__.strict_deadline
    967         cond2 = self.context.__parent__.enddate
    968         cond3 = self.context.__parent__.enddate < datetime.now(pytz.utc)
    969         if cond1 and (not cond2 or cond3):
    970             self.flash(
    971                 _('The form cannot be submitted. Application period has expired!'))
    972966            return
    973967        IWorkflowInfo(self.context).fireTransition('submit')
     
    10231017
    10241018    def update(self):
    1025         # Check if application has started ...
    1026         if not self.context.startdate or (
    1027             self.context.startdate > datetime.now(pytz.utc)):
    1028             self.flash(_('Application has not yet started.'))
    1029             self.redirect(self.url(self.context))
    1030             return
    1031         # ... or ended
    1032         if not self.context.enddate or (
    1033             self.context.enddate < datetime.now(pytz.utc)):
    1034             self.flash(_('Application has ended.'))
     1019        if self.context.expired:
     1020            self.flash(_('Outside application period.'))
    10351021            self.redirect(self.url(self.context))
    10361022            return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py

    r8645 r8665  
    2121from random import SystemRandom as r
    2222import grok
     23import pytz
     24from datetime import datetime
    2325from zope.component import getUtility
    2426from zope.component.factory import Factory
     
    101103        return getUtility(IApplicantsUtils).getApplicantsStatistics(self)
    102104
     105    @property
     106    def expired(self):
     107        # Check if application has started ...
     108        if not self.startdate or (
     109            self.startdate > datetime.now(pytz.utc)):
     110            return True
     111        # ... or ended
     112        if not self.enddate or (
     113            self.enddate < datetime.now(pytz.utc)):
     114            return True
     115        return False
     116
     117
    103118ApplicantsContainer = attrs_to_fields(ApplicantsContainer)
    104119
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r8664 r8665  
    773773        self.assertTrue('Final Submit' in self.browser.contents)
    774774        self.fill_correct_values() # fill other fields with correct values
     775        self.browser.getControl("Save").click()
    775776        self.browser.getControl("Final Submit").click()
    776777        # We forgot to upload a passport picture
     
    789790            in self.browser.contents)
    790791        self.browser.getControl(name="confirm_passport").value = True
     792        # If application period has expired and strict-deadline is set
     793        # applicants do notsee edit button and can't open
     794        # the edit form.
    791795        self.applicantscontainer.enddate = datetime.now(pytz.utc)
    792         self.browser.getControl("Final Submit").click()
    793         self.assertTrue(
    794             'Application period has expired' in self.browser.contents)
     796        self.browser.open(self.view_path)
     797        self.assertFalse(
     798            'Edit application record' in self.browser.contents)
     799        self.browser.open(self.edit_path)
     800        self.assertTrue(
     801            'form is locked' in self.browser.contents)
    795802        # We can either postpone the enddate ...
    796803        self.applicantscontainer.enddate = datetime.now(
    797804            pytz.utc) + timedelta(days=10)
     805        self.browser.open(self.edit_path)
    798806        self.browser.getControl(name="confirm_passport").value = True
    799807        self.browser.getControl("Final Submit").click()
     
    811819        self.browser.goBack(count=1)
    812820        self.browser.getControl("Save").click()
     821        # The form is locked.
    813822        self.assertTrue(
    814823            'The requested form is locked' in self.browser.contents)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py

    r8565 r8665  
    157157        """Get a URL to the target...
    158158        """
    159         if self.context.locked:
     159        if self.context.locked or (
     160            self.context.__parent__.expired and
     161            self.context.__parent__.strict_deadline):
    160162            return
    161163        return self.view.url(self.view.context, self.target)
Note: See TracChangeset for help on using the changeset viewer.