~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-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
# App: groups
19
 
# Author: Matt Giuca
20
 
# Date: 21/7/2008
21
 
 
22
 
# Allows students and tutors to manage project groups.
23
 
 
24
 
# XXX Does not distinguish between current and past subjects.
25
 
 
26
 
import cgi
 
18
# Author: Matt Giuca, Will Grant
 
19
 
 
20
'''
 
21
Allows students and tutors to manage project groups.
 
22
'''
 
23
 
 
24
# TODO Does not distinguish between current and past subjects.
27
25
 
28
26
from ivle import caps
29
27
from ivle.database import Subject
30
 
from ivle import util
31
 
 
32
 
import genshi
33
 
import genshi.core
34
 
import genshi.template
35
 
 
36
 
def handle(req):
37
 
    # Set request attributes
38
 
    req.content_type = "text/html"
39
 
    req.styles = ["media/groups/groups.css"]
40
 
    req.scripts = [
41
 
        "media/groups/groups.js",
42
 
        "media/common/util.js",
43
 
        "media/common/json2.js",
 
28
 
 
29
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
 
30
from ivle.webapp.base.xhtml import XHTMLView
 
31
 
 
32
class GroupsView(XHTMLView):
 
33
    """
 
34
    The groups view
 
35
    """
 
36
    template = 'template.html'
 
37
    appname = 'groups' # XXX
 
38
 
 
39
    def authorize(self, req):
 
40
        return req.user is not None
 
41
 
 
42
    def populate(self, req, ctx):
 
43
        self.plugin_styles[Plugin] = ['groups.css']
 
44
        self.plugin_scripts[Plugin] = ['groups.js']
 
45
 
 
46
        # Show a group panel per enrolment
 
47
        ctx['get_user_groups'] = req.user.get_groups
 
48
        ctx['enrolments'] = req.user.active_enrolments
 
49
        ctx['manage_subjects'] = req.store.find(Subject) if \
 
50
              req.user.hasCap(caps.CAP_MANAGEGROUPS) else []
 
51
 
 
52
 
 
53
class Plugin(ViewPlugin, MediaPlugin):
 
54
    """
 
55
    The Plugin class for the group admin plugin.
 
56
    """
 
57
    urls = [
 
58
        ('groups/', GroupsView),
44
59
    ]
45
 
    req.write_html_head_foot = True     # Have dispatch print head and foot
46
 
 
47
 
    ctx = genshi.template.Context()
48
 
    
49
 
    ctx['enrolments'] = []
50
 
    # Show a group panel per enrolment
51
 
    enrolments = req.user.active_enrolments
52
 
    if enrolments.count() == 0:
53
 
        ctx['no_enrolments'] = True
54
 
    else:
55
 
        ctx['no_enrolments'] = False
56
 
    
57
 
    for enrolment in enrolments:
58
 
        add_subject_panel(req, enrolment.offering, ctx)
59
 
        
60
 
    if req.user.hasCap(caps.CAP_MANAGEGROUPS):
61
 
        ctx['manage_groups'] = True
62
 
        ctx['manage_subjects'] = []
63
 
        subjects = req.store.find(Subject)
64
 
        for s in subjects:
65
 
            new_s = {}
66
 
            new_s['id'] = s.id
67
 
            new_s['name'] = s.name
68
 
            new_s['code'] = s.code
69
 
            ctx['manage_subjects'].append(new_s)
70
 
    else:
71
 
        ctx['manage_groups'] = False
72
 
  
73
 
    loader = genshi.template.TemplateLoader(".", auto_reload=True)
74
 
    tmpl = loader.load(util.make_local_path("apps/groups/template.html"))
75
 
    
76
 
    req.write(tmpl.generate(ctx).render('html'))
77
 
 
78
 
def add_subject_panel(req, offering, ctx):
79
 
    """
80
 
    Show the group management panel for a particular subject.
81
 
    Prints to req.
82
 
    """
83
 
    # Get the groups this user is in, for this offering
84
 
    groups = req.user.get_groups(offering)
85
 
    if groups.count() == 0:
86
 
        return
87
 
    
88
 
    offering_groups = {}
89
 
    
90
 
    offering_groups['offering_id'] = offering.id
91
 
    offering_groups['offering_name'] = offering.subject.name
92
 
    offering_groups['groups'] = []
93
 
    
94
 
    #TODO: Use a better way to manage group membership and invitations
95
 
    for group in groups:
96
 
        new_group = {}
97
 
        new_group['nick'] = cgi.escape(group.nick if group.nick else '')
98
 
        new_group['name'] = cgi.escape(group.name)
99
 
        
100
 
        # XXX - This should be set to reflect whether or not a user is invited
101
 
        #     - or if they have accepted the offer
102
 
        new_group['is_member'] = True
103
 
        new_group['members'] = []
104
 
        
105
 
        for user in group.members:
106
 
            member = {}
107
 
            member['fullname'] = cgi.escape(user.fullname)
108
 
            member['login'] = cgi.escape(user.login)
109
 
            new_group['members'].append(member)
110
 
        offering_groups['groups'].append(new_group)
111
 
 
112
 
    ctx['enrolments'].append(offering_groups)
 
60
 
 
61
    media = 'media'
 
62
    help = {'Groups': 'help.html'}