Changeset 7260


Ignore:
Timestamp:
4 Dec 2011, 07:56:39 (13 years ago)
Author:
Henrik Bettermann
Message:

Let's generate the applicant_id only when the applicant is added to its container to be compliant with the generic batch processor (importer).

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

Legend:

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

    r7255 r7260  
    1717##
    1818import os
    19 from random import SystemRandom as r
    2019import grok
    2120from grok import index
     
    3433    )
    3534
    36 def generate_applicant_id(container=None):
    37     if container is not None:
    38         aid = u"%s_%d" % (container.code, r().randint(99999,1000000))
    39         while aid in container.keys():
    40             aid = u"%s_%d" % (container.code, r().randint(99999,1000000))
    41         return aid
    42     else:
    43         # In some tests we don't use containers
    44         return u"xxx_1234"
    45 
    4635class Applicant(grok.Container):
    4736    grok.implements(IApplicant,IApplicantEdit)
    4837    grok.provides(IApplicant)
    4938
    50     def __init__(self, container=None):
     39    def __init__(self):
    5140        super(Applicant, self).__init__()
    52         self.applicant_id = generate_applicant_id(container)
    5341        self.password = None
    5442        IWorkflowInfo(self).fireTransition('init')
    5543        self.application_date = None
     44        self.applicant_id = None
    5645        return
    5746
     
    7261    @property
    7362    def application_number(self):
    74         return self.applicant_id.split('_')[1]
     63        try:
     64            return self.applicant_id.split('_')[1]
     65        except AttributeError:
     66            return None
    7567
    7668    @property
     
    110102
    111103    def __call__(self, *args, **kw):
    112         return Applicant(kw['container'])
     104        return Applicant()
    113105
    114106    def getInterfaces(self):
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r7259 r7260  
    424424    @grok.action('Create application record')
    425425    def addApplicant(self, **data):
    426         applicant = createObject(u'waeup.Applicant', container = self.context)
     426        applicant = createObject(u'waeup.Applicant')
    427427        self.applyData(applicant, **data)
    428428        self.context.addApplicant(applicant)
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/container.py

    r7240 r7260  
    1919Containers for university applicants.
    2020"""
     21from random import SystemRandom as r
    2122import grok
    2223from zope.component.factory import Factory
     
    2728    )
    2829from waeup.sirp.utils.helpers import attrs_to_fields
     30
     31def generate_applicant_id(container=None):
     32    if container is not None:
     33        aid = u"%s_%d" % (container.code, r().randint(99999,1000000))
     34        while aid in container.keys():
     35            aid = u"%s_%d" % (container.code, r().randint(99999,1000000))
     36        return aid
     37    else:
     38        # In some tests we don't use containers
     39        return u"xxx_1234"
    2940
    3041class ApplicantsContainer(grok.Container):
     
    89100            raise TypeError(
    90101                'ApplicantsContainers contain only IApplicant instances')
     102        applicant_id = generate_applicant_id(container=self)
     103        applicant.applicant_id = applicant_id
    91104        self[applicant.application_number] = applicant
    92105        return
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r7255 r7260  
    257257        title = u'Applicant Id',
    258258        required = False,
    259         readonly = True,
     259        readonly = False,
    260260        )
    261261
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicant.py

    r7255 r7260  
    123123        # we can get an image filename for applicants not in a container
    124124        appl = Applicant()
     125        appl.applicant_id = u'dummy_123456'
    125126        chooser = IFileStoreNameChooser(appl)
    126127        result = chooser.chooseName()
    127128        # the file would be stored in a ``_default`` directory.
    128129        self.assertEqual(
    129             result, '__img-applicant___default/xxx_1234.jpg')
     130            result, '__img-applicant___default/dummy_123456.jpg')
    130131        return
    131132
     
    134135        fake_container.__name__ = 'folder'
    135136        fake_container.code = 'folder'
    136         appl = Applicant(container=fake_container)
     137        appl = Applicant()
     138        appl.applicant_id = u'folder_123456'
    137139        appl.__parent__ = fake_container
    138140        chooser = IFileStoreNameChooser(appl)
     
    147149        fake_container.__name__ = 'folder'
    148150        fake_container.code = 'folder'
    149         appl = Applicant(container=fake_container)
     151        appl = Applicant()
     152        appl.applicant_id = u'folder_123456'
    150153        appl.__parent__ = fake_container
    151154        chooser = IFileStoreNameChooser(appl)
     
    193196
    194197    def test_factory(self):
    195         obj = self.factory(container=None)
     198        obj = self.factory()
    196199        assert isinstance(obj, Applicant)
    197200
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py

    r7259 r7260  
    117117
    118118        # Add an applicant
    119         self.applicant = Applicant(container=applicantscontainer)
    120         app['applicants']['app2009'][
    121             self.applicant.application_number] = self.applicant
     119        self.applicant = Applicant()
     120        app['applicants']['app2009'].addApplicant(self.applicant)
    122121        IUserAccount(
    123122            self.app['applicants']['app2009'][
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_catalog.py

    r7240 r7260  
    6161        setSite(self.app)
    6262        self.app['applicants']['mystuff'] = self.container
    63         self.applicant = Applicant(container=self.container)
    64         self.app['applicants']['mystuff'][
    65             self.applicant.application_number] = self.applicant
     63        self.applicant = Applicant()
     64        self.app['applicants']['mystuff'].addApplicant(self.applicant)
    6665        return
    6766
Note: See TracChangeset for help on using the changeset viewer.