Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
mangar committed Feb 9, 2013
0 parents commit 375b062
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app.yaml
@@ -0,0 +1,21 @@
application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true


handlers:
- url: /.*
script: index.app


# libraries:
# - name: jinja2
# version: 2.6
# - name: setuptools
# version: 0.6c11


# - url: /user/.*
# script: user.app
Empty file added app/__init__.py
Empty file.
Binary file added app/__init__.pyc
Binary file not shown.
Empty file added app/controllers/__init__.py
Empty file.
Binary file added app/controllers/__init__.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions app/controllers/index.py
@@ -0,0 +1,21 @@
import webapp2
from google.appengine.ext.webapp import template

class IndexHandler(webapp2.RequestHandler):
def index(self):
# self.response.headers['Content-Type'] = 'text/plain'
# self.response.write('#oioioi %s' % "aaa")

template_values = {
'message': "Mensagem para o template.... vindo do IndexHandler..",
}


return template_values



# app = webapp2.WSGIApplication([('/', MainPage)], debug=True)



Binary file added app/controllers/index.pyc
Binary file not shown.
Empty file added app/models/__init__.py
Empty file.
Binary file added app/models/__init__.pyc
Binary file not shown.
14 changes: 14 additions & 0 deletions app/models/greeting.py
@@ -0,0 +1,14 @@
import datetime

from google.appengine.ext import db

class Greeting(db.Model):
author = db.StringProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)



def guestbook_key(guestbook_name=None):
"""Constructs a Datastore key for a Guestbook entity with guestbook_name."""
return db.Key.from_path('Guestbook', guestbook_name or 'default_guestbook')
Binary file added app/models/greeting.pyc
Binary file not shown.
73 changes: 73 additions & 0 deletions index.py
@@ -0,0 +1,73 @@
import webapp2
import os

from google.appengine.ext.webapp import template


BASE_CONTROLLER_DIR = "app.controllers"
EXT_ACTION = ".jhtml"

TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'templates')


#
# Ex.:
# /admin --> from app.controllers.admin import index // chama o metodo index
# /admin/cidades --> from app.controllers.admin.cidades import index // chama o metodo index
# /admin/cidades/salvar.jhtml --> from app.controllers.admin.cidades import index // chama o metodo salvar
#
#
def import_from_statement(self):
_from = BASE_CONTROLLER_DIR
_import = "index"

url_split = self.request.path.split('/')
if not self.request.path == "/": # pacote padrao(index) e action padrao (index)
# _from = _from + "index"
# _import = "index"

# else:
for s in url_split:
if s:
if not(s.endswith(EXT_ACTION)):
_from += ("." + s)
else:
_import = s.replace(EXT_ACTION, "")

return "from " + _from + " import " + _import





class Handler(webapp2.RequestHandler):
def get(self):

template_values2 = {}

# exec_import = import_from()

path = self.request.path
if path == '/':
exec "from app.controllers import %s" % "index"
exec "template_values2 = index.IndexHandler(self.request, self.response).index()"



template_values2['a'] = self.request.path
template_values2['import_from'] = import_from_statement(self)

path = os.path.join(TEMPLATE_DIR, 'index.html')
self.response.out.write(template.render(path, template_values2))

# else:
# self.response.headers['Content-Type'] = 'text/plain'
# self.response.write('BE Handler %s' % path)



url_map = [ ('/.*', Handler),]


app = webapp2.WSGIApplication(url_map, debug=True)

Binary file added index.pyc
Binary file not shown.
40 changes: 40 additions & 0 deletions jinja2.py
@@ -0,0 +1,40 @@
import webapp2
import os
import jinja2


# jinja_environment = jinja2.Environment(
# loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

# jinja_environment = jinja2.Environment(autoescape = True,
# loader = jinja2.FileSystemLoader(os.path.dirname(__file__), 'templates'))


class MainPage(webapp2.RequestHandler):
def get(self):


# guestbook_name=self.request.get('guestbook_name')
# greetings_query = Greeting.all().ancestor(
# guestbook_key(guestbook_name)).order('-date')
# greetings = greetings_query.fetch(10)

# if users.get_current_user():
# url = users.create_logout_url(self.request.uri)
# url_linktext = 'Logout'
# else:
# url = users.create_login_url(self.request.uri)
# url_linktext = 'Login'

# template_values = {
# 'greetings': greetings,
# 'url': url,
# 'url_linktext': url_linktext,
# }

template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))




Binary file added jinja2.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions templates/index.html
@@ -0,0 +1,13 @@
<html>
<body>
<b>Referência</b> <br> <a href="https://developers.google.com/appengine/docs/python/gettingstarted/templates">https://developers.google.com/appengine/docs/python/gettingstarted/templates</a> <br>
<pre>
{{message}}
</pre>
<hr>
<b>import_from:</b> <br>{{import_from}}
<hr>
<b>a:</b> <br> {{a}}
<hr>
</body>
</html>
Binary file added user.pyc
Binary file not shown.

0 comments on commit 375b062

Please sign in to comment.