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

« back to all changes in this revision

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

  • Committer: David Coles
  • Date: 2010-02-24 08:19:50 UTC
  • Revision ID: coles.david@gmail.com-20100224081950-5g3w565es0dyv8aj
docs: Worksheets and Exercise developer documentation

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 semester %s' % (self.context.semester.year,
 
92
                                   self.context.semester.semester)
 
93
 
 
94
 
 
95
class ProjectsBreadcrumb(object):
 
96
    """Static 'Projects' breadcrumb to precede ProjectBreadcrumb."""
 
97
    def __init__(self, req, context):
 
98
        self.req = req
 
99
        self.context = context
 
100
 
 
101
    @property
 
102
    def url(self):
 
103
        return self.req.publisher.generate(self.context, None, '+projects')
 
104
 
 
105
    @property
 
106
    def text(self):
 
107
        return 'Projects'
 
108
 
 
109
 
 
110
class ProjectBreadcrumb(object):
 
111
    def __init__(self, req, context):
 
112
        self.req = req
 
113
        self.context = context
 
114
 
 
115
    @property
 
116
    def url(self):
 
117
        return self.req.publisher.generate(self.context)
 
118
 
 
119
    @property
 
120
    def text(self):
 
121
        return self.context.name
 
122
 
 
123
    @property
 
124
    def extra_breadcrumbs_before(self):
 
125
        return [ProjectsBreadcrumb(self.req, self.context.project_set.offering)]
 
126
 
 
127
 
 
128
class EnrolmentsBreadcrumb(object):
 
129
    """Static 'Enrolments' breadcrumb to precede EnrolmentBreadcrumb."""
 
130
    def __init__(self, req, context):
 
131
        self.req = req
 
132
        self.context = context
 
133
 
 
134
    @property
 
135
    def url(self):
 
136
        return self.req.publisher.generate(self.context, None, '+enrolments')
 
137
 
 
138
    @property
 
139
    def text(self):
 
140
        return 'Enrolments'
 
141
 
 
142
 
 
143
class EnrolmentBreadcrumb(object):
 
144
    def __init__(self, req, context):
 
145
        self.req = req
 
146
        self.context = context
 
147
 
 
148
    @property
 
149
    def text(self):
 
150
        return self.context.user.fullname
 
151
 
 
152
    @property
 
153
    def extra_breadcrumbs_before(self):
 
154
        return [EnrolmentsBreadcrumb(self.req, self.context.offering)]