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

1294.2.89 by William Grant
Add an Offering breadcrumb.
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
1472 by William Grant
Add a 'Users' breadcrumb.
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
1294.2.96 by William Grant
Add a UserBreadcrumb.
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):
1294.2.118 by William Grant
Merge from object-publishing.
36
        return self.req.publisher.generate(self.context)
1294.2.96 by William Grant
Add a UserBreadcrumb.
37
38
    @property
39
    def text(self):
1684 by Matt Giuca
Breadcrumb now shows user's nickname on user page only if the current user is authorised to view that user. Otherwise, shows login. (Previously showed the nickname always, which is a minor information disclosure). Fixes Launchpad bug #493919.
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
1294.2.96 by William Grant
Add a UserBreadcrumb.
47
1472 by William Grant
Add a 'Users' breadcrumb.
48
    @property
49
    def extra_breadcrumbs_before(self):
50
        return [UsersBreadcrumb()]
51
52
1683 by Matt Giuca
Added breadcrumb for Subjects page (previously each subject had its own top-level breadcrumb).
53
class SubjectsBreadcrumb(object):
54
    @property
55
    def url(self):
56
        return '/subjects'
57
58
    @property
59
    def text(self):
60
        return 'Subjects'
61
1294.2.94 by William Grant
Add a SubjectBreadcrumb.
62
class SubjectBreadcrumb(object):
63
    def __init__(self, req, context):
64
        self.req = req
65
        self.context = context
66
67
    @property
1678.1.1 by Matt Giuca
Added new view SubjectView, which shows all offerings for a subject. This is accessible from the SubjectsManage view, or by the subject name in the breadcrumbs.
68
    def url(self):
69
        return self.req.publisher.generate(self.context)
70
71
    @property
1294.2.94 by William Grant
Add a SubjectBreadcrumb.
72
    def text(self):
73
        return self.context.name
74
1683 by Matt Giuca
Added breadcrumb for Subjects page (previously each subject had its own top-level breadcrumb).
75
    @property
76
    def extra_breadcrumbs_before(self):
77
        return [SubjectsBreadcrumb()]
78
1472 by William Grant
Add a 'Users' breadcrumb.
79
1294.2.89 by William Grant
Add an Offering breadcrumb.
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):
1294.2.118 by William Grant
Merge from object-publishing.
87
        return self.req.publisher.generate(self.context)
1294.2.89 by William Grant
Add an Offering breadcrumb.
88
89
    @property
90
    def text(self):
1822.1.1 by William Grant
Replace semester.semester with semester.{code,url_name,display_name}.
91
        return '%s %s' % (self.context.semester.year,
92
                          self.context.semester.display_name)
1294.2.89 by William Grant
Add an Offering breadcrumb.
93
1472 by William Grant
Add a 'Users' breadcrumb.
94
1616 by William Grant
Add a Projects breadcrumb.
95
class ProjectsBreadcrumb(object):
1710 by Matt Giuca
Project set page: Added 'Projects' breadcrumb, consistent with offering projects page. Fixes Launchpad bug #493913.
96
    """Static 'Projects' breadcrumb to precede ProjectBreadcrumb.
97
    context must be a ProjectSet.
98
    """
1616 by William Grant
Add a Projects breadcrumb.
99
    def __init__(self, req, context):
100
        self.req = req
101
        self.context = context
102
103
    @property
104
    def url(self):
1710 by Matt Giuca
Project set page: Added 'Projects' breadcrumb, consistent with offering projects page. Fixes Launchpad bug #493913.
105
        return self.req.publisher.generate(self.context.offering, None,
106
                                           '+projects')
1616 by William Grant
Add a Projects breadcrumb.
107
108
    @property
109
    def text(self):
110
        return 'Projects'
111
112
1294.2.98 by William Grant
Add a ProjectBreadcrumb.
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):
1294.2.118 by William Grant
Merge from object-publishing.
120
        return self.req.publisher.generate(self.context)
1294.2.98 by William Grant
Add a ProjectBreadcrumb.
121
122
    @property
123
    def text(self):
124
        return self.context.name
125
1616 by William Grant
Add a Projects breadcrumb.
126
    @property
127
    def extra_breadcrumbs_before(self):
1710 by Matt Giuca
Project set page: Added 'Projects' breadcrumb, consistent with offering projects page. Fixes Launchpad bug #493913.
128
        return [ProjectsBreadcrumb(self.req, self.context.project_set)]
1616 by William Grant
Add a Projects breadcrumb.
129
1615 by William Grant
Add breadcrumbs for enrolments.
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)]