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

1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
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.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
18
# Author: David Coles, Will Grant
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
19
20
import os
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
21
import re
22
import time
23
import hashlib
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
24
import urlparse
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
25
from urllib import quote
26
27
from ivle.webapp.base.xhtml import XHTMLView
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
28
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
1092.1.62 by William Grant
Move the forum secret out of the main configuration file and into the forum
29
import ivle.config
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
30
31
class ForumView(XHTMLView):
1116 by William Grant
Move the old tutorial views into the 'subjects' tab, so they get the right
32
    tab = 'forum'
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
33
34
    def __init__(self, req, path):
35
        self.path = path
36
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
37
    def authorize(self, req):
38
        return req.user is not None
39
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
40
    def populate(self, req, ctx):
41
        self.plugin_styles[Plugin] = ['forum.css']
1092.2.3 by William Grant
Add documentation and patches for phpBB3 integration.
42
        forum_base = req.config.plugin_configs[Plugin]['base']
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
43
1210 by William Grant
Use Request.make_path everywhere.
44
        ctx['url'] = req.make_path(os.path.join(forum_base, self.path))
1099.1.81 by William Grant
Split ivle.webapp.forum.ForumView's board and topic special cases into
45
46
class ForumBoardView(ForumView):
47
    def __init__(self, req, board):
48
        self.path = 'viewforum.php?f=' + board
49
50
class ForumTopicView(ForumView):
51
    def __init__(self, req, topic):
52
        self.path = 'viewtopic.php?t=' + topic
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
53
54
def make_forum_cookie(user):
1092.1.62 by William Grant
Move the forum secret out of the main configuration file and into the forum
55
    secret = ivle.config.Config().plugin_configs[Plugin]['secret']
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
56
57
    login = quote(user.login)
58
    nick = quote(user.nick)
59
    email = ''
60
    if user.email != None:
61
        email = quote(user.email)
62
1101 by William Grant
Privileges (apart from admin) are now offering-local, not global.
63
    role = 'admin' if user.admin else 'student' # XXX
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
64
65
    hashtext = login + nick + email + role + secret
66
    hash = hashlib.md5(hashtext).hexdigest()
67
    data = quote(login + ':' + nick + ':' + email + ':' + role + ':' + hash)
68
69
    return data
70
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
71
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
72
    urls = [
73
        ('forum', ForumView, {'path': ''}),
1099.1.81 by William Grant
Split ivle.webapp.forum.ForumView's board and topic special cases into
74
        ('forum/+board/:board', ForumBoardView),
75
        ('forum/+topic/:topic', ForumTopicView),
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
76
        ('forum/*path', ForumView),
77
    ]
78
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
79
    tabs = [
80
        ('forum', 'Forum', 'Discussion boards for material relating to '
81
         'Informatics, IVLE and Python.', 'forum.png', 'forum', 4)
82
    ]
83
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
84
    cookies = {'ivleforumcookie': make_forum_cookie}
85
86
    media = 'media'