Ignore:
Timestamp:
20 May 2012, 09:57:09 (13 years ago)
Author:
Henrik Bettermann
Message:

Add property is_postgrad.

Add invariant constraint to ICertificate.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/batchprocessing.txt

    r8372 r8472  
    298298    >>> open('certificates.csv', 'wb').write(
    299299    ... """code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category
    300     ... CERT1,FAC1,DEP1,Certificate 1,ug_ft,100,300,basic
     300    ... CERT1,FAC1,DEP1,Certificate 1,pg_ft,999,999,basic
    301301    ... CERT2,FAC1,DEP1,Certificate 2,ug_ft,200,300,cest
    302302    ... """)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r8471 r8472  
    412412    @property
    413413    def form_fields(self):
    414         cm = getattr(self.context,'current_mode', None)
    415         if cm is not None and cm.startswith('pg'):
     414        if self.context.is_postgrad:
    416415            form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked')
    417416        else:
     
    434433    @property
    435434    def form_fields(self):
    436         cm = getattr(self.context,'current_mode', None)
    437         if cm is not None and cm.startswith('pg'):
     435        if self.context.is_postgrad:
    438436            form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked')
    439437        else:
     
    478476    @property
    479477    def form_fields(self):
    480         cm = getattr(self.context,'current_mode', None)
    481         if cm is not None and cm.startswith('pg'):
     478        if self.context.is_postgrad:
    482479            form_fields = grok.AutoFields(IPGStudentClearance)
    483480        else:
     
    16211618    @property
    16221619    def form_fields(self):
    1623         cm = getattr(self.context,'current_mode', None)
    1624         if cm is not None and cm.startswith('pg'):
     1620        if self.context.is_postgrad:
    16251621            form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked')
    16261622        else:
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r8452 r8472  
    133133        if certificate is not None:
    134134            return certificate.study_mode
    135         return
     135        return None
     136
     137    @property
     138    def is_postgrad(self):
     139        is_postgrad = getattr(
     140            self.get('studycourse', None), 'is_postgrad', False)
     141        return is_postgrad
    136142
    137143# Set all attributes of Student required in IStudent as field
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py

    r8471 r8472  
    4848            return True
    4949        if self.getStudent().state == PAID \
    50             and self.getStudent().current_mode.startswith('pg'):
     50            and self.getStudent().is_postgrad:
    5151            return True
    5252        return False
     
    105105        return
    106106
     107    @property
     108    def is_postgrad(self):
     109        cert = getattr(self, 'certificate', None)
     110        if cert is not None:
     111            return cert.study_mode.startswith('pg')
     112            #return cert.start_level == 999 or cert.end_level == 999
     113        return False
     114
    107115StudentStudyCourse = attrs_to_fields(StudentStudyCourse)
    108116
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r8471 r8472  
    18371837        self.assertFalse('Employer' in self.browser.contents)
    18381838        # Now we change the study mode of the certificate and a different
    1839         # interface is used by clearance views
     1839        # interface is used by clearance views.
    18401840        self.certificate.study_mode = 'pg_ft'
     1841        # Invariants are not being checked here?!
     1842        self.certificate.end_level = 100
    18411843        self.browser.open(self.clearance_path)
    18421844        self.assertTrue('Employer' in self.browser.contents)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r8471 r8472  
    278278                details['p_session'], details[
    279279                    'p_level'] = self.getReturningData(student)
    280             elif student.current_mode.startswith('pg') and student.state == PAID:
     280            elif student.is_postgrad and student.state == PAID:
    281281                # Returning postgraduate students also pay for the next session
    282282                # but their level always remains the same.
  • main/waeup.kofa/trunk/src/waeup/kofa/university/interfaces.py

    r8299 r8472  
    2020
    2121from zope import schema
    22 from zope.interface import Attribute
     22from zope.interface import Attribute, invariant, Invalid
    2323from waeup.kofa.interfaces import (IKofaObject, IKofaContainer)
    2424from waeup.kofa.interfaces import MessageFactory as _
     
    245245        """
    246246
     247    @invariant
     248    def check_pg_conditions(cert):
     249        if cert.start_level == 999 and not cert.end_level == 999:
     250            raise Invalid(_("Start level and end level must correspond."))
     251        if cert.end_level == 999 and not cert.start_level == 999:
     252            raise Invalid(_("Start level and end level must correspond."))
     253        if cert.study_mode.startswith('pg') and not cert.start_level == 999:
     254            raise Invalid(_(
     255                "Study mode, start level and end level must correspond."))
     256        if cert.start_level == 999  and not cert.study_mode.startswith('pg'):
     257            raise Invalid(_(
     258                "Study mode, start level and end level must correspond."))
     259
     260
    247261class ICertificateAdd(ICertificate):
    248262    """Representation of a certificate.
Note: See TracChangeset for help on using the changeset viewer.