Ignore:
Timestamp:
16 Jan 2013, 13:16:20 (12 years ago)
Author:
Henrik Bettermann
Message:

Let students and officers add course tickets by entering the course code on the StudyLevelEditFormPage? or StudyLevelManageFormPage? respectively. The course ticket add forms can still be used in case course code is unknown.

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

Legend:

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

    r9868 r9895  
    139139    return None
    140140
     141
     142def addCourseTicket(view, course=None):
     143    students_utils = getUtility(IStudentsUtils)
     144    ticket = createObject(u'waeup.CourseTicket')
     145    ticket.automatic = False
     146    ticket.carry_over = False
     147    max_credits = students_utils.maxCreditsExceeded(view.context, course)
     148    if max_credits:
     149        view.flash(_(
     150            'Total credits exceed ${a}.',
     151            mapping = {'a': max_credits}))
     152        return False
     153    try:
     154        view.context.addCourseTicket(ticket, course)
     155    except KeyError:
     156        view.flash(_('The ticket exists.'))
     157        return False
     158    view.flash(_('Successfully added ${a}.',
     159        mapping = {'a':ticket.code}))
     160    return True
     161
    141162class StudentsBreadcrumb(Breadcrumb):
    142163    """A breadcrumb for the students container.
     
    11571178        _('Remove selected tickets'),_('Cancel')]
    11581179
    1159     def update(self):
     1180    def update(self, ADD=None, course=None):
    11601181        if not self.context.__parent__.is_current:
    11611182            emit_lock_message(self)
     
    11701191        warning.need()
    11711192        datatable.need()
     1193        if ADD is not None:
     1194            if not course:
     1195                self.flash(_('No valid course code entered.'))
     1196                self.redirect(self.url(self.context, u'@@manage')+'?tab2')
     1197                return
     1198            cat = queryUtility(ICatalog, name='courses_catalog')
     1199            result = cat.searchResults(code=(course, course))
     1200            if len(result) != 1:
     1201                self.flash(_('Course not found.'))
     1202            else:
     1203                course = list(result)[0]
     1204                addCourseTicket(self, course)
     1205            self.redirect(self.url(self.context, u'@@manage')+'?tab2')
    11721206        return
    11731207
     
    11891223        msave(self, **data)
    11901224        return
    1191 
    1192     @action(_('Add course ticket'))
    1193     def addCourseTicket(self, **data):
    1194         self.redirect(self.url(self.context, '@@add'))
    11951225
    11961226    @jsaction(_('Remove selected tickets'))
     
    12961326    @action(_('Add course ticket'))
    12971327    def addCourseTicket(self, **data):
    1298         students_utils = getUtility(IStudentsUtils)
    1299         ticket = createObject(u'waeup.CourseTicket')
    13001328        course = data['course']
    1301         ticket.automatic = False
    1302         ticket.carry_over = False
    1303         max_credits = students_utils.maxCreditsExceeded(self.context, course)
    1304         if max_credits:
    1305             self.flash(_(
    1306                 'Total credits exceed ${a}.',
    1307                 mapping = {'a': max_credits}))
    1308             return
    1309         try:
    1310             self.context.addCourseTicket(ticket, course)
    1311         except KeyError:
    1312             self.flash(_('The ticket exists.'))
    1313             return
    1314         self.flash(_('Successfully added ${a}.',
    1315             mapping = {'a':ticket.code}))
    1316         self.redirect(self.url(self.context, u'@@manage')+'?tab2')
     1329        success = addCourseTicket(self, course)
     1330        if success:
     1331            self.redirect(self.url(self.context, u'@@manage')+'?tab2')
    13171332        return
    13181333
     
    22942309    pnav = 4
    22952310
    2296     def update(self):
     2311    def update(self, ADD=None, course=None):
    22972312        if not self.context.__parent__.is_current:
    22982313            emit_lock_message(self)
     
    23052320        datatable.need()
    23062321        warning.need()
     2322        if ADD is not None:
     2323            if not course:
     2324                self.flash(_('No valid course code entered.'))
     2325                return
     2326            cat = queryUtility(ICatalog, name='courses_catalog')
     2327            result = cat.searchResults(code=(course, course))
     2328            if len(result) != 1:
     2329                self.flash(_('Course not found.'))
     2330                return
     2331            course = list(result)[0]
     2332            addCourseTicket(self, course)
    23072333        return
    23082334
     
    23192345    def translated_values(self):
    23202346        return translated_values(self)
    2321 
    2322     @action(_('Add course ticket'))
    2323     def addCourseTicket(self, **data):
    2324         self.redirect(self.url(self.context, 'ctadd'))
    23252347
    23262348    def _delCourseTicket(self, **data):
     
    23732395        return
    23742396
    2375     @action(_('Register course list'), style='primary')
     2397    @action(_('Register course list'))
    23762398    def registerCourses(self, **data):
    23772399        self._registerCourses(**data)
    23782400        return
    2379 
    23802401
    23812402class CourseTicketAddFormPage2(CourseTicketAddFormPage):
     
    23962417    @action(_('Add course ticket'))
    23972418    def addCourseTicket(self, **data):
    2398         students_utils = getUtility(IStudentsUtils)
    23992419        # Safety belt
    24002420        if self.context.student.state != PAID:
    24012421            return
    2402         ticket = createObject(u'waeup.CourseTicket')
    24032422        course = data['course']
    2404         ticket.automatic = False
    2405         ticket.carry_over = False
    2406         max_credits = students_utils.maxCreditsExceeded(self.context, course)
    2407         if max_credits:
    2408             self.flash(_(
    2409                 'Your total credits exceed ${a}.',
    2410                 mapping = {'a': max_credits}))
    2411             return
    2412         try:
    2413             self.context.addCourseTicket(ticket, course)
    2414         except KeyError:
    2415             self.flash(_('The ticket exists.'))
    2416             return
    2417         self.flash(_('Successfully added ${a}.',
    2418             mapping = {'a':ticket.code}))
    2419         self.redirect(self.url(self.context, u'@@edit'))
    2420         return
    2421 
     2423        success = addCourseTicket(self, course)
     2424        if success:
     2425            self.redirect(self.url(self.context, u'@@edit'))
     2426        return
    24222427
    24232428class SetPasswordPage(KofaPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/studyleveleditpage.pt

    r9698 r9895  
    5050  </div>
    5151
     52  <br /><br /><br />
     53  <table class="input-table">
     54    <tr>
     55      <td>
     56        <input class="btn primary" type="submit" name="ADD"
     57               i18n:translate=""
     58               value="Add course ticket" />
     59      </td>
     60      <td>
     61        <input type="text" name="course" />
     62        <div class="hint" i18n:translate="">
     63            Enter valid course code.
     64        </div>
     65      </td>
     66    </tr>
     67  </table>
     68  <p i18n:translate="">
     69    You don't know the course code? Then select a course
     70    <a href="ctadd">here</a>.
     71  </p>
    5272</form> 
    5373
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/studylevelmanagepage.pt

    r9328 r9895  
    7575      </div>
    7676
     77      <br /><br /><br />
     78      <table class="input-table">
     79        <tr>
     80          <td>
     81            <input class="btn primary" type="submit" name="ADD"
     82                   i18n:translate=""
     83                   value="Add course ticket" />
     84          </td>
     85          <td>
     86            <input type="text" name="course" />
     87            <div class="hint" i18n:translate="">
     88                Enter valid course code.
     89            </div>
     90          </td>
     91        </tr>
     92      </table>
     93      <p i18n:translate="">
     94        You don't know the course code? Then select a course
     95        <a href="add">here</a>.
     96      </p>
     97
    7798    </div>
    7899  </div>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9874 r9895  
    750750        self.assertTrue('zope.mgr - students.browser.StudyLevelManageFormPage '
    751751        '- K1000000 - removed: COURSE1' in logcontent)
    752         self.browser.getControl("Add course ticket").click()
     752        self.browser.getLink("here").click()
    753753        self.browser.getControl(name="form.course").value = ['COURSE1']
    754754        self.course.credits = 100
     
    759759        self.browser.getControl("Add course ticket").click()
    760760        self.assertTrue('Successfully added' in self.browser.contents)
     761        # We can do the same by adding the course on the manage page directly
     762        del self.student['studycourse']['100']['COURSE1']
     763        self.browser.getControl(name="course").value = 'COURSE1'
    761764        self.browser.getControl("Add course ticket").click()
     765        self.assertTrue('Successfully added' in self.browser.contents)
     766        self.browser.getLink("here").click()
    762767        self.browser.getControl(name="form.course").value = ['COURSE1']
    763768        self.browser.getControl("Add course ticket").click()
     
    20182023        self.browser.getLink("100").click()
    20192024        self.browser.getLink("Edit course list").click()
    2020         self.browser.getControl("Add course ticket").click()
     2025        self.browser.getLink("here").click()
    20212026        self.browser.getControl(name="form.course").value = ['COURSE1']
    20222027        self.browser.getControl("Add course ticket").click()
     
    20312036        self.browser.getLink("200").click()
    20322037        self.browser.getLink("Edit course list").click()
    2033         self.browser.getControl("Add course ticket").click()
     2038        self.browser.getLink("here").click()
    20342039        self.browser.getControl(name="form.course").value = ['COURSE1']
    20352040        self.course.credits = 100
    20362041        self.browser.getControl("Add course ticket").click()
    20372042        self.assertMatches(
    2038             '...Your total credits exceed 50...', self.browser.contents)
     2043            '...Total credits exceed 50...', self.browser.contents)
    20392044        self.course.credits = 10
    20402045        self.browser.getControl("Add course ticket").click()
     
    20632068        self.browser.getControl("Register course list").click()
    20642069        self.assertTrue('Maximum credits of 50 exceeded' in self.browser.contents)
    2065         # Student can now remove the ticket
     2070        # Student can now remove the ticket ...
    20662071        ctrl = self.browser.getControl(name='val_id')
    20672072        ctrl.getControl(value='COURSE1').selected = True
    20682073        self.browser.getControl("Remove selected", index=0).click()
    20692074        self.assertTrue('Successfully removed' in self.browser.contents)
    2070         # Course list can be registered, even if it's empty
     2075        # ... and add the same ticket using the edit page directly.
     2076        # We can do the same by adding the course on the manage page directly
     2077        self.browser.getControl(name="course").value = 'COURSE1'
     2078        self.browser.getControl("Add course ticket").click()
     2079        # Course list can be registered
    20712080        self.browser.getControl("Register course list").click()
    20722081        self.assertTrue('Course list has been registered' in self.browser.contents)
     
    20962105        self.browser.getLink("999").click()
    20972106        self.browser.getLink("Edit course list").click()
    2098         self.browser.getControl("Add course ticket").click()
     2107        self.browser.getLink("here").click()
    20992108        self.browser.getControl(name="form.course").value = ['COURSE1']
    21002109        self.browser.getControl("Add course ticket").click()
Note: See TracChangeset for help on using the changeset viewer.