Browse files

Merge branch 'master' of https://github.com/mangar/gae_py

  • Loading branch information...
2 parents 0b0bb58 + 1a7a63d commit 0d4f108dfc94dfee3673b05c001667347ed3d878 @mangar committed Feb 10, 2013
View
0 config/__init__.py
No changes.
View
12 config/config.py
@@ -1,12 +0,0 @@
-import os
-
-class Config(object):
-
-
- BASE_CONTROLLER_DIR = "app.controllers"
- EXT_ACTION = ".jhtml"
- TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), '../templates')
-
-
- def __init__(self):
- super(Config, self).__init__()
View
52 index.py
@@ -3,10 +3,41 @@
from google.appengine.ext.webapp import template
-from config.config import Config
-from lib.gae_py.controllers.from_import_statement import FromImportStatement
-from lib.gae_py.controllers.method_to_call import MethodToCall
-from lib.gae_py.controllers.template_file import TemplateFile
+
+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):
@@ -21,14 +52,19 @@ def get(self):
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'] = FromImportStatement(self.request).from_import_statement()
- template_values2['method_to_call'] = MethodToCall(self.request).method_to_call()
- template_values2['template_file'] = TemplateFile(self.request).template_file()
+ template_values2['import_from'] = import_from_statement(self)
- path = os.path.join(Config.TEMPLATE_DIR, 'index.html')
+ 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),]
View
0 lib/__init__.py
No changes.
View
0 lib/gae_py/__init__.py
No changes.
View
0 lib/gae_py/controllers/__init__.py
No changes.
View
36 lib/gae_py/controllers/from_import_statement.py
@@ -1,36 +0,0 @@
-
-from config.config import Config
-
-#
-#
-class FromImportStatement(object):
-
- def __init__(self, request):
- super(FromImportStatement, self).__init__()
- self.request = request
-
-
- #
- # Ex.:
- #
- # /admin --> from app.controllers.admin import index
- # /admin/cidades --> from app.controllers.admin.cidades import index
- # /admin/cidades/salvar.jhtml --> from app.controllers.admin.cidades import index
- # /admin/cidades/crud_salvar.jhtml --> from app.controllers.admin.cidades import crud
- #
- def from_import_statement(self):
- _from = Config.BASE_CONTROLLER_DIR
- _import = "index"
-
- url_split = self.request.path.split('/')
- if not self.request.path == "/": # pacote padrao(index) e action padrao (index)
- for s in url_split:
- if s:
- if not(s.endswith(Config.EXT_ACTION)):
- _from += ("." + s)
- else:
- if s.find("_") > 0:
- _import = s.split("_")[0]
-
-
- return "from " + _from + " import " + _import
View
31 lib/gae_py/controllers/method_to_call.py
@@ -1,31 +0,0 @@
-from config.config import Config
-
-#
-#
-#
-class MethodToCall(object):
-
- def __init__(self, request):
- super(MethodToCall, self).__init__()
- self.request = request
-
-
- #
- # 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
- # /admin/cidades/crud_salvar.jhtml --> from app.controllers.admin.cidades import crud // chama o metodo salvar
- #
- def method_to_call(self):
- _method = "index"
- url = self.request.path
-
- if url.endswith(Config.EXT_ACTION):
- _method = url[url.rfind("/")+1:]
-
- if _method.count("_") >= 1:
- _method = _method[_method.find("_")+1:]
-
- return _method.replace(Config.EXT_ACTION, "")
View
35 lib/gae_py/controllers/template_file.py
@@ -1,35 +0,0 @@
-from config.config import Config
-
-#
-#
-#
-class TemplateFile(object):
-
- def __init__(self, request):
- super(TemplateFile, self).__init__()
- self.request = request
-
-
- #
- # Ex.:
- #
- # /admin --> TEMPLATE_DIR/admin/index.html
- # /admin/cidades --> TEMPLATE_DIR/admin/cidades/index.html
- # /admin/cidades/salvar.jhtml --> TEMPLATE_DIR/admin/cidades/salvar.html
- # /admin/cidades/crud_salvar.jhtml --> TEMPLATE_DIR/admin/cidades/crud_salvar.html
- #
- def template_file(self):
- _from = Config.TEMPLATE_DIR
- _file = "index.html"
-
- url_split = self.request.path.split('/')
- if not self.request.path == "/": # pacote padrao(index) e action padrao (index)
- for s in url_split:
- if s:
- if not(s.endswith(Config.EXT_ACTION)):
- _from += ("/" + s)
- else:
- if s.find("_") > 0:
- _file = s.replace(Config.EXT_ACTION, ".html")
-
- return _from + "/" + _file
View
19 templates/index.html
@@ -2,25 +2,12 @@
<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 }}
+ {{message}}
</pre>
<hr>
- <b>import_from:</b> <br>
- {{ import_from }}
+ <b>import_from:</b> <br>{{import_from}}
<hr>
-
- <b>method:</b> <br>
- {{ method_to_call }}
+ <b>a:</b> <br> {{a}}
<hr>
-
- <b>template:</b> <br>
- {{ template_file }}
- <hr>
-
- <b>a:</b> <br>
- {{a}}
- <hr>
-
-
</body>
</html>

0 comments on commit 0d4f108

Please sign in to comment.