Ignore:
Timestamp:
11 Mar 2011, 10:45:19 (14 years ago)
Author:
uli
Message:

Add views to manage applicants containers. These views/forms (we have
to get rid of one of these soon) make use of datepicker JS code.

File:
1 edited

Legend:

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

    r5832 r5837  
    2424import grok
    2525
     26from datetime import datetime
     27from hurry.jquery import jquery
     28from hurry.jqueryui import jqueryui
    2629from zope.component import getUtility, getAllUtilitiesRegisteredFor
    2730from zope.formlib.widgets import FileWidget
     
    3134from waeup.sirp.browser.pages import LoginPage
    3235from waeup.sirp.interfaces import IWAeUPObject
     36from waeup.sirp.browser.resources import datepicker
    3337from waeup.sirp.browser.viewlets import (
    3438    AddActionButton, ManageActionButton, PrimaryNavTab,
     
    204208    grok.name('index')
    205209
    206     title = 'Applicants Container'
    207     label = 'Applicants Container'
     210    @property
     211    def title(self):
     212        return "Applicants Container: %s" % getattr(
     213            self.context, '__name__', 'unnamed')
     214
     215    @property
     216    def label(self):
     217        return self.title
    208218    pnav = 2
    209219
     
    214224
    215225class ApplicantsContainerEditPage(WAeUPPage):
     226    """Manage/edit a container for regular applicants.
     227    """
    216228    grok.context(IApplicantsContainer)
    217229    grok.name('manage')
    218230
    219     title = 'Manage Applicants Container'
    220     label = 'Manage Applicants Container'
    221     pnav = 2
    222 
    223 
     231    @property
     232    def title(self):
     233        return "Manage applicants container: %s" % getattr(
     234            self.context, '__name__', 'unnamed')
     235   
     236    @property
     237    def label(self):
     238        return self.title
     239
     240    pnav = 2
     241
     242    def update(self, CANCEL=None, SAVE=None,
     243               title=None, description=None, startdate=None, enddate=None):
     244        datepicker.need()
     245
     246        if CANCEL is not None:
     247            self.redirect(self.url(self.context))
     248            return
     249        if SAVE is None:
     250            return
     251        self.context.title = title
     252        self.context.description = description
     253        try:
     254            self.context.startdate = datetime.strptime(startdate, '%Y-%m-%d')
     255        except ValueError:
     256            pass
     257        try:
     258            self.context.enddate = datetime.strptime(enddate, '%Y-%m-%d')
     259        except ValueError:
     260            pass
     261        self.flash('Data saved.')
     262        return
     263
     264    def getFormattedDates(self):
     265        """Returns a dict with formatted start- and enddate.
     266
     267        Returns dates of form ``YYYY-MM-DD`` based on the start and
     268        enddates of the context container. The result dict has
     269        format::
     270
     271          { 'start': '<YYYY-MM-DD>',
     272            'end': '<YYYY-MM-DD>'}
     273
     274        Each value can also be ``''`` (empty string) if unset.
     275        """
     276        start = ''
     277        if self.context.startdate is not None:
     278            start = datetime.strftime(self.context.startdate, '%Y-%m-%d')
     279        end = ''
     280        if self.context.enddate is not None:
     281            end = datetime.strftime(self.context.enddate, '%Y-%m-%d')
     282        return {'start' : start, 'end' : end }
     283
     284
     285class ManageApplicantsContainer(WAeUPEditFormPage):
     286    grok.context(IApplicantsContainer)
     287    grok.name('edit')
     288    form_fields = grok.AutoFields(IApplicantsContainer)
     289    label = 'Edit container'
     290    title = label
     291    pnav = 2
     292
     293    def update(self):
     294        datepicker.need()
     295        return super(ManageApplicantsContainer, self).update()
     296
     297    @grok.action('Apply')
     298    def apply(self, **data):
     299        self.applyData(self.context, **data)
     300        self.flash('Data saved.')
     301        return
     302       
     303    @grok.action('Back')
     304    def cancel(self, **data):
     305        self.redirect(self.url(self.context))
     306        return
     307   
    224308#class AddApplicant(WAeUPAddFormPage):
    225309#    grok.context(IApplicantContainer)
Note: See TracChangeset for help on using the changeset viewer.