Commits

jvanasco  committed b0620dd

more docs and fixes

  • Participants
  • Parent commits 3c3f8e2

Comments (0)

Files changed (10)

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/handlers/__init__.py_tmpl

     config.add_handler('main', '/{action}', '{{package}}.handlers.main:MainHandler',
         path_info=r'/(?!favicon\.ico|robots\.txt|w3c)')
 
+    config.add_static_route('{{package}}', 'static', cache_max_age=3600)

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/handlers/account.py_tmpl

 
 
 class AccountHandler(BaseHandler):
+    """
+        This AccountHander does not actually do any auth.
+        We're simply checking / setting a session value, based on routines in {{package}}.helpers
+        
+        Pyramid offers a full fledged security system with Auth & Access Control
+        You can view the full docs here:
+            http://docs.pylonsproject.org/projects/pyramid/dev/narr/security.html
+            
+
+        Pyramid's auth is outside the scope of this quickstart at this time.
+        This handler shows a much simpler example for reference only.
+
+        
+        There are a few important examples in this class:
+        
+        1. _index_ will *return* a redirect to /accout/login
+        2. _login_ behaves differently on POST than GET.  A form would likely have additional logic.
+        3. _home_ is locked down to logged in users
+        
+        Notes on function locations:
+        
+            Many people believe that helpers should be a single file used for text transformations in templates.
+            Others belive it is okay to have 'lib' style functions in it.
+        
+            Placing these reference login functions into /helpers is only done for an initial convenience to illustrate functionality.  This is not meant to advocate one mechansim over another.
+        
+        Notes on auth:
+        
+            There's no typical way to do Auth in Pylons/Pyramid.  
+
+            Many people use modules that provide most of the functionality.
+            Many people prefer a homegrown solution.
+
+            Many people integrate auth into the Base Controller logic.
+            Many people prefer to handle it in middleware.
+        
+
+            Placing these reference login functions into this controller is only done for an initial convenience to illustrate functionality.  This is not meant to advocate one mechansim over another.
+    """
 
 
 
     def index(self):
-        log.debug("testing logging; entered AccountHandler.index()")
         return HTTPFound(location='/account/login')
 
 
 
     def login(self):
-        log.debug("testing logging; entered AccountHandler.login()")
-        
         # http://docs.pylonsproject.org/projects/pyramid/dev/narr/webob.html#request
         if self.request.method == 'POST' :
             {{package}}.helpers.do_login()
             return HTTPFound(location='/account/home')
-            
         return render_to_response('/account/login/form.mako', {'project':'{{package}}'}, self.request) 
 
 
 
     def logout(self):
-        log.debug("testing logging; entered AccountHandler.logout()")
         {{package}}.helpers.do_logout()
         return HTTPFound(location='/')
 
 
     @action(renderer='/account/home.mako')
     def home(self):
-        log.debug("testing logging; entered AccountHandler.home()")
         if not {{package}}.helpers.is_logged_in() :
             return HTTPFound(location='/account/login')
         return {'project':'{{package}}'}

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/handlers/main.py_tmpl

 
     @action(renderer='default-pylons.html')
     def index(self):
+        """
+            This is the standard way to render a request.
+            * the decorator @action specifies the template to render
+            * the return function is a dict specifying the project & package
+            The logging facility is also demonstrated.
+        """
         log.debug("testing logging; entered MainHandler.index()")
         return {'project':'{{package}}'}
 
 
 
-    def index_alt(self): 
+    def index_alt(self):
+        """
+            This is an alternate view designed to show render_to_response and light query string 
+              usage.
+            Query String Usage
+              * If this is accessed without a query string, a welcome screen will appear.
+              * If this is accessed with an "old" paramter ( ie /index_alt?old=1 ) then the default 
+                Pylons screen appears.
+            render_to_response
+               * this is an alternate way to render templates.  
+               * the normal way is to decorate a method with @action or @view_config
+               * this allows for conditional templates to be used
+               * note the return function still requires a dict specifying the project & package
+            The logging facility is also demonstrated.
+        """
         log.debug("testing logging; entered MainHandler.index_alt()")
         old= self.request.params.get('old')
         if old:

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/helpers/__init__.py

 
 The template globals (``h`` et al) are set in
 ``{{package}}.subscribers.add_renderer_globals()``.
+
+
+NOTE on pyramid_sqla_quickstart functions:
+	Many people believe that helpers should be a single file used for text transformations in templates.
+    Others belive it is okay to have 'lib' style functions in it.
+        
+    Placing these reference login functions into /helpers is only done for an initial convenience to illustrate functionality.  This is not meant to advocate one mechansim over another.
+
 """
 
 #from webhelpers.html import *
 
 from pyramid.threadlocal import get_current_request
 
+
 def do_login():
+    """REFERENCE FUNCTION
+This is meant for illutration only.
+    """
     session= get_current_request().session
     session['logged_in']= True
     
+
 def do_logout():
+    """REFERENCE FUNCTION
+This is meant for illutration only.
+    """
     session= get_current_request().session
     if 'logged_in' in session :
         del session['logged_in']
 
+
 def is_logged_in():
+    """REFERENCE FUNCTION
+This is meant for illutration only.
+    """
     session= get_current_request().session
     if not session:
         return False

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/subscribers.py_tmpl

 from pyramid.exceptions import ConfigurationError
 from pyramid.url import route_url
 from pyramid.url import current_route_url
-from pyramid.i18n import get_localizer
-from pyramid.i18n import TranslationStringFactory
 
 import {{package}}.helpers as helpers
 
         tmpl_context = request.tmpl_context
         globs['c'] = tmpl_context
         globs['tmpl_context'] = tmpl_context
-        globs['_'] = request.translate
-        globs['localizer'] = request.localizer
         try:
             globs['session'] = request.session
         except ConfigurationError:
             pass
-    event.update(globs)
-
-tsf = TranslationStringFactory('{{package}}')
-
-def add_localizer(event):
-    request = event.request
-    localizer = get_localizer(request)
-    def auto_translate(string):
-        return localizer.translate(tsf(string))
-    request.localizer = localizer
-    request.translate = auto_translate
+    event.update(globs)

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/templates/@site-template.mako

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:fb="http://www.facebook.com/2008/fbml">
-<head><%include file="/@site-template-modules/html_head.mako"/></head>
+<head>
+	<!--
+		This is designed as a quick how-to with mako.
+		
+		The @ character is an RFC reserved character. It will never be used in a valid url , and makes a good prefix for support files and directories -- such as site-templates and partials / modules.
+		
+		/@site-template-modules/html_head.mako
+			some people prefer to put html head stuff into partials.
+			if you want to, here you go.  if you don't... migrate that in here.
+			the default shows a starndard way to overload ie6/7/8 stylesheets
+	-->
+	<%include file="/@site-template-modules/html_head.mako"/>
+</head>
 <body>
+	<!--
+		It's common in Rails, Django and other frameworks to push the visible header stuff - like nav bars - into their own templates.  here you go.
+	-->
 	<%include file="/@site-template-modules/header.mako"/>
 	<div class="main">
+		<!--
+			this is where mako will render the template that inherits this from
+		-->
 		${next.body()}
 	</div>
 	<div class="clearboth"></div>
+	<!--
+		standardizing a footer into a shared module is a quick way to ensure you only have to update one file
+	-->
 	<%include file="/@site-template-modules/footer.mako"/>
 </body>
 </html>

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/templates/index.mako

 <%inherit file="/@site-template.mako"/> 
 
-index
+index
+
+<p>
+	% if 0 :
+	   0
+	% else :
+		!0
+	% endif
+</p>
+
+
+<p>
+	% if 1 :
+	   1
+	% else :
+		!1
+	% endif
+</p>

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/tests.py_tmpl

-import unittest
-
-class MyHandlerTests(unittest.TestCase):
-    def setUp(self):
-        from pyramid.config import Configurator
-        import pyramid_sqla
-        self.engine = pyramid_sqla.add_engine(url='sqlite://')
-        self.session = pyramid_sqla.get_session()()
-        self.config = Configurator(autocommit=True)
-        self.config.begin()
-        # Must call ``self.config.begin()`` in tests before using config.
-
-    def tearDown(self):
-        import pyramid_sqla
-        self.config.end()
-        # After calling ``self.config.end()``, don't use config.
-        self.session = None
-        pyramid_sqla.reset()
-
-    def _makeOne(self, request):
-        from {{package}}.handlers import MainHandler
-        return MainHandler(request)
-
-    def test_index(self):
-        request = DummyRequest()
-        handler = self._makeOne(request)
-        info = handler.index()
-        self.assertEqual(info['project'], '{{package}}')
-
-class DummyRequest(object):
-    pass

File pyramid_sqla/paster_templates/pyramid_sqla_quickstart/+package+/tests/__init__.py_tmpl

+import unittest
+
+class MyHandlerTests(unittest.TestCase):
+    def setUp(self):
+        from pyramid.config import Configurator
+        import pyramid_sqla
+        self.engine = pyramid_sqla.add_engine(url='sqlite://')
+        self.session = pyramid_sqla.get_session()()
+        self.config = Configurator(autocommit=True)
+        self.config.begin()
+        # Must call ``self.config.begin()`` in tests before using config.
+
+    def tearDown(self):
+        import pyramid_sqla
+        self.config.end()
+        # After calling ``self.config.end()``, don't use config.
+        self.session = None
+        pyramid_sqla.reset()
+
+    def _makeOne(self, request):
+        from {{package}}.handlers import MainHandler
+        return MainHandler(request)
+
+    def test_index(self):
+        request = DummyRequest()
+        handler = self._makeOne(request)
+        info = handler.index()
+        self.assertEqual(info['project'], '{{package}}')
+
+class DummyRequest(object):
+    pass
 entry_points = """
     [paste.paster_create_template]
     pyramid_sqla=pyramid_sqla.paster_templates:PyramidSQLAProjectTemplate
+    pyramid_sqla_quickstart=pyramid_sqla.paster_templates:PyramidSQLAQuickstartProjectTemplate
 """
 
 setup(name='pyramid_sqla',