123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- # -*- coding: utf-8 -*-
- """Main Controller"""
-
- from tg import expose, flash, require, url, lurl, request, redirect, tmpl_context
- from tg.i18n import ugettext as _, lazy_ugettext as l_
- from tg import predicates
- from pboard import model
- from pboard.controllers.secure import SecureController
- from pboard.model import DBSession, metadata
- from tgext.admin.tgadminconfig import TGAdminConfig
- from tgext.admin.controller import AdminController
-
- from pboard.lib.base import BaseController
- from pboard.controllers.error import ErrorController
-
- import pboard.model as pbm
- import pboard.controllers as pbc
- from pboard.lib import dbapi as pld
- from pboard.controllers import api as pbca
-
- __all__ = ['RootController']
-
-
- class RootController(BaseController):
- """
- The root controller for the pboard application.
-
- All the other controllers and WSGI applications should be mounted on this
- controller. For example::
-
- panel = ControlPanelController()
- another_app = AnotherWSGIApplication()
-
- Keep in mind that WSGI applications shouldn't be mounted directly: They
- must be wrapped around with :class:`tg.controllers.WSGIAppController`.
-
- """
- secc = SecureController()
- admin = AdminController(model, DBSession, config_type=TGAdminConfig)
-
- error = ErrorController()
-
- api = pbca.PODApiController()
-
- def _before(self, *args, **kw):
- tmpl_context.project_name = "pboard"
-
- @expose('pboard.templates.index')
- def index(self):
- """Handle the front-page."""
- return dict(page='index')
-
- @expose('pboard.templates.about')
- def about(self):
- """Handle the 'about' page."""
- return dict(page='about')
-
- @expose('pboard.templates.environ')
- def environ(self):
- """This method showcases TG's access to the wsgi environment."""
- return dict(page='environ', environment=request.environ)
-
- @expose('pboard.templates.data')
- @expose('json')
- def data(self, **kw):
- """This method showcases how you can use the same controller for a data page and a display page"""
- return dict(page='data', params=kw)
-
- @expose('pboard.templates.iconset')
- def iconset(self, **kw):
- """This method showcases how you can use the same controller for a data page and a display page"""
- return dict(page='data', params=kw)
-
-
- @expose('pboard.templates.index')
- @require(predicates.has_permission('manage', msg=l_('Only for managers')))
- def manage_permission_only(self, **kw):
- """Illustrate how a page for managers only works."""
- return dict(page='managers stuff')
-
- @expose('pboard.templates.index')
- @require(predicates.is_user('editor', msg=l_('Only for the editor')))
- def editor_user_only(self, **kw):
- """Illustrate how a page exclusive for the editor works."""
- return dict(page='editor stuff')
-
- @expose('pboard.templates.login')
- def login(self, came_from=lurl('/')):
- """Start the user login."""
- login_counter = request.environ.get('repoze.who.logins', 0)
- if login_counter > 0:
- flash(_('Wrong credentials'), 'warning')
- return dict(page='login', login_counter=str(login_counter),
- came_from=came_from)
-
- @expose()
- def post_login(self, came_from=lurl('/')):
- """
- Redirect the user to the initially requested page on successful
- authentication or redirect her back to the login page if login failed.
-
- """
- if not request.identity:
- login_counter = request.environ.get('repoze.who.logins', 0) + 1
- redirect('/login',
- params=dict(came_from=came_from, __logins=login_counter))
- userid = request.identity['repoze.who.userid']
- flash(_('Welcome back, %s!') % userid)
- redirect(came_from)
-
- @expose()
- def post_logout(self, came_from=lurl('/')):
- """
- Redirect the user to the initially requested page on logout and say
- goodbye as well.
-
- """
- flash(_('We hope to see you soon!'))
- redirect(came_from)
-
- @expose('pboard.templates.document')
- def document(self, node=0, came_from=lurl('/')):
- """show the user dashboard"""
- import pboard.model.data as pbmd
-
- # loRootNodeList = pbm.DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.parent_id==None).order_by(pbmd.PBNode.node_order).all()
- print "===> AAA"
- loRootNodeList = pld.buildTreeListForMenu()
- print "===> BBB"
- liNodeId = max(int(node), 1) # show node #1 if no selected node
- loCurrentNode = pbm.DBSession.query(pbmd.PBNode).filter(pbmd.PBNode.node_id==liNodeId).one()
- print "===> CCC"
- loNodeStatusList = pbmd.PBNodeStatus.getList()
- print "===> DDD"
- return dict(root_node_list=loRootNodeList, current_node=loCurrentNode, node_status_list = loNodeStatusList)
-
-
- @expose()
- def fill_treepath(self):
- """show the user dashboard"""
- import pboard.model.data as pbmd
-
- loRootNodeList = pbm.DBSession.query(pbmd.PBNode).order_by(pbmd.PBNode.parent_id).all()
- for loNode in loRootNodeList:
- if loNode.parent_id==None:
- loNode.node_depth = 0
- loNode.parent_tree_path = '/'
- else:
- loNode.node_depth = loNode._oParent.node_depth+1
- loNode.parent_tree_path = '%s%i/'%(loNode._oParent.parent_tree_path,loNode.parent_id)
-
- pbm.DBSession.flush()
-
- return
-
-
-
|