source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py @ 8351

Last change on this file since 8351 was 8290, checked in by Henrik Bettermann, 13 years ago

Enable import of password and state. When application_number is given in create mode, construct applicant_id accordingly (do not use id generator) and store applicant with this application_number in the respective container. Attention: application_number can be any string.

More tests will follow.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: container.py 8290 2012-04-26 17:01:32Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Containers for university applicants.
20"""
21from random import SystemRandom as r
22import grok
23from zope.component.factory import Factory
24from zope.component.interfaces import IFactory
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.applicants.interfaces import (
27    IApplicantsContainer, IApplicantsContainerAdd, IApplicant
28    )
29from waeup.kofa.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"
40
41class ApplicantsContainer(grok.Container):
42    """An applicants container contains university applicants.
43    """
44    grok.implements(IApplicantsContainer,IApplicantsContainerAdd)
45
46    #: A dictionary to hold per language translations of description string.
47    description_dict = {}
48
49    @property
50    def local_roles(self):
51        return []
52
53    def archive(self, app_ids=None):
54        """Create on-dist archive of applicants stored in this term.
55
56        If app_ids is `None`, all applicants are archived.
57
58        If app_ids contains a single id string, only the respective
59        applicants are archived.
60
61        If app_ids contains a list of id strings all of the respective
62        applicants types are saved to disk.
63        """
64        raise NotImplementedError()
65
66    def clear(self, app_ids=None, archive=True):
67        """Remove applicants of type given by 'id'.
68
69        Optionally archive the applicants.
70
71        If id is `None`, all applicants are archived.
72
73        If id contains a single id string, only the respective
74        applicants are archived.
75
76        If id contains a list of id strings all of the respective
77        applicant types are saved to disk.
78
79        If `archive` is ``False`` none of the archive-handling is done
80        and respective applicants are simply removed from the
81        database.
82        """
83        raise NotImplementedError()
84
85    def addApplicant(self, applicant):
86        """Add an applicant.
87        """
88        if not IApplicant.providedBy(applicant):
89            raise TypeError(
90                'ApplicantsContainers contain only IApplicant instances')
91        if applicant.applicant_id is None:
92            applicant_id = generate_applicant_id(container=self)
93            applicant.applicant_id = applicant_id
94        self[applicant.application_number] = applicant
95        return
96
97ApplicantsContainer = attrs_to_fields(ApplicantsContainer)
98
99# ApplicantsContainers must be importable. So we need a factory.
100class ApplicantsContainerFactory(grok.GlobalUtility):
101    """A factory for student online payments.
102    """
103    grok.implements(IFactory)
104    grok.name(u'waeup.ApplicantsContainer')
105    title = u"Create a new container for applicants.",
106    description = u"This factory instantiates new IApplicantsContainer instances."
107
108    def __call__(self, *args, **kw):
109        return ApplicantsContainer()
110
111    def getInterfaces(self):
112        return implementedBy(ApplicantsContainer)
Note: See TracBrowser for help on using the repository browser.