:mod:`waeup.kofa.university.course` -- Courses ********************************************** .. module:: waeup.kofa.university.course Components that represent courses. .. :doctest: .. :layer: waeup.kofa.testing.KOFAUnitTestLayer Content Classes (models and containers) ======================================= :class:`Course` --------------- .. class:: Course([code=u'NA'[, title=u'Unnamed Course'[, credits=0[, passmark=40[, semester=1]]]]]]) Create a course instance with the given parameters. .. attribute:: grok.implements(ICourse) All parameters are optional: >>> from waeup.kofa.university.course import Course >>> mycourse = Course() >>> mycourse Course instances have the attributes required by the :class:`waeup.kofa.interfaces.ICourse` interface: >>> from waeup.kofa.university.interfaces import ICourse >>> ICourse.providedBy(mycourse) True >>> from zope.interface.verify import verifyObject >>> verifyObject(ICourse, mycourse) True .. attribute:: title Each course has a title: >>> mycourse.title u'Unnamed Course' .. attribute:: code Each course holds a code, which might be a shortcut or abbreviation of the real course name. By default the code is ``NA`` (=not assigned). This value has to be unique if used in a :class:`Department` instance as it serves as a key: >>> mycourse.code u'NA' .. attribute:: passmark Each course holdes a passmark, which is ``40`` by default: >>> mycourse.passmark 40 .. attribute:: semester Each course holds a semester attribute which is ``1`` by default: >>> mycourse.semester 1 .. attribute:: credits Each course holds the number of credits that can be earned. Default is ``0``. >>> mycourse.credits 0 Utilities ========= :class:`CourseFactory` --------------------------- .. class:: CourseFactory() .. attribute:: grok.name(u'waeup.Course') .. attribute:: grok.implements(IFactory) A named utility to deliver new instances of :class:`Course` without the need to import the implementation before: >>> from zope.component import createObject >>> mycourse = createObject(u'waeup.Course') >>> mycourse The factory complies with the specifications from the :class:`IFactory` insterface: >>> from zope.interface.verify import verifyClass >>> from zope.component.interfaces import IFactory >>> from waeup.kofa.university.course import CourseFactory >>> verifyClass(IFactory, CourseFactory) True This means also, that we can get the interfaces of the created object from the factory: >>> course_factory = CourseFactory() >>> course_factory.getInterfaces() Examples ======== Creating courses ---------------- The simplest way to create a :class:`Course` instance is to import the class and calling the constructor: >>> from waeup.kofa.university.course import Course >>> mycourse = Course() >>> mycourse Another way to create courses is by asking for a factory called ``waeup.Course``. This way we can create a factory without importing a class: >>> from zope.component import createObject >>> mycourse = createObject(u'waeup.Course') >>> mycourse