changeset 185:3380ca40cdba

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
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 00:51:49 +0200
parents 2fc206a32ef0
children 556473ba0399
files pylons_app/__init__.py pylons_app/lib/base.py pylons_app/lib/simplehg.py pylons_app/templates/base/base.html setup.py
diffstat 5 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/__init__.py	Fri May 21 23:52:18 2010 +0200
+++ b/pylons_app/__init__.py	Sat May 22 00:51:49 2010 +0200
@@ -0,0 +1,13 @@
+"""
+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]))
--- a/pylons_app/lib/base.py	Fri May 21 23:52:18 2010 +0200
+++ b/pylons_app/lib/base.py	Sat May 22 00:51:49 2010 +0200
@@ -2,26 +2,35 @@
 
 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:
--- a/pylons_app/lib/simplehg.py	Fri May 21 23:52:18 2010 +0200
+++ b/pylons_app/lib/simplehg.py	Sat May 22 00:51:49 2010 +0200
@@ -27,7 +27,7 @@
         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):
--- a/pylons_app/templates/base/base.html	Fri May 21 23:52:18 2010 +0200
+++ b/pylons_app/templates/base/base.html	Sat May 22 00:51:49 2010 +0200
@@ -20,7 +20,7 @@
     	${next.main()}
     </div>
     <div class="page-footer">
-        Mercurial App &copy; 2010
+        Hg App ${c.hg_app_version} &copy; 2010
     </div>   
 
     <div id="powered-by">
--- a/setup.py	Fri May 21 23:52:18 2010 +0200
+++ b/setup.py	Sat May 22 00:51:49 2010 +0200
@@ -1,3 +1,4 @@
+from pylons_app import get_version
 try:
     from setuptools import setup, find_packages
 except ImportError:
@@ -7,7 +8,7 @@
 
 setup(
     name='pylons_app',
-    version='1.0',
+    version=get_version(),
     description='',
     author='marcin kuzminski',
     author_email='marcin@python-blog.com',