class RootController(WsgiDispatchController): """ The root controller for the allura 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`. """ auth = AuthController() error = ErrorController() nf = NewForgeController() nf.admin = SiteAdminController() search = SearchController() rest = RestController() def __init__(self): n_url_prefix = '/%s/' % request.path.split('/')[1] n = M.Neighborhood.query.get(url_prefix=n_url_prefix) if n and not n.url_prefix.startswith('//'): n.bind_controller(self) self.browse = ProjectBrowseController() self.allura_sitemap = SitemapIndexController() super(RootController, self).__init__() def _setup_request(self): c.project = c.app = None c.memoize_cache = {} c.user = plugin.AuthenticationProvider.get( request).authenticate_request() assert c.user is not None, 'c.user should always be at least User.anonymous()' def _cleanup_request(self): pass @expose('jinja:allura:templates/project_list.html') @with_trailing_slash def index(self, **kw): """Handle the front-page.""" c.project_summary = W.project_summary projects = M.Project.query.find( dict(is_root=True, is_nbhd_project=False, deleted=False)).sort('shortname').all() neighborhoods = M.Neighborhood.query.find().sort('name') psort = [(n, [p for p in projects if p.neighborhood_id == n._id]) for n in neighborhoods] categories = M.ProjectCategory.query.find({ 'parent_id': None }).sort('name').all() c.custom_sidebar_menu = [ SitemapEntry(cat.label, '/browse/' + cat.name) for cat in categories ] return dict(projects=psort, title="All Projects", text=None)
class RootController(WsgiDispatchController): """ The root controller for the allura 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`. """ auth = AuthController() error = ErrorController() nf = NewForgeController() search = SearchController() rest = RestController() categories = TroveCategoryController() def __init__(self): n_url_prefix = '/%s/' % request.path.split('/')[1] n = g.neighborhood_cache.get(n_url_prefix) if n and not n.url_prefix.startswith('//'): n.bind_controller(self) self.browse = ProjectBrowseController() self.nf.admin = SiteAdminController() super(RootController, self).__init__() def _setup_request(self): c.project = c.app = None c.user = plugin.AuthenticationProvider.get( request).authenticate_request() assert c.user is not None, ( 'c.user should always be at least User.anonymous(). ' 'Did you run `paster setup-app` to create the database?') if not c.user.is_anonymous(): c.user.track_active(request) if asbool(config.get('force_ssl.logged_in')): session.secure = True def _cleanup_request(self): pass @expose('jinja:allura:templates/neighborhood_list.html') @with_trailing_slash def index(self, **kw): """Handle the front-page.""" neighborhoods = M.Neighborhood.query.find().sort('name') categories = M.ProjectCategory.query.find({ 'parent_id': None }).sort('name').all() c.custom_sidebar_menu = [ SitemapEntry(cat.label, '/browse/' + cat.name) for cat in categories ] return dict(neighborhoods=neighborhoods, title="All Neighborhoods")
class HostNeighborhoodController(WsgiDispatchController, NeighborhoodController): '''Neighborhood controller with support for use as a root controller, for instance, when using adobe.sourceforge.net (if this is allowed). ''' auth = AuthController() error = ErrorController() nf = NewForgeController() search = SearchController()
class RootController(WsgiDispatchController): """ The root controller for the allura 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`. When testing the root, BasetestProjectRootController should be considered as the root controller """ auth = AuthController() error = ErrorController() nf = NewForgeController() search = SearchController() rest = RestController() categories = TroveCategoryController() dashboard = DashboardController() browse = ProjectBrowseController() def __init__(self): super(RootController, self).__init__() self.nf.admin = SiteAdminController() @expose() def _lookup(self, nbhd_mount, *remainder): n_url_prefix = '/%s/' % nbhd_mount n = self._lookup_neighborhood(n_url_prefix) if n and not n.url_prefix.startswith('//'): return NeighborhoodController(n), remainder else: raise exc.HTTPNotFound def _lookup_neighborhood(self, url_prefix): n = M.Neighborhood.query.get(url_prefix=url_prefix) return n def _setup_request(self): c.project = c.app = None c.user = plugin.AuthenticationProvider.get( request).authenticate_request() assert c.user is not None, ( 'c.user should always be at least User.anonymous(). ' 'Did you run `paster setup-app` to create the database?') if not c.user.is_anonymous(): c.user.track_active(request) if asbool(config.get('force_ssl.logged_in')): session.secure = True # Make sure the page really isn't cached (not accessible by back button, etc) # pylons.configuration defaults to "no-cache" only. # See also http://blog.55minutes.com/2011/10/how-to-defeat-the-browser-back-button-cache/ and # https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en#defining_optimal_cache-control_policy response.headers[str('Cache-Control')] = str( 'no-cache, no-store, must-revalidate') @expose() @with_trailing_slash def index(self, **kw): """Handle the front-page.""" if not c.user.is_anonymous(): redirect('/dashboard') else: redirect('/neighborhood') @expose('jinja:allura:templates/neighborhood_list.html') def neighborhood(self, **kw): neighborhoods = M.Neighborhood.query.find().sort('name') categories = M.ProjectCategory.query.find({ 'parent_id': None }).sort('name').all() c.custom_sidebar_menu = [ SitemapEntry(cat.label, '/browse/' + cat.name) for cat in categories ] return dict(neighborhoods=neighborhoods, title="All Neighborhoods")