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

« back to all changes in this revision

Viewing changes to ivle/webapp/tos/__init__.py

Merge from new-dispatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
This is mainly for the benefit of the link in ivle.webapp.help."""
23
23
 
24
24
import ivle.util
 
25
import ivle.dispatch.login
25
26
from ivle.webapp.base.xhtml import XHTMLView
26
27
from ivle.webapp.base.plugins import ViewPlugin
27
28
 
28
29
class TermsOfServiceView(XHTMLView):
29
 
    """Static view of the Terms of Service."""
 
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
 
30
49
    def authorize(self, req):
31
 
        return req.user is not None
 
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
32
53
 
33
54
    def populate(self, req, ctx):
34
55
        ctx['text'] = ivle.util.get_terms_of_service()
35
56
 
 
57
        if self.mode == 'accept':
 
58
            ctx['user'] = self.user
 
59
 
36
60
class Plugin(ViewPlugin):
37
61
    """Registration for the Terms of Service plugin."""
38
62
    urls = [