Ignore:
Timestamp:
7 Jun 2012, 18:28:09 (12 years ago)
Author:
Henrik Bettermann
Message:

Move statistics method to ApplicantsUtils? in order to ease customization.

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

Legend:

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

    r8643 r8645  
    2424from zope.component.factory import Factory
    2525from zope.component.interfaces import IFactory
    26 from zope.catalog.interfaces import ICatalog
    2726from waeup.kofa.interfaces import MessageFactory as _
    2827from waeup.kofa.applicants.interfaces import (
    29     IApplicantsContainer, IApplicantsContainerAdd, IApplicant
    30     )
     28    IApplicantsContainer, IApplicantsContainerAdd, IApplicant,
     29    IApplicantsUtils)
    3130from waeup.kofa.utils.helpers import attrs_to_fields
    32 from waeup.kofa.applicants.workflow import (INITIALIZED,
    33     STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED)
     31
    3432
    3533def generate_applicant_id(container=None):
     
    10098
    10199    @property
    102     def unused_statistics(self):
    103         state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0,
    104             ADMITTED:0, NOT_ADMITTED:0, CREATED:0}
    105         faculty_keys = grok.getSite()['faculties'].keys()
    106         fac_stats = dict([(i,0) for i in faculty_keys])
    107         for key in self.keys():
    108             state = self[key].state
    109             state_stats[state] += 1
    110             cert = getattr(self[key],'course1',None)
    111             if  cert is not None and state == SUBMITTED:
    112                 faculty = cert.__parent__.__parent__.__parent__
    113                 fac_stats[faculty.__name__] += 1
    114         return state_stats, fac_stats
    115 
    116     @property
    117100    def statistics(self):
    118         state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0,
    119             ADMITTED:0, NOT_ADMITTED:0, CREATED:0}
    120         cat = getUtility(ICatalog, name='applicants_catalog')
    121         code = self.code
    122         year = int(code[-4:])
    123         target = code[:-4]
    124         mxcode = target + str(year + 1)
    125         for state in state_stats:
    126             state_stats[state] = len(cat.searchResults(
    127                 state=(state, state),
    128                 applicant_id=(code, mxcode)))
    129         return state_stats, None
     101        return getUtility(IApplicantsUtils).getApplicantsStatistics(self)
    130102
    131103ApplicantsContainer = attrs_to_fields(ApplicantsContainer)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py

    r8534 r8645  
    2121from time import time
    2222import grok
     23from zope.component import getUtility
     24from zope.catalog.interfaces import ICatalog
     25from waeup.kofa.interfaces import MessageFactory as _
    2326from waeup.kofa.applicants.interfaces import IApplicantsUtils
    24 from waeup.kofa.interfaces import MessageFactory as _
     27from waeup.kofa.applicants.workflow import (INITIALIZED,
     28    STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED)
    2529
    2630class ApplicantsUtils(grok.GlobalUtility):
     
    5761        payment.p_category = 'application'
    5862        return None
     63
     64    def getApplicantsStatistics(self,container):
     65        state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0,
     66            ADMITTED:0, NOT_ADMITTED:0, CREATED:0}
     67        cat = getUtility(ICatalog, name='applicants_catalog')
     68        code = container.code
     69        year = int(code[-4:])
     70        target = code[:-4]
     71        mxcode = target + str(year + 1)
     72        for state in state_stats:
     73            state_stats[state] = len(cat.searchResults(
     74                state=(state, state),
     75                applicant_id=(code, mxcode)))
     76        return state_stats, None
Note: See TracChangeset for help on using the changeset viewer.