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/students
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.