Use Django dispatcher instead of CherryPy dispatcher

This commit is big because anything small breaks the code.

- Django dispatcher is based on regular expressions and does not need a tree structure
- Reduces a lot of unnecessary dependencies among modules
- Use Django sessions middlewear instead of CherryPy sessions
- Introduce dependency based modules instead of numeric load order
- Remove PagePlugin and simply use Django views
- Eliminate page rendering wrappers in favor of Django context processors
- Use custom auth for now until replaced by Django auth middlewear
- Use Django templated 404 and 500 error pages
This commit is contained in:
Sunil Mohan Adapa committed 2014-06-12 23:33:25 +05:30
1 parent 657bb11bbc
commit 58d13e3ed8
42 files changed
+1281 -1289

No files matched your search

+2 -2
View File
@@ -20,6 +20,6 @@ Plinth module for help pages
"""
from . import help # pylint: disable-msg=W0622
from .help import init
__all__ = ['help']
__all__ = ['help', 'init']
+30 -39
View File
@@ -1,49 +1,40 @@
import os
import cherrypy
from gettext import gettext as _
from plugin_mount import PagePlugin
from django.template.response import TemplateResponse
import cfg
import util
class Help(PagePlugin):
order = 20 # order of running init in PagePlugins
def __init__(self):
super(Help, self).__init__()
self.register_page("help")
self.menu = cfg.main_menu.add_item(_("Documentation"), "icon-book", "/help", 101)
self.menu.add_item(_("Where to Get Help"), "icon-search", "/help/index", 5)
self.menu.add_item(_("Developer's Manual"), "icon-info-sign", "/help/view/plinth", 10)
self.menu.add_item(_("FAQ"), "icon-question-sign", "/help/view/faq", 20)
self.menu.add_item(_("%s Wiki" % cfg.box_name), "icon-pencil", "http://wiki.debian.org/FreedomBox", 30)
self.menu.add_item(_("About"), "icon-star", "/help/about", 100)
@cherrypy.expose
def index(self):
return util.render_template(template='help',
title=_('Documentation and FAQ'))
@cherrypy.expose
def about(self):
return util.render_template(
template='about',
title=_('About the {box_name}').format(box_name=cfg.box_name))
def init():
"""Initialize the Help module"""
menu = cfg.main_menu.add_item(_('Documentation'), 'icon-book', '/help',
101)
menu.add_item(_("Where to Get Help"), "icon-search", "/help/index", 5)
menu.add_item(_('Developer\'s Manual'), 'icon-info-sign',
'/help/view/plinth', 10)
menu.add_item(_('FAQ'), 'icon-question-sign', '/help/view/faq', 20)
menu.add_item(_('%s Wiki' % cfg.box_name), 'icon-pencil',
'http://wiki.debian.org/FreedomBox', 30)
menu.add_item(_('About'), 'icon-star', '/help/about', 100)
class View(PagePlugin):
def __init__(self):
super(View, self).__init__()
def index(request):
"""Serve the index page"""
return TemplateResponse(request, 'help.html',
{'title': _('Documentation and FAQ')})
self.register_page("help.view")
@cherrypy.expose
def default(self, page=''):
if page not in ['design', 'plinth', 'hacking', 'faq']:
raise cherrypy.HTTPError(404, "The path '/help/view/%s' was not found." % page)
def about(request):
"""Serve the about page"""
title = _('About the {box_name}').format(box_name=cfg.box_name)
return TemplateResponse(request, 'about.html', {'title': title})
with open(os.path.join("doc", "%s.part.html" % page), 'r') as IF:
main = IF.read()
return util.render_template(title=_("%s Documentation" %
cfg.product_name), main=main)
def default(request, page=''):
"""Serve the documentation pages"""
with open(os.path.join('doc', '%s.part.html' % page), 'r') as input_file:
main = input_file.read()
title = _('%s Documentation') % cfg.product_name
return TemplateResponse(request, 'login_nav.html',
{'title': title, 'main': main})