Ignore:
Timestamp:
13 Sep 2022, 07:06:32 (2 years ago)
Author:
Henrik Bettermann
Message:

Implement Polling Unit Locator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.lpng/trunk/src/kofacustom/lpng/applicants/browser.py

    r17073 r17091  
    2626    FriendlyDatetimeDisplayWidget)
    2727from waeup.kofa.applicants.pdf import PDFApplicationSlip
     28from waeup.kofa.browser.layout import KofaEditFormPage, action
    2829from waeup.kofa.applicants.browser import (
    2930    ApplicantRegistrationPage, ApplicantsContainerPage,
     
    4647    ICustomApplicantOnlinePayment,
    4748    ICustomApplicantEdit,
     49    IPollingUnit,
     50    STATES, LGAS, WARDS, PUNITS
    4851    )
    4952from kofacustom.lpng.interfaces import MessageFactory as _
     
    5558
    5659    @property
    57     def form_fields(self):
    58         form_fields = grok.AutoFields(ICustomApplicant)
     60    def render_punit(self):
     61        if self.context.punit:
     62            punit = self.context.punit.split('_')
     63            return ' / '.join([STATES[punit[0]],
     64                    LGAS['_'.join(punit[:2])],
     65                    WARDS['_'.join(punit[:3])] ,
     66                    PUNITS['_'.join(punit[:4])]
     67                   ])
     68        return
     69
     70    @property
     71    def form_fields(self):
     72        form_fields = grok.AutoFields(
     73            ICustomApplicant).omit('locked', 'suspended', 'federalstate',
     74                                   'lga', 'ward', 'punit')
    5975        form_fields['perm_address'].custom_widget = BytesDisplayWidget
    60         form_fields['notice'].custom_widget = BytesDisplayWidget
     76        #form_fields['notice'].custom_widget = BytesDisplayWidget
    6177        if not getattr(self.context, 'student_id'):
    6278            form_fields = form_fields.omit('student_id')
     
    91107    @property
    92108    def form_fields(self):
    93         form_fields = grok.AutoFields(ICustomApplicant)
     109        form_fields = grok.AutoFields(ICustomApplicant).omit(
     110            'federalstate', 'lga', 'ward', 'punit')
    94111        if not getattr(self.context, 'student_id'):
    95112            form_fields = form_fields.omit('student_id')
     
    136153    def form_fields(self):
    137154        form_fields = grok.AutoFields(ICustomApplicantEdit)
    138         form_fields = form_fields.omit('notice', 'locked', 'suspended')
     155        form_fields = form_fields.omit('locked', 'suspended', 'federalstate',
     156                                       'lga', 'ward', 'punit')
    139157        if not getattr(self.context, 'student_id'):
    140158            form_fields = form_fields.omit('student_id')
     
    177195            self.context.__parent__, applicantview, note=self.note,
    178196            omit_fields=())
     197
     198class PunitFormPage(KofaEditFormPage):
     199    """
     200    """
     201    grok.context(ICustomApplicant)
     202    grok.require('waeup.handleApplication')
     203    grok.name('punitformpage')
     204    form_fields = grok.AutoFields(IPollingUnit)
     205    grok.template('puniteditpage')
     206    label = _('Locate polling unit')
     207    pnav = 3
     208
     209    @action(_('Save'), style='primary')
     210    def save(self, **data):
     211        changed_fields = self.applyData(self.context, **data)
     212        # Turn list of lists into single list
     213        if changed_fields:
     214            changed_fields = reduce(lambda x, y: x+y, changed_fields.values())
     215        if 'federalstate' in changed_fields:
     216            # Clear other form fields
     217            self.context.lga = self.context.ward = self.context.punit = None
     218            self.flash(_('Federal State has been saved.'))
     219            return         
     220        if 'lga' in changed_fields:
     221            # Clear other form fields
     222            self.context.ward = self.context.punit = None
     223            self.flash(_('LGA has been saved.'))
     224            return         
     225        if 'ward' in changed_fields:
     226            # Clear other form fields
     227            self.context.punit = None
     228            self.flash(_('Ward has been saved.'))
     229            return
     230        if 'punit' in changed_fields and self.context.punit:
     231            self.flash(_('Polling Unit has been successfully saved.'))
     232            self.redirect(self.url(self.context))
     233        return
Note: See TracChangeset for help on using the changeset viewer.