Created
          October 10, 2013 07:07 
        
      - 
      
 - 
        
Save rob-b/6914238 to your computer and use it in GitHub Desktop.  
    pyramid_jinja2 doesn't easily work with appengine; here's the changes needed
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | commit ae9c6a6dc96897d6d82db20bfca68df813f5dabb | |
| Author: Rob Berry | |
| Date: Thu Oct 10 08:00:02 2013 +0100 | |
| Add pyramid_jinja2 | |
| diff --git a/buildout.cfg b/buildout.cfg | |
| index 2510ba1..367938f 100644 | |
| --- a/buildout.cfg | |
| +++ b/buildout.cfg | |
| @@ -47,6 +47,7 @@ packages= | |
| prettyexc | |
| deform | |
| + pyramid-jinja2 | |
| server-script = dev_appserver | |
| zip-packages = False | |
| diff --git a/src/app.yaml b/src/app.yaml | |
| index 6f60390..f4ace9c 100644 | |
| --- a/src/app.yaml | |
| +++ b/src/app.yaml | |
| @@ -27,4 +27,6 @@ libraries: | |
| version: latest | |
| - name: ssl | |
| version: latest | |
| +- name: jinja2 | |
| + version: latest | |
| diff --git a/src/development.ini b/src/development.ini | |
| index 8ed3f66..8290ab5 100644 | |
| --- a/src/development.ini | |
| +++ b/src/development.ini | |
| @@ -22,6 +22,11 @@ project3.apns_sandbox = true | |
| project3.apns_cert = apns-dev.pem | |
| project3.bucket = some-bucket-name | |
| +# cannot write to the filesystem in appengine | |
| +jinja2.bytecode_caching = false | |
| +jinja2.directories = project3:templates | |
| + | |
| + | |
| # By default, the toolbar only appears for clients from IP addresses | |
| # '127.0.0.1' and '::1'. | |
| # debugtoolbar.hosts = 127.0.0.1 ::1 | |
| diff --git a/src/project3/__init__.py b/src/project3/__init__.py | |
| index e759005..754cb2c 100644 | |
| --- a/src/project3/__init__.py | |
| +++ b/src/project3/__init__.py | |
| @@ -1,6 +1,7 @@ | |
| from pyramid.config import Configurator | |
| from pyramid.security import unauthenticated_userid | |
| from pyramid.authorization import ACLAuthorizationPolicy | |
| +from pyramid_jinja2 import renderer_factory | |
| from sqlalchemy import engine_from_config | |
| from .viewmapper import ViewMapper | |
| from .security import sessionfinder | |
| @@ -58,6 +59,10 @@ def main(global_config, **settings): | |
| config = Configurator(settings=settings, default_view_mapper=ViewMapper, | |
| root_factory='project3.models.RootFactory') | |
| + # jinja2 for html templates | |
| + config.include('pyramid_jinja2') | |
| + config.add_renderer('.html', renderer_factory) | |
| + | |
| # auth (both kinds) | |
| config.set_authentication_policy(authn_policy) | |
| config.set_authorization_policy(authz_policy) | |
| @@ -97,6 +102,19 @@ def application(*args): | |
| google.__path__.append(os.path.join(root, 'google')) | |
| sys.path.insert(0, root) | |
| + class main(object): | |
| + """appengine imports don't work like normal python imports | |
| + | |
| + long story short; this lets us use pyramid_jinja2 | |
| + (http://stackoverflow.com/a/18074353)""" | |
| + | |
| + def __init__(self, name): | |
| + sys.modules[name] = self | |
| + | |
| + def __getattr__(self, name): | |
| + return globals()[name] | |
| + main('__main__') | |
| + | |
| root = os.path.dirname(os.path.dirname(__file__)) | |
| config_file = 'production.ini' | |
| if os.environ.get('SERVER_SOFTWARE', '').startswith('Development'): | |
| diff --git a/src/setup.py b/src/setup.py | |
| index 78898c7..e97ace0 100644 | |
| --- a/src/setup.py | |
| +++ b/src/setup.py | |
| @@ -31,6 +31,7 @@ requires = [ | |
| 'deform', | |
| + 'pyramid_jinja2', | |
| ] | |
| setup(name='project3', | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment