Ignore:
Timestamp:
9 May 2012, 08:39:01 (13 years ago)
Author:
Henrik Bettermann
Message:

Add description (= introduction) to ApplicantsRoot?. Adjust ApplicantsPlugin? accordingly.

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

Legend:

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

    r8365 r8388  
    6161grok.context(IKofaObject) # Make IKofaObject the default context
    6262
    63 class ApplicantsRootPage(KofaPage):
     63class ApplicantsRootPage(KofaDisplayFormPage):
    6464    grok.context(IApplicantsRoot)
    6565    grok.name('index')
    6666    grok.require('waeup.Public')
     67    form_fields = grok.AutoFields(IApplicantsRoot)
     68    form_fields['description'].custom_widget = HTMLDisplayWidget
    6769    label = _('Application Section')
    6870    pnav = 3
     
    7072    def update(self):
    7173        super(ApplicantsRootPage, self).update()
    72         #datatable.need()
    73         return
     74        return
     75
     76    @property
     77    def introduction(self):
     78        # Here we know that the cookie has been set
     79        lang = self.request.cookies.get('kofa.language')
     80        html = self.context.description_dict.get(lang,'')
     81        if html == '':
     82            portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
     83            html = self.context.description_dict.get(portal_language,'')
     84        return html
    7485
    7586class ApplicantsRootManageFormPage(KofaEditFormPage):
     
    7788    grok.name('manage')
    7889    grok.template('applicantsrootmanagepage')
     90    form_fields = grok.AutoFields(IApplicantsRoot)
    7991    label = _('Manage application section')
    8092    pnav = 3
    8193    grok.require('waeup.manageApplication')
    82     taboneactions = [_('Add applicants container'), _('Remove selected'),
    83         _('Cancel')]
    84     tabtwoactions1 = [_('Remove selected local roles')]
    85     tabtwoactions2 = [_('Add local role')]
     94    taboneactions = [_('Save')]
     95    tabtwoactions = [_('Add applicants container'), _('Remove selected')]
     96    tabthreeactions1 = [_('Remove selected local roles')]
     97    tabthreeactions2 = [_('Add local role')]
    8698    subunits = _('Applicants Containers')
    8799
     
    90102        datatable.need()
    91103        warning.need()
     104        self.tab1 = self.tab2 = self.tab3 = ''
     105        qs = self.request.get('QUERY_STRING', '')
     106        if not qs:
     107            qs = 'tab1'
     108        setattr(self, qs, 'active')
    92109        return super(ApplicantsRootManageFormPage, self).update()
    93110
     
    109126    def delApplicantsContainers(self, **data):
    110127        form = self.request.form
    111         child_id = form['val_id']
     128        if form.has_key('val_id'):
     129            child_id = form['val_id']
     130        else:
     131            self.flash(_('No container selected!'))
     132            self.redirect(self.url(self.context, '@@manage')+'?tab2')
     133            return
    112134        if not isinstance(child_id, list):
    113135            child_id = [child_id]
     
    123145            self.flash(_('Successfully removed: ${a}',
    124146                mapping = {'a':', '.join(deleted)}))
    125         self.redirect(self.url(self.context, '@@manage'))
     147        self.redirect(self.url(self.context, '@@manage')+'?tab2')
    126148        return
    127149
     
    131153        return
    132154
    133     @action(_('Cancel'), validator=NullValidator)
    134     def cancel(self, **data):
    135         self.redirect(self.url(self.context))
    136         return
    137 
    138155    @action(_('Add local role'), validator=NullValidator)
    139156    def addLocalRole(self, **data):
     
    143160    def delLocalRoles(self, **data):
    144161        return del_local_roles(self,3,**data)
     162
     163    def _description(self):
     164        view = ApplicantsRootPage(
     165            self.context,self.request)
     166        view.setUpWidgets()
     167        return view.widgets['description']()
     168
     169    @action(_('Save'), style='primary')
     170    def save(self, **data):
     171        self.applyData(self.context, **data)
     172        self.context.description_dict = self._description()
     173        self.flash(_('Form has been saved.')+'?tab1')
     174        return
    145175
    146176class ApplicantsContainerAddFormPage(KofaAddFormPage):
     
    236266        lang = self.request.cookies.get('kofa.language')
    237267        html = self.context.description_dict.get(lang,'')
    238         if html =='':
     268        if html == '':
    239269            portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    240270            html = self.context.description_dict.get(portal_language,'')
    241         if html =='':
    242             return ''
    243         else:
    244             return html
     271        return html
    245272
    246273    @property
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantsrootmanagepage.pt

    r7811 r8388  
    22  i18n:domain="waeup.kofa" method="POST"  enctype="multipart/form-data">
    33  <ul class="tabs" data-tabs="tabs">
    4     <li class="active">
     4    <li tal:attributes="class view/tab1">
    55    <a href="#tab-1">
     6      <span i18n:translate="">Introduction
     7      </span></a>
     8    </li>
     9    <li tal:attributes="class view/tab2">
     10    <a href="#tab-2">
    611      <span tal:content="view/subunits">Contents
    712      </span></a>
    813    </li>
    9     <li>
    10     <a href="#tab-2">
     14    <li tal:attributes="class view/tab3">
     15    <a href="#tab-3">
    1116      <span i18n:translate="">Local Roles
    1217      </span></a>
     
    1419  </ul>
    1520  <div class="tab-content">
    16     <div id="tab-1" class="active">
     21    <div id="tab-1" tal:attributes="class view/tab1">
     22      <table class="form-table">
     23        <tbody>
     24          <tal:widgets content="structure provider:widgets" />
     25        </tbody>
     26      </table>
     27
     28      <div tal:condition="view/availableActions">
     29        <span tal:repeat="action view/actions" tal:omit-tag="">
     30          <input tal:condition="python:action.label in view.taboneactions"
     31            tal:replace="structure action/render"/>
     32        </span>
     33      </div>
     34    </div>
     35    <div id="tab-2" tal:attributes="class view/tab2">
    1736      <h3 tal:content="view/subunits">SUBUNITS</h3>
    1837      <table class="display dataTableManage">
     
    4362      <div tal:condition="view/availableActions">
    4463        <span tal:repeat="action view/actions" tal:omit-tag="">
    45           <input tal:condition="python:action.label in view.taboneactions"
     64          <input tal:condition="python:action.label in view.tabtwoactions"
    4665            tal:replace="structure action/render"/>
    4766        </span>
    4867      </div>
    4968    </div>
    50     <div id="tab-2"> <br />
     69    <div id="tab-3" tal:attributes="class view/tab3">
     70      <br />
    5171      <table class="display dataTableManage">
    5272        <thead>
     
    7494      <div tal:condition="view/availableActions">
    7595        <span tal:repeat="action view/actions" tal:omit-tag="">
    76           <input tal:condition="python:action.label in view.tabtwoactions1"
     96          <input tal:condition="python:action.label in view.tabthreeactions1"
    7797            tal:replace="structure action/render"/>
    7898        </span>
     
    96116            <div tal:condition="view/availableActions">
    97117              <span tal:repeat="action view/actions" tal:omit-tag="">
    98                 <input tal:condition="python:action.label in view.tabtwoactions2"
     118                <input tal:condition="python:action.label in view.tabthreeactions2"
    99119                  tal:replace="structure action/render"/>
    100120              </span>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantsrootpage.pt

    r7811 r8388  
     1<span tal:condition="view/introduction" tal:omit-tag="">
     2  <span tal:content="structure view/introduction">INTRODUCTION</span>
     3  <br />
     4</span>
     5
    16<table i18n:domain="waeup.kofa">
    27  <thead>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r8365 r8388  
    149149    """A container for university applicants containers.
    150150    """
    151     pass
     151
     152    description = schema.Text(
     153        title = _(u'Human readable description in HTML format'),
     154        required = False,
     155        default = u'''This text can been seen by anonymous users.
     156Here we put multi-lingual general information about the application procedure.
     157>>de<<
     158Dieser Text kann von anonymen Benutzern gelesen werden.
     159Hier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.'''
     160        )
     161
     162    description_dict = Attribute(
     163        """Content as language dictionary with values in HTML format.""")
    152164
    153165class IApplicantsContainer(IKofaObject):
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/root.py

    r7819 r8388  
    2323from hurry.query.interfaces import IQuery
    2424from zope.component import getUtility
     25from zope.schema import getFields
    2526from waeup.kofa.interfaces import IKofaPluggable
    2627from waeup.kofa.applicants.interfaces import IApplicantsRoot
    2728from waeup.kofa.utils.logger import Logger
     29from waeup.kofa.utils.helpers import attrs_to_fields
    2830
    2931class ApplicantsRoot(grok.Container, Logger):
     
    3436
    3537    local_roles = []
     38
     39    #: A dictionary to hold per language translations of description string.
     40    description_dict = {}
    3641
    3742    logger_name = 'waeup.kofa.${sitename}.applicants'
     
    4449                target, ob_class, comment))
    4550        return
     51
     52ApplicantsRoot = attrs_to_fields(ApplicantsRoot)
    4653
    4754class ApplicantsPlugin(grok.GlobalUtility):
     
    7885        site_name = getattr(site, '__name__', '<Unnamed Site>')
    7986        if IApplicantsRoot.providedBy(app_folder):
    80             # Applicants up to date. Return.
    81             logger.info(
    82                 '%s: Updating site at %s: Nothing to do.' % (
    83                     self.log_prefix, site_name,)
    84                 )
     87            items = getFields(IApplicantsRoot).items()
     88            nothing_to_do = True
     89            for i in items:
     90                if not hasattr(app_folder,i[0]):
     91                    nothing_to_do = False
     92                    setattr(app_folder,i[0],i[1].missing_value)
     93                    logger.info(
     94                        '%s: %s added to root.' % (self.log_prefix,i[0]))
     95            # can be removed after upgrading uniben
     96            if not hasattr(app_folder, 'description_dict'):
     97                nothing_to_do = False
     98                setattr(app_folder,'description_dict',{})
     99                logger.info(
     100                    '%s: description_dict added to root.' % self.log_prefix)
     101            if nothing_to_do:
     102                logger.info(
     103                    '%s: Updating site at %s: Nothing to do.' % (
     104                        self.log_prefix, site_name,)
     105                    )
    85106            return
    86107        elif app_folder is not None:
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r8346 r8388  
    237237        # Managers can add and delete applicants containers
    238238        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    239         self.browser.open(self.manage_root_path)
    240         self.browser.getControl("Cancel").click()
    241         self.assertEqual(self.browser.url, self.root_path)
    242239        self.browser.open(self.manage_root_path)
    243240        self.browser.getControl("Add applicants container").click()
Note: See TracChangeset for help on using the changeset viewer.