Ignore:
Timestamp:
10 Jun 2016, 08:15:54 (9 years ago)
Author:
Henrik Bettermann
Message:

Add LecturerLandingPage and LecturerCourses ManageLink viewlet.

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

Legend:

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

    r13813 r13908  
    365365                    self.redirect(self.application_url() + rel_link)
    366366                    return
     367                # Redirect lecturer after login
     368                local_roles = get_user_account(self.request).getLocalRoles()
     369                if local_roles.has_key('waeup.local.Lecturer'):
     370                    self.redirect(self.application_url() + '/my_courses')
     371                    return
    367372                if not self.camefrom:
    368373                    self.redirect(self.application_url() + '/index')
     
    978983        return site_roles_userfriendly
    979984
     985class LecturerLandingPage(KofaPage):
     986    """Display courses when lecturer logs in.
     987    """
     988    grok.name('my_courses')
     989    grok.require('waeup.Authenticated')
     990    grok.context(IUniversity)
     991    grok.template('mycourses')
     992    label =_('My Courses')
     993
     994    @property
     995    def academic_session(self):
     996        current_academic_session = grok.getSite()[
     997            'configuration'].current_academic_session
     998        if current_academic_session:
     999            session = academic_sessions_vocab.getTerm(
     1000                current_academic_session).title
     1001            return session
     1002        return _('no academic session set')
     1003
     1004    @property
     1005    def getCourses(self):
     1006        local_roles = get_user_account(self.request).getLocalRoles()
     1007        return local_roles['waeup.local.Lecturer']
     1008
    9801009#
    9811010# Search pages...
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py

    r13898 r13908  
    300300        url = self.view.url(grok.getSite(), self.link)
    301301        text = translate(self.text, context=self.request)
    302         return u'<li><a href="%s">%s</a></li>' % (
    303                 url, text)
     302        return u'<li><a href="%s">%s</a></li>' % (url, text)
    304303
    305304class ManagePortalConfiguration(ManageLink):
     
    339338    text = _(u'Reports')
    340339
     340class LecturerCourses(ManageLink):
     341    """A link to courses of lecturers.
     342    """
     343    grok.order(6)
     344    grok.require('waeup.Authenticated')
     345
     346    link = u'my_courses'
     347    text = _(u'My Courses')
     348
     349    def render(self):
     350        user_account = get_user_account(self.request)
     351        if user_account:
     352            local_roles = user_account.getLocalRoles()
     353            if local_roles.has_key('waeup.local.Lecturer'):
     354                url = self.view.url(grok.getSite(), self.link)
     355                text = translate(self.text, context=self.request)
     356                return u'<li><a href="%s">%s</a></li>' % (url, text)
     357        return ''
     358
    341359class MyPreferences(ManageLink):
    342360    """A link to personal preferences, placed in upper left box.
    343361    """
    344     grok.order(6)
     362    grok.order(7)
    345363    grok.require('waeup.Public')
    346364    text = _(u'My Preferences')
     
    351369            url = self.view.url(account_object)
    352370            text = translate(self.text, context=self.request)
    353             return u'<li><a href="%s">%s</a></li>' % (
    354                     url, text)
     371            return u'<li><a href="%s">%s</a></li>' % (url, text)
    355372        return ''
    356373
     
    358375    """A link to display site and local roles.
    359376    """
    360     grok.order(7)
     377    grok.order(8)
    361378    grok.require('waeup.Public')
    362379    text = _(u'My Roles')
     
    367384            url = self.view.url(account_object) + '/my_roles'
    368385            text = translate(self.text, context=self.request)
    369             return u'<li><a href="%s">%s</a></li>' % (
    370                     url, text)
     386            return u'<li><a href="%s">%s</a></li>' % (url, text)
    371387        return ''
    372388
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r13898 r13908  
    32093209            code=(self.context.code, self.context.code)
    32103210            )
    3211         result = [[_('Matric No.'),
     3211        header = [[_('Matric No.'),
    32123212                   _('Reg. No.'),
    32133213                   _('Fullname'),
     
    32163216                   _('Level'),
    32173217                   _('Score') ],]
     3218        tickets = []
    32183219        for ticket in list(coursetickets):
    32193220            row = [ticket.student.matric_number,
     
    32243225                  ticket.level,
    32253226                  ticket.score]
    3226             result.append(row)
    3227         return result
     3227            tickets.append(row)
     3228        return header + sorted(tickets, key=lambda value: value[0])
    32283229
    32293230    def render(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r13904 r13908  
    18211821        prmlocal = IPrincipalRoleManager(course)
    18221822        prmlocal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrslecturer')
     1823        notify(LocalRoleSetEvent(
     1824            course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
    18231825        # Login as lecturer.
    18241826        self.browser.open(self.login_path)
    18251827        self.browser.getControl(name="form.login").value = 'mrslecturer'
    1826         self.browser.getControl(name="form.password").value = 'mrslecturersecret'
     1828        self.browser.getControl(
     1829            name="form.password").value = 'mrslecturersecret'
    18271830        self.browser.getControl("Login").click()
    18281831        self.assertMatches('...You logged in...', self.browser.contents)
    1829         # CO can see her roles.
     1832        # Lecturer is on landing page
     1833        self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents)
     1834        # Lecturer can click the 'My Roles' link.
    18301835        self.browser.getLink("My Roles").click()
    18311836        self.assertMatches(
    18321837            '...<div>Academics Officer (view only)</div>...',
    18331838            self.browser.contents)
    1834         # But not her local role ...
    1835         self.assertFalse('Lecturer' in self.browser.contents)
    1836         # ... because we forgot to notify the course that the local role
    1837         # has changed.
    1838         notify(LocalRoleSetEvent(
    1839             course, 'waeup.local.Lecturer', 'mrslecturer', granted=True))
    1840         self.browser.open('http://localhost/app/users/mrslecturer/my_roles')
    1841         self.assertTrue('Lecturer' in self.browser.contents)
    18421839        self.assertMatches(
    1843             '...<a href="http://localhost/app/faculties/fac1/dep1/courses/COURSE1">...',
     1840            '...<a href="http://localhost/app/'
     1841            'faculties/fac1/dep1/courses/COURSE1">...',
    18441842            self.browser.contents)
     1843        self.assertFalse('(<span>COURSE1</span>)' in self.browser.contents)
     1844        # Lecturer can click the 'My Courses' link ...
     1845        self.browser.getLink("My Courses").click()
     1846        # ... and is is back on landing page
     1847        self.assertTrue('(<span>COURSE1</span>)' in self.browser.contents)
    18451848        # The lecturer can go to her course ...
    1846         self.browser.getLink(
    1847             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1").click()
     1849        self.browser.getLink("COURSE1").click()
    18481850        # Lecturers can neither filter students ...
    18491851        self.assertRaises(
     
    18611863        # Course results can be batch edited via the edit_courses view.
    18621864        self.app['faculties']['fac1']['dep1'].score_editing_disabled = True
    1863         self.browser.open("http://localhost/app/faculties/fac1/dep1/courses/COURSE1")
     1865        self.browser.open(
     1866            "http://localhost/app/faculties/fac1/dep1/courses/COURSE1")
    18641867        self.browser.getLink("Update scores").click()
    18651868        self.assertTrue('Score editing disabled' in self.browser.contents)
    18661869        self.app['faculties']['fac1']['dep1'].score_editing_disabled = False
    18671870        self.browser.getLink("Update scores").click()
    1868         self.assertTrue('Current academic session not set' in self.browser.contents)
     1871        self.assertTrue(
     1872            'Current academic session not set' in self.browser.contents)
    18691873        self.app['configuration'].current_academic_session = 2004
    18701874        self.browser.getLink("Update scores").click()
     
    18751879        # Student must be in state 'courses validated'.
    18761880        self.browser.open(
    1877             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
     1881            'http://localhost/app/faculties/fac1/'
     1882            'dep1/courses/COURSE1/edit_scores')
    18781883        self.assertTrue(
    18791884            'input type="text" name="scores"' in self.browser.contents)
     
    18881893        logcontent = open(logfile).read()
    18891894        self.assertTrue('mrslecturer - students.browser.EditScoresPage - '
    1890                         'K1000000 100/COURSE1 score updated (55)' in logcontent)
     1895            'K1000000 100/COURSE1 score updated (55)' in logcontent)
    18911896        # Non-integer scores won't be accepted.
    18921897        self.browser.open(
    1893             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
     1898            'http://localhost/app/faculties/fac1/'
     1899            'dep1/courses/COURSE1/edit_scores')
    18941900        self.assertTrue('value="55" />' in self.browser.contents)
    18951901        self.browser.getControl(name="scores", index=0).value = 'abc'
     
    18991905        # Scores can be removed.
    19001906        self.browser.open(
    1901             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/edit_scores")
     1907            'http://localhost/app/faculties/fac1/'
     1908            'dep1/courses/COURSE1/edit_scores')
    19021909        self.browser.getControl(name="scores", index=0).value = ''
    19031910        self.browser.getControl("Update scores").click()
     
    19061913        logcontent = open(logfile).read()
    19071914        self.assertTrue('mrslecturer - students.browser.EditScoresPage - '
    1908                         'K1000000 100/COURSE1 score updated (None)' in logcontent)
     1915            'K1000000 100/COURSE1 score updated (None)' in logcontent)
    19091916        # A course ticket slip can be downloaded
    19101917        self.browser.open(
    1911             "http://localhost/app/faculties/fac1/dep1/courses/COURSE1/coursetickets.pdf")
     1918            'http://localhost/app/faculties/fac1/'
     1919            'dep1/courses/COURSE1/coursetickets.pdf')
    19121920        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    19131921        self.assertEqual(self.browser.headers['Content-Type'],
     
    19161924        open(path, 'wb').write(self.browser.contents)
    19171925        print "Sample PDF coursetickets.pdf written to %s" % path
    1918 
    19191926
    19201927    def test_change_current_mode(self):
Note: See TracChangeset for help on using the changeset viewer.