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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/breadcrumbs.py

  • Committer: William Grant
  • Date: 2010-07-27 10:44:14 UTC
  • mto: This revision was merged to the branch mainline in revision 1824.
  • Revision ID: grantw@unimelb.edu.au-20100727104414-meuycir4c0dqbpe2
Update schema, add missing UNIQUE constraint, and update sample data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2009 The University of Melbourne
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
 
 
19
class UsersBreadcrumb(object):
 
20
    @property
 
21
    def url(self):
 
22
        return '/users'
 
23
 
 
24
    @property
 
25
    def text(self):
 
26
        return 'Users'
 
27
 
 
28
 
 
29
class UserBreadcrumb(object):
 
30
    def __init__(self, req, context):
 
31
        self.req = req
 
32
        self.context = context
 
33
 
 
34
    @property
 
35
    def url(self):
 
36
        return self.req.publisher.generate(self.context)
 
37
 
 
38
    @property
 
39
    def text(self):
 
40
        perms = self.context.get_permissions(self.req.user, self.req.config)
 
41
        # Show nickname iff current user has permission to view this user
 
42
        # (Else, show just the login name)
 
43
        if 'view' in perms:
 
44
            return self.context.nick
 
45
        else:
 
46
            return self.context.login
 
47
 
 
48
    @property
 
49
    def extra_breadcrumbs_before(self):
 
50
        return [UsersBreadcrumb()]
 
51
 
 
52
 
 
53
class SubjectsBreadcrumb(object):
 
54
    @property
 
55
    def url(self):
 
56
        return '/subjects'
 
57
 
 
58
    @property
 
59
    def text(self):
 
60
        return 'Subjects'
 
61
 
 
62
class SubjectBreadcrumb(object):
 
63
    def __init__(self, req, context):
 
64
        self.req = req
 
65
        self.context = context
 
66
 
 
67
    @property
 
68
    def url(self):
 
69
        return self.req.publisher.generate(self.context)
 
70
 
 
71
    @property
 
72
    def text(self):
 
73
        return self.context.name
 
74
 
 
75
    @property
 
76
    def extra_breadcrumbs_before(self):
 
77
        return [SubjectsBreadcrumb()]
 
78
 
 
79
 
 
80
class OfferingBreadcrumb(object):
 
81
    def __init__(self, req, context):
 
82
        self.req = req
 
83
        self.context = context
 
84
 
 
85
    @property
 
86
    def url(self):
 
87
        return self.req.publisher.generate(self.context)
 
88
 
 
89
    @property
 
90
    def text(self):
 
91
        return '%s %s' % (self.context.semester.year,
 
92
                          self.context.semester.display_name)
 
93
 
 
94
 
 
95
class ProjectsBreadcrumb(object):
 
96
    """Static 'Projects' breadcrumb to precede ProjectBreadcrumb.
 
97
    context must be a ProjectSet.
 
98
    """
 
99
    def __init__(self, req, context):
 
100
        self.req = req
 
101
        self.context = context
 
102
 
 
103
    @property
 
104
    def url(self):
 
105
        return self.req.publisher.generate(self.context.offering, None,
 
106
                                           '+projects')
 
107
 
 
108
    @property
 
109
    def text(self):
 
110
        return 'Projects'
 
111
 
 
112
 
 
113
class ProjectBreadcrumb(object):
 
114
    def __init__(self, req, context):
 
115
        self.req = req
 
116
        self.context = context
 
117
 
 
118
    @property
 
119
    def url(self):
 
120
        return self.req.publisher.generate(self.context)
 
121
 
 
122
    @property
 
123
    def text(self):
 
124
        return self.context.name
 
125
 
 
126
    @property
 
127
    def extra_breadcrumbs_before(self):
 
128
        return [ProjectsBreadcrumb(self.req, self.context.project_set)]
 
129
 
 
130
 
 
131
class EnrolmentsBreadcrumb(object):
 
132
    """Static 'Enrolments' breadcrumb to precede EnrolmentBreadcrumb."""
 
133
    def __init__(self, req, context):
 
134
        self.req = req
 
135
        self.context = context
 
136
 
 
137
    @property
 
138
    def url(self):
 
139
        return self.req.publisher.generate(self.context, None, '+enrolments')
 
140
 
 
141
    @property
 
142
    def text(self):
 
143
        return 'Enrolments'
 
144
 
 
145
 
 
146
class EnrolmentBreadcrumb(object):
 
147
    def __init__(self, req, context):
 
148
        self.req = req
 
149
        self.context = context
 
150
 
 
151
    @property
 
152
    def text(self):
 
153
        return self.context.user.fullname
 
154
 
 
155
    @property
 
156
    def extra_breadcrumbs_before(self):
 
157
        return [EnrolmentsBreadcrumb(self.req, self.context.offering)]