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

1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
458 by mattgiuca
Added "tos" as an app. This app simply displays the Terms of Service
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
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
18
# Author: Matt Giuca, Will Grant
19
20
"""View to display the Terms of Service.
21
22
This is mainly for the benefit of the link in ivle.webapp.help."""
23
24
import ivle.util
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
25
import ivle.dispatch.login
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
26
from ivle.webapp.base.xhtml import XHTMLView
1092.1.28 by William Grant
Only load tos.js on /+tos.
27
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
28
29
class TermsOfServiceView(XHTMLView):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
30
    """View of the Terms of Service, allowing acceptance.
31
32
    Users with state 'no_agreement' see buttons to accept or decline.
33
    If a user has already accepted it, they just see a static page.
34
    """
35
36
    def __init__(self, req):
37
        # We need to be able to handle the case where a user has status
38
        # 'no_agreement'. In that case, req.user will be None, so we have
39
        # to get it ourselves.
40
        if req.user is None:
41
            self.user = ivle.dispatch.login.get_user_details(req)
42
            self.mode = 'accept'
43
            self.template = 'accept.html'
44
        else:
45
            self.user = req.user
46
            self.mode = 'view'
47
            self.template = 'view.html'
48
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
49
    def authorize(self, req):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
50
        # This can be used by any authenticated user, even if they haven't
51
        # accepted the ToS yet.
52
        return ivle.dispatch.login.get_user_details(req) is not None
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
53
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
54
    def populate(self, req, ctx):
55
        ctx['text'] = ivle.util.get_terms_of_service()
56
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
57
        if self.mode == 'accept':
1092.1.28 by William Grant
Only load tos.js on /+tos.
58
            self.plugin_scripts[Plugin] = ['tos.js']
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
59
            ctx['user'] = self.user
60
1092.1.28 by William Grant
Only load tos.js on /+tos.
61
class Plugin(ViewPlugin, MediaPlugin):
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
62
    """Registration for the Terms of Service plugin."""
63
    urls = [
64
        ('+tos', TermsOfServiceView),
65
    ]
1092.1.28 by William Grant
Only load tos.js on /+tos.
66
67
    media = 'media'