Changeset 5822


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

Reenable ApplicantsRoot? index page and add page/viewlet for adding
applicant containers.

File:
1 edited

Legend:

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

    r5806 r5822  
    2424import grok
    2525
     26from zope.component import getUtility, getAllUtilitiesRegisteredFor
    2627from zope.formlib.widgets import FileWidget
    2728from waeup.sirp.browser import (
     
    3031from waeup.sirp.browser.pages import LoginPage
    3132from waeup.sirp.interfaces import IWAeUPObject
     33from waeup.sirp.browser.viewlets import AddActionButton
    3234from waeup.sirp.applicants import get_applicant_data, ResultEntry
    3335from waeup.sirp.applicants.interfaces import (
    34     IApplicant, IApplicantPrincipal, IApplicantPDEEditData)
     36    IApplicant, IApplicantPrincipal, IApplicantPDEEditData,
     37    IApplicantsRoot, IApplicantsContainer, IApplicantContainerProvider,
     38    )
    3539from waeup.sirp.widgets.passportwidget import (
    3640    PassportWidget, PassportDisplayWidget
     
    6266    MultiListDisplayWidget, subwidget=results_display_widget)
    6367
    64 #class ApplicationsPage(WAeUPPage):
    65 #    grok.context(IApplicantContainer)
    66 #    grok.name('index')
    67 #    title = 'Applications'
    68 #    pnav = 1
    69 #   
    70 #    def getApplications(self):
    71 #        """Get a list of all stored applications.
    72 #        """
    73 #        for key, val in self.context.items():
    74 #            url = self.url(val)
    75 #            yield(dict(url=url, name=key))
     68class ApplicationsPage(WAeUPPage):
     69    grok.context(IApplicantsRoot)
     70    grok.name('index')
     71    title = 'Applicants'
     72    pnav = 1
     73   
     74    def getApplications(self):
     75        """Get a list of all stored applicant containers.
     76        """
     77        for key, val in self.context.items():
     78            url = self.url(val)
     79            yield(dict(url=url, name=key))
    7680
     81class AddApplicantsContainerActionButton(AddActionButton):
     82    grok.context(IApplicantsRoot)
     83    grok.view(ApplicationsPage)
     84    text = 'Add applicants container'
     85
     86class AddApplicantsContainer(WAeUPPage):
     87    grok.context(IApplicantsRoot)
     88    grok.name('add')
     89    grok.template('addcontainer')
     90    title = 'Add applicants container'
     91    pnav = 1
     92
     93    def update(self, providername=None, name=None, ADD=None, CANCEL=None):
     94        if CANCEL is not None:
     95            self.redirect(self.url(self.context))
     96            return
     97        if ADD is None:
     98            return
     99        if not name:
     100            self.flash('Error: you must give a name')
     101            return
     102        if name in self.context.keys():
     103            self.flash('A container of the given name already exists')
     104            return
     105        # Add new applicants container...
     106        provider = getUtility(IApplicantContainerProvider,
     107                              name=providername)
     108        container = provider.factory()
     109        self.context[name] = container
     110        self.flash('Added "%s".' % name)
     111        self.redirect(self.url(self.context))
     112        return
     113       
     114    def getContainerProviders(self):
     115
     116        providers = getAllUtilitiesRegisteredFor(IApplicantContainerProvider)
     117        result = [
     118            {'name': getattr(x, 'grokcore.component.directive.name'),
     119             'provider': x}
     120             for x in providers
     121            ]
     122        return result
     123       
    77124#class AddApplicant(WAeUPAddFormPage):
    78125#    grok.context(IApplicantContainer)
Note: See TracChangeset for help on using the changeset viewer.