Changeset 6069


Ignore:
Timestamp:
13 May 2011, 15:25:22 (14 years ago)
Author:
Henrik Bettermann
Message:

Rename ApplicantsRootEditPage? to ApplicantsRootManageFormPage?.
Rename AddApplicantsContainer? to ApplicantsContainerAddFormPage?.
Change from base class WAeUPPage to WAeUPEditFormPage and WAeUPAddFormPage respectively.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/applicants
Files:
1 added
1 deleted
7 edited

Legend:

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

    r6067 r6069  
    2727from hurry.jquery import jquery
    2828from hurry.jqueryui import jqueryui
    29 from zope.component import getUtility, getAllUtilitiesRegisteredFor
     29from zope.component import getUtility, getAllUtilitiesRegisteredFor, createObject
    3030from zope.formlib.widgets import FileWidget, DateWidget
    3131from zope.securitypolicy.interfaces import IPrincipalRoleManager
     
    4444    IApplicant, IApplicantPrincipal, IApplicantPDEEditData,
    4545    IApplicantsRoot, IApplicantsContainer, IApplicantsContainerProvider,
     46    IApplicantsContainerAdd
    4647    )
    4748from waeup.sirp.widgets.passportwidget import (
     
    8485    grok.name('index')
    8586    title = 'Applicants'
     87    label = 'Application Section'
    8688    pnav = 3
    8789
     
    101103    grok.context(IApplicantsRoot)
    102104    grok.view(ApplicantsRootPage)
    103     text = 'Manage applicant containers'
    104 
    105 class ApplicantsRootEditPage(WAeUPPage):
     105    grok.require('waeup.manageUniversity')
     106    text = 'Manage application section'
     107
     108class ApplicantsRootManageFormPage(WAeUPEditFormPage):
    106109    grok.context(IApplicantsRoot)
    107110    grok.name('manage')
    108111    grok.template('applicantsrooteditpage')
    109     title = 'Edit applicants containers'
    110     pnav = 3
    111 
    112     def update(self, entries=None, DELETE=None, CANCEL=None):
    113         if CANCEL is not None:
    114             self.redirect(self.url(self.context))
    115             return
    116         if DELETE is None:
    117             return
    118         if entries is None:
    119             return
    120         if not isinstance(entries, list):
    121             entries = [entries]
    122         for name in entries:
    123             del self.context[name]
    124             self.flash('Deleted "%s"' % name)
    125         return
    126 
    127     def getApplications(self):
    128         """Get a list of all stored applicant containers.
    129         """
    130         for key, val in self.context.items():
    131             url = self.url(val)
    132             yield(dict(url=url, name=key))
    133 
    134 class AddApplicantsContainerActionButton(AddActionButton):
     112    title = 'Applicants'
     113    label = 'Manage application section'
     114    pnav = 3
     115    grok.require('waeup.manageUniversity')
     116    taboneactions = ['Add applicants container', 'Remove selected','Cancel']
     117    subunits = 'Applicants Containers'
     118   
     119    def update(self):
     120        tabs.need()
     121        #warning.need()
     122        return super(ApplicantsRootManageFormPage, self).update()
     123
     124    # ToDo: Show warning message before deletion
     125    @grok.action('Remove selected')
     126    def delApplicantsContainers(self, **data):
     127        form = self.request.form
     128        child_id = form['val_id']
     129        if not isinstance(child_id, list):
     130            child_id = [child_id]
     131        deleted = []
     132        for id in child_id:
     133            try:
     134                del self.context[id]
     135                deleted.append(id)
     136            except:
     137                self.flash('Could not delete %s: %s: %s' % (
     138                        id, sys.exc_info()[0], sys.exc_info()[1]))
     139        if len(deleted):
     140            self.flash('Successfully removed: %s' % ', '.join(deleted))
     141        self.redirect(self.url(self.context, '@@manage')+'#tab-1')   
     142        return       
     143
     144    @grok.action('Add applicants container', validator=NullValidator)
     145    def addApplicantsContainer(self, **data):
     146        self.redirect(self.url(self.context, '@@add'))
     147        return   
     148       
     149    @grok.action('Cancel', validator=NullValidator)
     150    def cancel(self, **data):
     151        self.redirect(self.url(self.context))
     152        return   
     153   
     154class ApplicantsContainerAddFormPage(WAeUPAddFormPage):
    135155    grok.context(IApplicantsRoot)
    136     grok.view(ApplicantsRootEditPage)
    137     text = 'Add applicants container'
    138 
    139 class AddApplicantsContainer(WAeUPPage):
    140     grok.context(IApplicantsRoot)
     156    grok.require('waeup.manageUniversity')
    141157    grok.name('add')
    142     grok.template('addcontainer')
    143     title = 'Add applicants container'
    144     pnav = 3
    145 
    146     def update(self, providername=None, name=None, title=None,
    147                description=None, ADD=None, CANCEL=None):
    148         if CANCEL is not None:
    149             self.redirect(self.url(self.context))
    150             return
    151         if ADD is None:
    152             return
    153         if not name:
    154             self.flash('Error: you must give a name')
    155             return
    156         if name in self.context.keys():
    157             self.flash('A container of the given name already exists')
     158    grok.template('applicantscontaineraddformpage')
     159    title = 'Applicants'
     160    label = 'Add applicants container'
     161    pnav = 3
     162    form_fields = grok.AutoFields(IApplicantsContainerAdd)
     163    # hier muessen noch die widgets fuer die Datumsfelder rein
     164   
     165    @grok.action('Add applicants container')
     166    def addApplicantsContainer(self, **data):
     167        if data['code'] in self.context.keys():
     168            self.status = Invalid('The name chosen already exists '
     169                                  'in the database')
    158170            return
    159171        # Add new applicants container...
    160172        provider = getUtility(IApplicantsContainerProvider,
    161                               name=providername)
     173                              name=getattr(data['provider'],
     174                                   'grokcore.component.directive.name'))
    162175        container = provider.factory()
    163         if title:
    164             container.title = title
    165         if description:
    166             container.description = description
    167         self.context[name] = container
    168         self.flash('Added "%s".' % name)
    169         self.redirect(self.url(self.context))
     176        self.applyData(container, **data)
     177        self.context[data['code']] = container
     178        self.flash('Added "%s".' % data['code'])
     179        self.redirect(self.url(self.context, u'@@manage')+'#tab-1')
    170180        return
    171181       
    172     def getContainerProviders(self):
    173         """Get a list of applicants container providers.
    174 
    175         Applicants container providers are named utilities that help
    176         to create applicants containers of different types
    177         (JAMB-based, non-JAMB-based, etc.).
    178 
    179         The list returned contains dicts::
    180 
    181           {'name': <utility_name>,
    182            'provider': <provider instance>}
    183 
    184         where `utility_name` is the name under which the respective
    185         provider utility is registered and `provider` is the real
    186         provider instance.
    187 
    188         The `utility_name` can be used to lookup the utility anew (for
    189         instance after submitting a form) and the `provider` instance
    190         can be used to create new instances of the respective
    191         applicants container type.
    192         """
    193         providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider)
    194         result = [
    195             {'name': getattr(x, 'grokcore.component.directive.name'),
    196              'provider': x}
    197              for x in providers
    198             ]
    199         return result
     182    @grok.action('Cancel')
     183    def cancel(self, **data):
     184        self.redirect(self.url(self.context))       
     185     
     186    #def getContainerProviders(self):
     187    #    """Get a list of applicants container providers.
     188    #
     189    #    Applicants container providers are named utilities that help
     190    #    to create applicants containers of different types
     191    #    (JAMB-based, non-JAMB-based, etc.).
     192    #
     193    #    The list returned contains dicts::
     194    #
     195    #      {'name': <utility_name>,
     196    #       'provider': <provider instance>}
     197    #
     198    #    where `utility_name` is the name under which the respective
     199    #    provider utility is registered and `provider` is the real
     200    #    provider instance.
     201    #
     202    #    The `utility_name` can be used to lookup the utility anew (for
     203    #    instance after submitting a form) and the `provider` instance
     204    #    can be used to create new instances of the respective
     205    #    applicants container type.
     206    #    """
     207    #    providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider)
     208    #    result = [
     209    #        {'name': getattr(x, 'grokcore.component.directive.name'),
     210    #         'provider': x}
     211    #         for x in providers
     212    #        ]
     213    #    return result
    200214
    201215class ApplicantsRootBreadcrumb(Breadcrumb):
     
    213227    """Faculties-tab in primary navigation.
    214228    """
     229   
    215230    grok.context(IWAeUPObject)
    216231    grok.order(3)
    217     grok.require('waeup.View')
     232    grok.require('waeup.manageUniversity')
    218233    grok.template('primarynavtab')
    219234
     
    253268    #    else:
    254269    #        return
     270
     271
    255272
    256273class ManageApplicantsContainerActionButton(ManageActionButton):
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantscontainerpage.pt

    r6063 r6069  
    77<table class="zebra">
    88  <tbody>
    9       <tr>
    10         <td class="fieldname">
    11           Type (Code):
    12         </td>
    13         <td class="field">
    14           <input tal:replace="context/__name__" />
    15         </td>
    16       </tr> 
    179    <tal:block repeat="widget view/widgets">
    1810      <tal:condition condition="python:widget.name not in ['form.description','form.title']">
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantsrooteditpage.pt

    r5860 r6069  
    1 <form method="POST">
    2   <table>
     1<h2 i18n:translate=""
     2tal:condition="view/label"
     3tal:content="view/label">Label</h2>
     4
     5<div class="form-status"
     6tal:define="status view/status"
     7tal:condition="status">
     8
     9<div i18n:translate="" tal:content="view/status">
     10  Form status summary
     11</div>
     12
     13<ul class="errors" tal:condition="view/errors">
     14  <li tal:repeat="error view/error_views">
     15     <span tal:replace="structure error">Error Type</span>
     16  </li>
     17</ul>
     18</div>
     19
     20
     21<form action="." tal:attributes="action request/URL" method="POST"
     22      class="edit-form" enctype="multipart/form-data">
     23
     24<div id="tabs">
     25<ul>
     26  <li><a href="#tab-1"><span tal:content="view/subunits">Contents</span></a></li>
     27</ul>
     28   
     29<div id="tab-1">
     30  <h3 tal:content="view/subunits">Applicants Containers</h3>
     31  <table class="zebra">
    332    <thead>
    433      <tr>
    5         <th>&nbsp;</th><th>Name</th><th>Title</th>
     34        <th>&nbsp;</th><th>Code</th><th>Title</th>
    635      </tr>
    736    </thead>
    837    <tbody>
    9       <tr tal:repeat="entry view/getApplications"
    10           tal:attributes="class python: repeat['entry'].odd() and 'odd' or 'even'">
    11         <td>
    12           <input type="checkbox" name="entries"
    13                  tal:attributes="value entry/name" />
    14         </td>
    15         <td>
    16           <a href=""
    17              tal:attributes="href entry/url"
    18              tal:content="entry/name"
    19              >Some Entry</a>
    20         </td>
    21         <td>
    22           <span tal:define="name entry/name">
    23             <span tal:content="python: context[name].title">Title</span>
    24           </span>
    25         </td>
     38      <tr tal:repeat="ac context/values">
     39        <td>
     40          <input type="checkbox"
     41                 name="val_id"
     42                 tal:attributes="value ac/__name__" />
     43        </td>
     44        <td>
     45          <a tal:attributes="href python: view.url(ac)"
     46             tal:content="ac/__name__">
     47                ID
     48          </a>
     49        </td>
     50        <td>
     51          <span tal:content="ac/title">
     52           ID
     53          </span>
     54        </td>
    2655      </tr>
    2756    </tbody>
    2857  </table>
    29   <input type="submit" name="DELETE" value="Delete selected" />
    30   <input type="reset" name="RESET" value="Reset" />
    31   <input type="submit" name="CANCEL" value="Cancel" />
    32 </form>
     58 
     59    <div id="actionsView">
     60        <span class="actionButtons" tal:condition="view/availableActions">
     61            <span tal:repeat="action view/actions"
     62                  tal:omit-tag="">
     63              <input tal:condition="python:action.label in view.taboneactions"
     64                     tal:replace="structure action/render"/>
     65            </span>
     66        </span>
     67    </div>     
     68 
     69</div>
     70</div>
     71</form>
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantsrootpage.pt

    r6067 r6069  
     1<h2 i18n:translate=""
     2tal:condition="view/label"
     3tal:content="view/label">Label</h2>
     4
    15<table class="display dataTable">
    26  <thead>
    37    <tr>
    4       <th>Name</th><th>Title</th>
     8      <th>Code</th><th>Title</th>
    59    </tr>
    610  </thead>
     
    1115        <a href=""
    1216           tal:attributes="href python:view.url(entry)"
    13            tal:content="entry/name"
     17           tal:content="entry/__name__"
    1418           >Name</a>
    1519      </td>
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/container.py

    r5884 r6069  
    2525import grok
    2626from waeup.sirp.applicants.interfaces import (
    27     IApplicantsContainer, IApplicantsContainerProvider,
     27    IApplicantsContainer, IApplicantsContainerAdd,
     28    IApplicantsContainerProvider,
    2829    )
     30from zope.schema.fieldproperty import FieldProperty   
    2931
    3032class ApplicantsContainer(grok.Container):
    3133    """An applicants container contains university applicants.
    3234    """
    33     grok.implements(IApplicantsContainer)
     35    grok.implements(IApplicantsContainer,IApplicantsContainerAdd)
     36    #grok.provides(IApplicantsContainer)
    3437
    3538    title = u'Simple applicant container'
     
    3841    enddate = None
    3942    strict_deadline = True
    40 
    41     @property
    42     def name(self):
    43         return getattr(self, '__name__', None)
     43    provider = None
     44    code = None
    4445   
    4546    def archive(self, app_ids=None):
     
    7475        """
    7576        raise NotImplemented()
    76 
     77       
    7778class ApplicantsContainerProvider(grok.GlobalUtility):
    7879    """A utility that provides basic applicants containers.
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r6039 r6069  
    3333from waeup.sirp.image.image import WAeUPImageFile
    3434from waeup.sirp.interfaces import IWAeUPObject, SimpleWAeUPVocabulary
     35from zope.component import getAllUtilitiesRegisteredFor
    3536
    3637IMAGE_PATH = os.path.join(
     
    8081        if value == 'f':
    8182            return 'female'
     83           
     84class ApplicantContainerProviderSource(BasicSourceFactory):
     85    """
     86    """
     87    def getValues(self):
     88        providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider)
     89        return providers                 
     90
     91    def getToken(self, value):
     92        return getattr(value, 'grokcore.component.directive.name')
     93       
     94    def getTitle(self, value):
     95        return "%s - %s" % (value.factory.title, value.factory.description)           
    8296
    8397class IResultEntry(IWAeUPObject):
     
    97111    """
    98112    pass
     113   
    99114
    100115class IApplicantsContainer(IWAeUPObject):
     
    102117
    103118    """
     119
     120    code = schema.TextLine(
     121        title = u'Code',
     122        description = u'Abbreviated code of applicants container',
     123        default = u'NA',
     124        required = True,
     125        readonly = True,
     126        )   
     127   
     128    provider = schema.Choice(
     129        title = u'Type of applicants stored here.',
     130        required = True,
     131        default = None,
     132        source = ApplicantContainerProviderSource(),
     133        )       
     134   
    104135    title = schema.TextLine(
    105136        title = u'Title of the type of applicants stored here.',
     
    161192        database.
    162193        """
     194       
     195class IApplicantsContainerAdd(IApplicantsContainer):
     196    """An applicants container contains university applicants.
     197    """
     198    code = schema.TextLine(
     199        title = u'Code',
     200        description = u'Abbreviated code of applicants container',
     201        default = u'NA',
     202        required = True,
     203        readonly = False,
     204        )   
     205       
     206IApplicantsContainerAdd['code'].order =  IApplicantsContainer['code'].order         
     207           
    163208class IApplicantBaseData(IWAeUPObject):
    164209    """The data for an applicant.
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/root.py

    r5867 r6069  
    2929
    3030class ApplicantsRoot(grok.Container):
    31     """The root of applicants-related components. It contains primarily
     31    """The root of applicants-related components. It contains only
    3232    containers for applicants.
    3333    """
Note: See TracChangeset for help on using the changeset viewer.