~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/groups/__init__.py

  • Committer: William Grant
  • Date: 2009-02-26 02:55:51 UTC
  • Revision ID: grantw@unimelb.edu.au-20090226025551-hofgfw6e7h3pt54i
Tags: 0.1.9.2, 0.1.9.3, 0.1.9.4
Move the group admin view to per-offering.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
Allows students and tutors to manage project groups.
22
22
'''
23
23
 
24
 
# TODO Does not distinguish between current and past subjects.
25
 
 
26
 
from ivle.database import Subject
 
24
from ivle.database import Subject, Offering, Semester
27
25
 
28
26
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
29
27
from ivle.webapp.base.xhtml import XHTMLView
35
33
    template = 'template.html'
36
34
    tab = 'groups'
37
35
 
 
36
    def __init__(self, req, subject, year, semester):
 
37
        """Find the given offering by subject, year and semester."""
 
38
        self.context = req.store.find(Offering,
 
39
            Offering.subject_id == Subject.id,
 
40
            Subject.code == subject,
 
41
            Offering.semester_id == Semester.id,
 
42
            Semester.year == year,
 
43
            Semester.semester == semester).one()
 
44
        
 
45
        if not self.context:
 
46
            raise NotFound()
 
47
 
38
48
    def authorize(self, req):
39
 
        return req.user is not None
 
49
        enrolment = self.context.get_enrolment(req.user)
 
50
        if not enrolment:
 
51
            return False
 
52
        return req.user.admin or enrolment.role in (u'tutor', u'lecturer')
40
53
 
41
54
    def populate(self, req, ctx):
42
55
        self.plugin_styles[Plugin] = ['groups.css']
43
56
        self.plugin_scripts[Plugin] = ['groups.js']
44
57
 
45
 
        roles = set((e.role for e in req.user.active_enrolments))
46
 
        ctx['manage_subjects'] = req.store.find(Subject) if \
47
 
              req.user.admin or 'tutor' in roles or 'lecturer' in roles else []
48
 
 
 
58
        ctx['offering'] = self.context
49
59
 
50
60
class Plugin(ViewPlugin, MediaPlugin):
51
61
    """
52
62
    The Plugin class for the group admin plugin.
53
63
    """
54
64
    urls = [
55
 
        ('groups/', GroupsView),
 
65
        ('/subjects/:subject/:year/:semester/+groups/', GroupsView),
56
66
    ]
57
67
 
58
68
    media = 'media'