Permalink
Browse files

Merge branch 'python27'

  • Loading branch information...
2 parents 1da3f3a + c4e4fd4 commit b83af4afabfcae007cf3230d5c36f80d5ce22470 @troberti committed Nov 22, 2011
View
@@ -1,22 +1,31 @@
application: firiplanning
-version: production
-runtime: python
+version: py27
+runtime: python27
api_version: 1
+threadsafe: yes
builtins:
- appstats: on
+libraries:
+- name: jinja2
+ version: "2.6"
+- name: markupsafe
+ version: "0.15"
+- name: setuptools
+ version: "0.6c11"
+
handlers:
- url: /images
static_dir: images
- url: /css
static_dir: css
- url: /mapreduce(/.*)?
- script: mapreduce/main.py
+ script: mapreduce.main.APP
login: admin
- url: /workers/.*
- script: workers.py
+ script: workers.application
login: admin
- url: /.*
login: required
- script: main.py
+ script: main.application
View
@@ -12,12 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""
-Selects the correct Django library version (1.2) for all wsgi_apps
-"""
-from google.appengine.dist import use_library
-use_library('django', '1.2')
-
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = recording.appstats_wsgi_middleware(app)
@@ -29,7 +29,7 @@
import Cookie
from time import strftime
-from django.utils import simplejson
+import json as simplejson
# settings
try:
@@ -43,7 +43,8 @@
from google.appengine.ext import db
from google.appengine.api import memcache
-from django.utils import simplejson
+# EDIT(tijmen): As simplejson is not available anymore
+import json as simplejson
# settings
try:
View
69 main.py
@@ -14,12 +14,10 @@
import os
import logging
-from google.appengine.ext import webapp
-from google.appengine.ext.webapp import template
-from google.appengine.ext.webapp.util import run_wsgi_app
+import webapp2 as webapp
+import jinja2
from google.appengine.ext import db
from appengine_utilities.sessions import Session
-
from model import Task, Context, Domain, User
import api
@@ -79,23 +77,26 @@ def _task_template_values(tasks, user, level=0):
for task in tasks]
-def render_template(file, template_values):
- """
- Renders the template specified through file passing the given
- template_values.
+class BaseHandler(webapp.RequestHandler):
+ @webapp2.cached_property
+ def jinja2(self):
+ return jinja2.get_jinja2(app=self.app)
- Args:
- file: relative path of the template file
- template_values: dictionary of template values
+ def render_template(file, template_values):
+ """
+ Renders the template specified through file passing the given
+ template_values.
- Returns:
- A string containing the rendered template.
- """
- path = os.path.join(os.path.dirname(__file__), file)
- return template.render(path, template_values)
+ Args:
+ file: relative path of the template file
+ template_values: dictionary of template values
+ Returns:
+ A string containing the rendered template.
+ """
+ self.response.write(self.jinja2.render_template(file, template_values))
-class Landing(webapp.RequestHandler):
+class Landing(BaseHandler):
"""
The main landing page. Shows the users domains and links to them.
"""
@@ -111,9 +112,7 @@ def get(self):
for domain in domains],
'messages': get_and_delete_messages(session),
}
- path = os.path.join(os.path.dirname(__file__),
- 'templates/landing.html')
- self.response.out.write(template.render(path, template_values))
+ render_template('landing.html', template_values)
class Overview(webapp.RequestHandler):
@@ -165,8 +164,7 @@ def get(self, domain_identifier):
'no_tasks_message': no_tasks_message,
'view_mode': view,
}
- self.response.out.write(render_template('templates/overview.html',
- template_values))
+ render_template('overview.html', template_values)
class TaskDetail(webapp.RequestHandler):
@@ -230,8 +228,7 @@ def get(self, domain_identifier, task_identifier):
'subtasks_heading': subtasks_heading,
'no_subtasks_description': no_subtasks_description,
}
- self.response.out.write(render_template('templates/taskdetail.html',
- template_values))
+ render_template('taskdetail.html', template_values)
class GetSubTasks(webapp.RequestHandler):
@@ -291,8 +288,7 @@ def get(self):
'view_mode': view,
'show_radio_buttons': show_radio_buttons,
}
- self.response.out.write(render_template('templates/get-subtasks.html',
- template_values))
+ render_template('get-subtasks.html', template_values)
class TaskEditView(webapp.RequestHandler):
@@ -339,8 +335,7 @@ def get(self, domain_identifier, task_identifier):
'show_radio_buttons': True,
'view_mode': 'all',
}
- self.response.out.write(render_template('templates/edittask.html',
- template_values))
+ render_template('edittask.html', template_values)
class CreateTask(webapp.RequestHandler):
@@ -532,7 +527,14 @@ def post(self):
_TASK_URL = '%s/task/(%s)/?' % (_DOMAIN_URL, _VALID_TASK_KEY_NAME)
_TASK_EDIT_URL = "%s/edit/?" % (_TASK_URL,)
-webapp.template.register_template_library('templatetags.templatefilters')
+
+config = {
+ 'webapp2_extras.jinja2': {
+ 'filters': {
+ 'markdown': templatetags.templatefilters.markdown
+ }
+ }
+ }
application = webapp.WSGIApplication([('/create-task', CreateTask),
('/set-task-completed', CompleteTask),
@@ -546,10 +548,5 @@ def post(self):
(_DOMAIN_OPEN, Overview),
(_TASK_EDIT_URL, TaskEditView),
(_TASK_URL, TaskDetail),
- ('/', Landing)])
-
-def main():
- run_wsgi_app(application)
-
-if __name__ == "__main__":
- main()
+ ('/', Landing)],
+ config=config)
View
@@ -17,7 +17,7 @@
"""
import copy
from google.appengine.ext import db
-import simplejson as json
+import json
import aetycoon
class Domain(db.Model):
Oops, something went wrong.

0 comments on commit b83af4a

Please sign in to comment.