source: main/waeup.kofa/branches/0.2/src/waeup/kofa/students/container.py @ 15284

Last change on this file since 15284 was 8737, checked in by Henrik Bettermann, 12 years ago

Use different msave method in students and in university.

Simplify logging. We don't need the logger_info method.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: container.py 8737 2012-06-17 07:32:08Z 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 students.
20"""
21import grok
22from thread import allocate_lock
23from transaction import commit
24from zope.component import getUtility
25from waeup.kofa.students.interfaces import (
26    IStudentsContainer, IStudent, IStudentsUtils)
27from waeup.kofa.utils.helpers import attrs_to_fields
28from waeup.kofa.utils.logger import Logger
29
30lock = allocate_lock() # a lock object to lock threads.
31
32class StudentsContainer(grok.Container, Logger):
33    """
34    The node containing the student models
35    """
36
37    grok.implements(IStudentsContainer)
38
39    _curr_stud_id = 10 ** 6
40
41    logger_name = 'waeup.kofa.${sitename}.students'
42    logger_filename = 'students.log'
43
44    @property
45    def unique_student_id(self):
46        """A unique student id.
47
48        The student id returned is guaranteed to be unique. It
49        consists of some prefix (normally a single letter) followed by
50        a number with at least 7 digits.
51
52        Once a student id was issued, it won't be issued again.
53
54        Obtaining a student id is currently not thread-safe but can be
55        made easily by enabling commented lines.
56        """
57        prefix = getUtility(IStudentsUtils).STUDENT_ID_PREFIX
58
59        # lock.acquire() # lock data
60        new_id = u'%s%s' % (prefix, self._curr_stud_id)
61        self._curr_stud_id += 1
62        # self._p_changed = True
63        # commit()
64        # lock.release() # end of lock
65        return new_id
66
67    def archive(self, id=None):
68        raise NotImplementedError()
69
70    def clear(self, id=None, archive=True):
71        raise NotImplementedError()
72
73    def addStudent(self, student):
74        """Add a student with subcontainers.
75        """
76        if not IStudent.providedBy(student):
77            raise TypeError(
78                'StudentsContainers contain only IStudent instances')
79        self[student.student_id] = student
80        return
81
82StudentsContainer = attrs_to_fields(StudentsContainer)
Note: See TracBrowser for help on using the repository browser.