Changeset - 3380ca40cdba
[Not reviewed]
default
0 5 0
Marcin Kuzminski - 15 years ago 2010-05-22 00:51:49
marcin@python-works.com
added version generation to pylons_app and showed it into template. Propagated baseController with some data for acces into each controller. Fixed simplehg middleware to get proper name of application
5 files changed with 30 insertions and 7 deletions:
0 comments (0 inline, 0 general)
pylons_app/__init__.py
Show inline comments
 
"""
 
Hg app, a web based mercurial repository managment based on pylons
 
"""
 

	
 
VERSION = (0, 6, 0, 'beta')
 

	
 
__version__ = '.'.join((str(each) for each in VERSION[:4]))
 

	
 
def get_version():
 
    """
 
    Returns shorter version (digit parts only) as string.
 
    """
 
    return '.'.join((str(each) for each in VERSION[:3]))
pylons_app/lib/base.py
Show inline comments
 
"""The base Controller API
 

	
 
Provides the BaseController class for subclassing.
 
"""
 
from beaker.cache import cache_region
 
from pylons import config, tmpl_context as c, request, session
 
from pylons.controllers import WSGIController
 
from pylons.templating import render_mako as render
 
from pylons_app.lib.auth import LoginRequired, AuthUser
 
from pylons_app.lib.utils import get_repo_slug
 
from pylons_app.model import meta
 
from beaker.cache import cache_region
 
from pylons import tmpl_context as c
 
from pylons_app.model.hg_model import HgModel
 
from pylons_app import get_version
 

	
 
@cache_region('long_term', 'cached_repo_list')
 
def _get_repos_cached():
 
    return [rep for rep in HgModel().get_repos()]
 

	
 
class BaseController(WSGIController):
 
        
 
    def __before__(self):
 
        c.hg_app_version = get_version()
 
        c.repos_prefix = config['hg_app_name']
 
        c.repo_name = get_repo_slug(request)
 
        c.hg_app_user = session.get('hg_app_user', AuthUser())
 
        c.cached_repo_list = _get_repos_cached()
 
        self.sa = meta.Session
 
    
 
    def __call__(self, environ, start_response):
 
        """Invoke the Controller"""
 
        # WSGIController.__call__ dispatches to the Controller method
 
        # the request is routed to. This routing information is
 
        # available in environ['pylons.routes_dict']
 
        c.cached_repo_list = _get_repos_cached()
 
        self.sa = meta.Session
 
        try:
 
            return WSGIController.__call__(self, environ, start_response)
 
        finally:
 
            meta.Session.remove()
pylons_app/lib/simplehg.py
Show inline comments
 
@@ -24,13 +24,13 @@ import os
 
class SimpleHg(object):
 

	
 
    def __init__(self, application, config):
 
        self.application = application
 
        self.config = config
 
        #authenticate this mercurial request using 
 
        realm = '%s %s' % (config['repos_name'], 'mercurial repository')
 
        realm = '%s %s' % (config['hg_app_name'], 'mercurial repository')
 
        self.authenticate = AuthBasicAuthenticator(realm, authfunc)
 
        
 
    def __call__(self, environ, start_response):
 
        if not is_mercurial(environ):
 
            return self.application(environ, start_response)
 
        else:
pylons_app/templates/base/base.html
Show inline comments
 
@@ -17,13 +17,13 @@
 
        ${self.page_nav()}
 
    </div>
 
    <div id="main">
 
    	${next.main()}
 
    </div>
 
    <div class="page-footer">
 
        Mercurial App &copy; 2010
 
        Hg App ${c.hg_app_version} &copy; 2010
 
    </div>   
 

	
 
    <div id="powered-by">
 
        <p>
 
        <a href="http://mercurial.selenic.com/" title="Mercurial">
 
            <img src="/images/hglogo.png" width="75" height="90" alt="mercurial"/></a>
setup.py
Show inline comments
 
from pylons_app import get_version
 
try:
 
    from setuptools import setup, find_packages
 
except ImportError:
 
    from ez_setup import use_setuptools
 
    use_setuptools()
 
    from setuptools import setup, find_packages
 

	
 
setup(
 
    name='pylons_app',
 
    version='1.0',
 
    version=get_version(),
 
    description='',
 
    author='marcin kuzminski',
 
    author_email='marcin@python-blog.com',
 
    url='',
 
    install_requires=[
 
        "Pylons>=1.0.0",
0 comments (0 inline, 0 general)