Changeset 6633


Ignore:
Timestamp:
26 Aug 2011, 10:10:18 (13 years ago)
Author:
Henrik Bettermann
Message:

We don't need a factory for StudentsContainer?.

Add addStudent method which automatically creates subcontainers.

Add StudentStudyCourse? container class which holds the study course data and contains student study level objects for course registration.

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

Legend:

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

    r6621 r6633  
    22from hurry.file.interfaces import IFileRetrieval
    33from zope.authentication.interfaces import IAuthentication
    4 from zope.component import createObject, getUtilitiesFor
     4from zope.component import getUtilitiesFor
    55from zope.component.interfaces import ObjectEvent
    66from zope.pluggableauth import PluggableAuthentication
    77from waeup.sirp.authentication import setup_authentication
    88from waeup.sirp.datacenter import DataCenter
     9from waeup.sirp.students.container import StudentsContainer
    910from waeup.sirp.imagestorage import ImageStorageFileRetrieval, ImageStorage
    1011from waeup.sirp.interfaces import (
     
    4243        self['datacenter'] = DataCenter()
    4344        self['images'] = ImageStorage()
    44         self['students'] = createObject(u'waeup.StudentsContainer')
     45        self['students'] = StudentsContainer()
    4546        self._createPlugins()
    4647
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r6632 r6633  
    211211        student_id = self.request.form.get('form.student_id')
    212212        student = createObject(u'waeup.Student')
     213        student.student_id = student_id
    213214        self.applyData(student, **data)
    214215        #import pdb; pdb.set_trace()
    215216        try:
    216             self.context[student_id] = student
     217            self.context.addStudent(student)
    217218        except KeyError:
    218219            self.flash('The student id chosen already exists.')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/container.py

    r6621 r6633  
    2121from zope.component.interfaces import IFactory
    2222from zope.interface import implementedBy
    23 from waeup.sirp.students.interfaces import IStudentsContainer
     23from waeup.sirp.students.interfaces import (
     24    IStudentsContainer, IStudent)
     25from waeup.sirp.students.studycourse import StudentStudyCourse
    2426
    2527class StudentsContainer(grok.Container):
     
    3537    def clear(self, id=None, archive=True):
    3638        raise NotImplementedError()
    37    
    38 class StudentsContainerFactory(grok.GlobalUtility):
    39     """A factory for students containers.
    40     """
    41     grok.implements(IFactory)
    42     grok.name(u'waeup.StudentsContainer')
    43     title = u"Create a new students container.",
    44     description = u"This factory instantiates new students containers."
    4539
    46     def __call__(self, *args, **kw):
    47         return StudentsContainer()
    48 
    49     def getInterfaces(self):
    50         return implementedBy(StudentsContainer)
     40    def addStudent(self, student):
     41        """Add a student with subcontainers.
     42        """
     43        if not IStudent.providedBy(student):
     44            raise TypeError('StudentsContainers contain only IStudent instances')
     45        self[student.student_id] = student
     46        studycourse = StudentStudyCourse()
     47        self[student.student_id]['studycourse'] = studycourse
     48        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r6631 r6633  
    4747    """
    4848
     49    def addStudent(faculty):
     50        """Add an IStudent object and subcontainers.
     51
     52        """
     53
    4954    def archive(id=None):
    5055        """Create on-dist archive of students.
     
    7681        database.
    7782        """
     83
     84class IStudentStudyCourse(IWAeUPObject):
     85    """A container for student study levels.
     86
     87    """
     88
     89    certificate_code = schema.TextLine(
     90        title = u'Certificate Code',
     91        default = u'None',
     92        required = True,
     93        )
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_container.py

    r6621 r6633  
    2525    )
    2626from waeup.sirp.students.container import (
    27     StudentsContainer, StudentsContainerFactory,
     27    StudentsContainer,
    2828    )
    2929from waeup.sirp.testing import FunctionalLayer
     
    5050        self.assertRaises(
    5151            NotImplementedError, container.clear)
    52 
    53 class StudentsContainerFactoryTest(FunctionalTestCase):
    54 
    55     layer = FunctionalLayer
    56 
    57     def setUp(self):
    58         self.factory = StudentsContainerFactory()
    59 
    60     def tearDown(self):
    61         pass
    62 
    63     def test_interfaces(self):
    64         verifyClass(IFactory, StudentsContainerFactory)
    65         verifyObject(IFactory, self.factory)
    66 
    67     def test_factory(self):
    68         obj = self.factory()
    69         assert isinstance(obj, StudentsContainer)
    70 
    71     def test_getInterfaces(self):
    72         implemented_by = self.factory.getInterfaces()
    73         assert implemented_by.isOrExtends(IStudentsContainer)
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_student.py

    r6632 r6633  
    3030    Student, StudentFactory,
    3131    )
     32from waeup.sirp.students.studycourse import (
     33    StudentStudyCourse,
     34    )
    3235from waeup.sirp.students.interfaces import (
    33     IStudent,
     36    IStudent, IStudentStudyCourse,
    3437    )
    3538from waeup.sirp.testing import FunctionalLayer
     
    4245        super(StudentTest, self).setUp()
    4346        self.student = Student()
     47        self.studycourse = StudentStudyCourse()
    4448        return
    4549
     
    5155        verify.verifyClass(IStudent, Student)
    5256        verify.verifyObject(IStudent, self.student)
     57        verify.verifyClass(IStudentStudyCourse, StudentStudyCourse)
     58        verify.verifyObject(IStudentStudyCourse, self.studycourse)
    5359        return
    5460
  • main/waeup.sirp/trunk/src/waeup/sirp/university/interfaces.py

    r6561 r6633  
    6262        """Add an IFactulty object.
    6363
    64         Returns the key, under which the object was stored.
    6564        """
    6665class IDepartment(IWAeUPObject):
Note: See TracChangeset for help on using the changeset viewer.