Ignore:
Timestamp:
30 Mar 2012, 17:55:44 (13 years ago)
Author:
Henrik Bettermann
Message:

Remove all ApplicantsContainerProvider? components and use same form customization technique as in students. In contrast to the students package, postgraduate applicants are only defined in the custom package. Thus the implementation is slightly different.

Location:
main/waeup.custom/trunk/src/waeup/custom/applicants
Files:
1 added
3 deleted
4 edited

Legend:

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

    r7866 r8012  
    2020from zope.interface import implementedBy
    2121from waeup.kofa.applicants.applicant import Applicant, ApplicantFactory
    22 from waeup.custom.applicants.interfaces import IPGApplicant, IPGApplicantEdit
     22from waeup.kofa.applicants.interfaces import IApplicantEdit
     23from waeup.kofa.utils.helpers import attrs_to_fields
     24from waeup.custom.applicants.interfaces import(
     25    IApplicant, IUGApplicantEdit, IPGApplicantEdit)
    2326
    24 class PGApplicant(Applicant):
    25     grok.implements(IPGApplicant,IPGApplicantEdit)
    26     grok.provides(IPGApplicant)
     27class Applicant(Applicant):
    2728
    28 class PGApplicantFactory(ApplicantFactory):
    29     """A factory for pg applicants.
     29    grok.implements(IApplicant, IUGApplicantEdit, IPGApplicantEdit)
     30    grok.provides(IApplicant)
     31
     32# Set all attributes of Applicant required in IApplicant as field
     33# properties. Doing this, we do not have to set initial attributes
     34# ourselves and as a bonus we get free validation when an attribute is
     35# set.
     36Applicant = attrs_to_fields(Applicant)
     37
     38class ApplicantFactory(ApplicantFactory):
     39    """A factory for customized applicants.
    3040    """
    31     grok.name(u'waeup.PGApplicant')
    32     title = u"Create a new pg applicant.",
    33     description = u"This factory instantiates new pg applicant instances."
    3441
    3542    def __call__(self, *args, **kw):
    36         return PGApplicant()
     43        return Applicant()
    3744
    3845    def getInterfaces(self):
    39         return implementedBy(PGApplicant)
     46        return implementedBy(Applicant)
  • main/waeup.custom/trunk/src/waeup/custom/applicants/interfaces.py

    r7866 r8012  
    1919"""
    2020
    21 from waeup.kofa.applicants.interfaces import IApplicant, IApplicantEdit
     21from zope import schema
     22from waeup.kofa.applicants.interfaces import IApplicant, IApplicantProcessData
     23from waeup.custom.interfaces import MessageFactory as _
     24
     25class IUGApplicant(IApplicant):
     26    """An undergraduate applicant.
     27
     28    """
    2229
    2330class IPGApplicant(IApplicant):
     
    2633    """
    2734
    28 class IPGApplicantEdit(IApplicantEdit):
     35    employer = schema.TextLine(
     36        title = _(u'Employer'),
     37        required = False,
     38        readonly = False,
     39        )
     40
     41class IApplicant(IUGApplicant,IPGApplicant):
     42    """An interface for both types of applicants.
     43
     44    """
     45
     46class IUGApplicantEdit(IApplicantProcessData):
     47    """An undergraduate applicant interface for editing.
     48
     49    Here we can repeat the fields from base data and set the
     50    `required` and `readonly` attributes to True to further restrict
     51    the data access. Or we can allow only certain certificates to be
     52    selected by choosing the appropriate source.
     53
     54    We cannot omit fields here. This has to be done in the
     55    respective form page.
     56    """
     57
     58class IPGApplicantEdit(IApplicantProcessData):
    2959    """A postgraduate applicant interface for editing.
    3060
  • main/waeup.custom/trunk/src/waeup/custom/applicants/tests.py

    r7934 r8012  
    2222from zope.component.hooks import setSite, clearSite
    2323from zope.component import createObject
     24from zope.testbrowser.testing import Browser
    2425from waeup.kofa.app import University
    2526from waeup.kofa.university.faculty import Faculty
    2627from waeup.kofa.university.department import Department
    2728from waeup.kofa.testing import FunctionalTestCase
     29from waeup.kofa.applicants.container import ApplicantsContainer
    2830from waeup.custom.testing import FunctionalLayer
    2931from waeup.kofa.interfaces import IBatchProcessor
    30 from waeup.kofa.applicants.applicant import Applicant
    31 from waeup.custom.applicants.container import PGApplicantsContainer
    32 from waeup.custom.applicants.applicant import PGApplicant
    33 from waeup.custom.applicants.batching import PGApplicantProcessor
    34 from waeup.custom.applicants.interfaces import IPGApplicant, IPGApplicantEdit
    3532
    36 APPLICANT_SAMPLE_DATA = open(
    37     os.path.join(os.path.dirname(__file__), 'sample_applicant_data.csv'),
    38     'rb').read()
    39 APPLICANT_HEADER_FIELDS = APPLICANT_SAMPLE_DATA.split(
    40     '\n')[0].split(',')
    41 
    42 class PGApplicantProcessorTest(FunctionalTestCase):
    43     """Perform some batching tests.
     33class ApplicantUITest(FunctionalTestCase):
     34    """Perform some browser tests.
    4435    """
    4536    layer = FunctionalLayer
    4637
    4738    def setUp(self):
    48         super(PGApplicantProcessorTest, self).setUp()
     39        super(ApplicantUITest, self).setUp()
    4940        # Setup a sample site for each test
    5041        app = University()
     
    6253        setSite(app)
    6354
    64         # Add an applicants container
    65         self.container = PGApplicantsContainer()
    66         self.container.code = u'pg2011'
    67         self.app['applicants']['pg2011'] = self.container
     55        # Add an two different applicants containers
     56        self.pgcontainer = ApplicantsContainer()
     57        self.pgcontainer.code = u'pg2011'
     58        self.pgcontainer.prefix = u'pg'
     59        self.app['applicants']['pg2011'] = self.pgcontainer
     60        self.ugcontainer = ApplicantsContainer()
     61        self.ugcontainer.code = u'app2011'
     62        self.ugcontainer.prefix = u'app'
     63        self.app['applicants']['app2011'] = self.ugcontainer
    6864
    6965        # Populate university
     
    7874            self.certificate)
    7975
    80         # Add applicant with subobjects
    81         applicant = PGApplicant()
    82         applicant.firstname = u'Anna'
    83         applicant.lastname = u'Tester'
    84         self.app['applicants']['pg2011'].addApplicant(applicant)
    85         self.application_number = applicant.application_number
    86         self.applicant = self.app['applicants']['pg2011'][
    87             self.application_number]
    88         self.processor = PGApplicantProcessor()
    89         self.workdir = tempfile.mkdtemp()
    90         self.csv_file = os.path.join(self.workdir, 'sample_applicant_data.csv')
    91         open(self.csv_file, 'wb').write(APPLICANT_SAMPLE_DATA)
     76        # Add (customized) applicants
     77        pgapplicant = createObject(u'waeup.Applicant')
     78        pgapplicant.firstname = u'Anna'
     79        pgapplicant.lastname = u'Post'
     80        self.app['applicants']['pg2011'].addApplicant(pgapplicant)
     81        self.pgapplication_number = pgapplicant.application_number
     82        self.pgapplicant = self.app['applicants']['pg2011'][
     83            self.pgapplication_number]
     84
     85        ugapplicant = createObject(u'waeup.Applicant')
     86        ugapplicant.firstname = u'Klaus'
     87        ugapplicant.lastname = u'Under'
     88        self.app['applicants']['app2011'].addApplicant(ugapplicant)
     89        self.ugapplication_number = ugapplicant.application_number
     90        self.ugapplicant = self.app['applicants']['app2011'][
     91            self.ugapplication_number]
     92
     93        self.browser = Browser()
     94        self.browser.handleErrors = False
    9295
    9396    def tearDown(self):
    94         super(PGApplicantProcessorTest, self).tearDown()
    95         shutil.rmtree(self.workdir)
     97        super(ApplicantUITest, self).tearDown()
    9698        shutil.rmtree(self.dc_root)
    9799        clearSite()
    98100        return
    99101
    100     def test_interfaces(self):
    101         # Make sure we fulfill the interface contracts.
    102         assert verifyObject(IBatchProcessor, self.processor) is True
    103         assert verifyClass(
    104             IBatchProcessor, PGApplicantProcessor) is True
    105         assert verifyObject(IPGApplicant, self.applicant) is True
    106         assert verifyClass(
    107             IPGApplicant, PGApplicant) is True
    108         assert verifyObject(IPGApplicantEdit, self.applicant) is True
    109         assert verifyClass(
    110             IPGApplicantEdit, PGApplicant) is True
     102    def test_manage_and_view_applicant(self):
     103        # Managers can manage pg applicants
     104        pgapplicant_path = ('http://localhost/app/applicants/pg2011/%s'
     105            % self.pgapplication_number)
     106        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     107        self.browser.open(pgapplicant_path)
     108        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     109        # The IPGApplicant interface is really used
     110        self.assertTrue('Employer' in self.browser.contents)
     111        # If we move the applicant to the container,
     112        # the Employer field disappears
     113        ugapplicant_path = ('http://localhost/app/applicants/app2011/%s'
     114            % self.ugapplication_number)
     115        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     116        self.browser.open(ugapplicant_path)
     117        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    111118
    112     def test_wrong_child(self):
    113         applicant = Applicant()
    114         applicant.firstname = u'Klaus'
    115         applicant.lastname = u'Tester'
    116         self.assertRaises(
    117             TypeError, self.app['applicants']['pg2011'].addApplicant, applicant)
    118 
    119     def test_import(self):
    120         num, num_warns, fin_file, fail_file = self.processor.doImport(
    121             self.csv_file, APPLICANT_HEADER_FIELDS)
    122         self.assertEqual(num_warns,0)
    123         keys = self.app['applicants']['pg2011'].keys()
    124         assert len(keys) == 4
    125         container = self.app['applicants']['pg2011']
    126         assert  container.__implemented__.__name__ == (
    127             'waeup.custom.applicants.container.PGApplicantsContainer')
    128         applicant = container[keys[0]]
    129         assert applicant.__implemented__.__name__ == (
    130             'waeup.custom.applicants.applicant.PGApplicant')
    131         shutil.rmtree(os.path.dirname(fin_file))
     119        self.assertFalse('Employer' in self.browser.contents)
     120        return
  • main/waeup.custom/trunk/src/waeup/custom/applicants/utils.py

    r7845 r8012  
    3636        'ct': ['Certificate Programmes', 'CTP'],
    3737        'dp': ['Diploma Programmes', 'DPP'],
    38         'pce': ['PCE Screening', 'PCE']
     38        'pce': ['PCE Screening', 'PCE'],
     39        'pg': ['Postgraduate Programmes', 'PCE']
    3940        }
Note: See TracChangeset for help on using the changeset viewer.