Ignore:
Timestamp:
5 Nov 2012, 07:19:54 (12 years ago)
Author:
Henrik Bettermann
Message:

Limit the total number of credits per level.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9521 r9532  
    12241224    @action(_('Add course ticket'))
    12251225    def addCourseTicket(self, **data):
     1226        students_utils = getUtility(IStudentsUtils)
    12261227        ticket = createObject(u'waeup.CourseTicket')
    12271228        course = data['course']
    12281229        ticket.automatic = False
    12291230        ticket.carry_over = False
     1231        max_credits = students_utils.maxCreditsExceeded(self.context, course)
     1232        if max_credits:
     1233            self.flash(_(
     1234                'Total credits exceed ${a}.',
     1235                mapping = {'a': max_credits}))
     1236            return
    12301237        try:
    12311238            self.context.addCourseTicket(ticket, course)
     
    22492256    @action(_('Add course ticket'))
    22502257    def addCourseTicket(self, **data):
     2258        students_utils = getUtility(IStudentsUtils)
    22512259        # Safety belt
    22522260        if self.context.student.state != PAID:
     
    22562264        ticket.automatic = False
    22572265        ticket.carry_over = False
     2266        max_credits = students_utils.maxCreditsExceeded(self.context, course)
     2267        if max_credits:
     2268            self.flash(_(
     2269                'Your total credits exceed ${a}.',
     2270                mapping = {'a': max_credits}))
     2271            return
    22582272        try:
    22592273            self.context.addCourseTicket(ticket, course)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9501 r9532  
    464464    certcode = Attribute('The certificate code of the study course')
    465465    is_current_level = Attribute('Is this level the current level of the student?')
     466    total_credits = Attribute('Total of all ticket credits in this study level.')
    466467
    467468    level_session = schema.Choice(
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studylevel.py

    r9501 r9532  
    5959
    6060    @property
     61    def total_credits(self):
     62        total = 0
     63        for ticket in self.values():
     64            total += ticket.credits
     65        return total
     66
     67    @property
    6168    def is_current_level(self):
    6269        try:
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9521 r9532  
    725725        self.browser.getControl("Add course ticket").click()
    726726        self.browser.getControl(name="form.course").value = ['COURSE1']
     727        self.course.credits = 100
     728        self.browser.getControl("Add course ticket").click()
     729        self.assertMatches(
     730            '...Total credits exceed 58...', self.browser.contents)
     731        self.course.credits = 10
    727732        self.browser.getControl("Add course ticket").click()
    728733        self.assertTrue('Successfully added' in self.browser.contents)
     
    18731878        self.browser.getControl("Add course ticket").click()
    18741879        self.browser.getControl(name="form.course").value = ['COURSE1']
     1880        self.course.credits = 100
     1881        self.browser.getControl("Add course ticket").click()
     1882        self.assertMatches(
     1883            '...Your total credits exceed 58...', self.browser.contents)
     1884        self.course.credits = 10
    18751885        self.browser.getControl("Add course ticket").click()
    18761886        self.assertMatches('...The ticket exists...',
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r9521 r9532  
    573573        return pdf_stream
    574574
     575    TOTAL_CREDITS = 58
     576
     577    def maxCreditsExceeded(self, studylevel, course):
     578        if self.TOTAL_CREDITS and \
     579            studylevel.total_credits + course.credits > self.TOTAL_CREDITS:
     580            return self.TOTAL_CREDITS
     581        return 0
     582
    575583    VERDICTS_DICT = {
    576584        '0': _('(not yet)'),
Note: See TracChangeset for help on using the changeset viewer.