~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
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
29
import ivle.util
1092.1.62 by William Grant
Move the forum secret out of the main configuration file and into the forum
30
import ivle.config
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
31
32
class ForumView(XHTMLView):
33
    appname = 'forum'
34
35
    def __init__(self, req, path):
36
        self.path = path
37
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
38
    def authorize(self, req):
39
        return req.user is not None
40
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
41
    def populate(self, req, ctx):
42
        self.plugin_styles[Plugin] = ['forum.css']
1092.2.3 by William Grant
Add documentation and patches for phpBB3 integration.
43
        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
44
1099.1.81 by William Grant
Split ivle.webapp.forum.ForumView's board and topic special cases into
45
        ctx['url'] = ivle.util.make_path(os.path.join(forum_base, self.path))
46
47
class ForumBoardView(ForumView):
48
    def __init__(self, req, board):
49
        self.path = 'viewforum.php?f=' + board
50
51
class ForumTopicView(ForumView):
52
    def __init__(self, req, topic):
53
        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
54
55
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
56
    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
57
58
    login = quote(user.login)
59
    nick = quote(user.nick)
60
    email = ''
61
    if user.email != None:
62
        email = quote(user.email)
63
1101 by William Grant
Privileges (apart from admin) are now offering-local, not global.
64
    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
65
66
    hashtext = login + nick + email + role + secret
67
    hash = hashlib.md5(hashtext).hexdigest()
68
    data = quote(login + ':' + nick + ':' + email + ':' + role + ':' + hash)
69
70
    return data
71
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
72
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
73
    urls = [
74
        ('forum', ForumView, {'path': ''}),
1099.1.81 by William Grant
Split ivle.webapp.forum.ForumView's board and topic special cases into
75
        ('forum/+board/:board', ForumBoardView),
76
        ('forum/+topic/:topic', ForumTopicView),
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
77
        ('forum/*path', ForumView),
78
    ]
79
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
80
    tabs = [
81
        ('forum', 'Forum', 'Discussion boards for material relating to '
82
         'Informatics, IVLE and Python.', 'forum.png', 'forum', 4)
83
    ]
84
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
85
    cookies = {'ivleforumcookie': make_forum_cookie}
86
87
    media = 'media'