Ignore:
Timestamp:
24 Aug 2015, 05:56:39 (9 years ago)
Author:
Henrik Bettermann
Message:

Extend and use container_code attribute to distinguish used and unused records.

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

Legend:

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

    r13213 r13216  
    8383
    8484    @property
    85     def record_used(self):
     85    def container_code(self):
     86        try:
     87            code = self.__parent__.code
     88        except AttributeError:  # in unit tests
     89            return
    8690        if (self.password,
    8791            self.firstname,
    8892            self.lastname,
    89             self.email) != (None, None, None, None):
    90             return True
    91         return False
    92 
    93     @property
    94     def container_code(self):
    95         try:
    96             code = self.__parent__.code
    97         except AttributeError:  # in unit tests
    98             return
    99         return code
     93            self.email) == (None, None, None, None):
     94            return code + '-'
     95        return code + '+'
    10096
    10197    @property
     
    236232    email = index.Field(attribute='email')
    237233    state = index.Field(attribute='state')
    238     record_used = index.Field(attribute='record_used')
     234    container_code = index.Field(attribute='container_code')
    239235
    240236class ApplicantFactory(grok.GlobalUtility):
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/export.py

    r13080 r13216  
    101101            # unwanted excel automatic
    102102            value = str('%s#' % value)
     103        elif name == 'container_code':
     104            value = value.strip('+')
    103105        return super(
    104106            ApplicantExporter, self).mangle_value(
     
    117119        """Export all applicants into filepath as CSV data.
    118120        If `filepath` is ``None``, a raw string with CSV data is returned.
     121        Only used records are being exported.
    119122        """
    120123        catalog = queryUtility(
     
    126129            # We therefore search for applicant_id.
    127130            applicant_id=(None, None))
    128         return self.export(applicants, filepath)
     131        used = [value for value in applicants if value.container_code.endswith('+')]
     132        return self.export(used, filepath=filepath)
    129133
    130134    def export_filtered(self, site, filepath=None, **kw):
    131135        """Export filtered applicants in container denoted by keywords (`kw`).
    132136        If `filepath` is ``None``, a raw string with CSV data should
    133         be returned.
     137        be returned. Only used records are being exported.
    134138        """
    135139        container = grok.getSite()['applicants'][kw['container']]
    136         return self.export(container.values(), filepath=filepath)
     140        container_values = container.values()
     141        used = [value for value in container_values if value.container_code.endswith('+')]
     142        return self.export(used, filepath=filepath)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r13213 r13216  
    327327    """
    328328    state = Attribute('Application state of an applicant')
    329     record_used = Attribute('True if password or any required field has been set')
    330329    history = Attribute('Object history, a list of messages')
    331330    display_fullname = Attribute('The fullname of an applicant')
    332331    application_number = Attribute('The key under which the record is stored')
    333     container_code = Attribute('Code of the parent container')
     332    container_code = Attribute('Code of the parent container plus additional information if record is used or not')
    334333    translated_state = Attribute('Real name of the application state')
    335334    special = Attribute('True if special application')
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/root.py

    r13214 r13216  
    9494            try:
    9595                cat = getUtility(ICatalog, name='applicants_catalog')
    96                 if 'record_used' not in cat.keys():
     96                if 'container_code' not in cat.keys():
    9797                    nothing_to_do = False
    98                     cat[u'record_used'] = FieldIndex(field_name=u'record_used')
     98                    cat[u'container_code'] = FieldIndex(field_name=u'container_code')
    9999                    cat.updateIndexes()
    100100                    logger.info(
    101                         '%s: record_used index added to applicants_catalog.'
     101                        '%s: container_code index added to applicants_catalog.'
    102102                        % self.log_prefix)
    103103            except ComponentLookupError: # in unit tests
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicant.py

    r13213 r13216  
    191191        return
    192192
    193     def test_record_used(self):
    194         self.applicant.password is None
    195         self.applicant.firstname is None
    196         self.applicant.lastname is None
    197         self.applicant.email is None
    198         self.applicant.record_used is False
    199         self.applicant.firstname is 'Anna'
    200         self.applicant.record_used is True
     193    def test_container_code(self):
     194        fake_container = grok.Container()
     195        fake_container.__name__ = 'folder'
     196        fake_container.code = 'folder'
     197        appl = Applicant()
     198        appl.password is None
     199        appl.firstname is None
     200        appl.lastname is None
     201        appl.email is None
     202        appl.container_code is 'folder-'
     203        appl.firstname is 'Anna'
     204        appl.container_code is 'folder+'
     205        return
    201206
    202207class ApplicantFactoryTest(FunctionalTestCase):
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py

    r13133 r13216  
    8888        cat = getUtility(ICatalog, name='applicants_catalog')
    8989        code = container.code
    90         year = int(code[-4:])
    91         target = code[:-4]
    92         mxcode = target + str(year + 1)
    9390        for state in state_stats:
    94             state_stats[state] = len(cat.searchResults(
    95                 state=(state, state),
    96                 applicant_id=(code, mxcode)))
     91            if state == 'initialized':
     92                results = cat.searchResults(
     93                                state=(state, state),
     94                                container_code=(code + '+', code + '+'))
     95                state_stats[state] = len(results)
     96            else:
     97                results = cat.searchResults(
     98                    state=(state, state),
     99                    container_code=(code + '+', code + '-'))
     100                state_stats[state] = len(results)
    97101        return state_stats, None
    98102
Note: See TracChangeset for help on using the changeset viewer.