Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

from … import and method

  • Loading branch information...
commit 18af0342a54debe06fa45423f292903c4bd66b58 1 parent 50c7cca
@mangar authored
Showing with 54 additions and 11 deletions.
  1. +38 −8 index.py
  2. +16 −3 templates/index.html
View
46 index.py
@@ -12,10 +12,11 @@
#
# 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 --> 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 import_from_statement(self):
_from = BASE_CONTROLLER_DIR
@@ -23,20 +24,47 @@ def import_from_statement(self):
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, "")
+ if s.find("_") > 0:
+ _import = s.split("_")[0]
+
return "from " + _from + " import " + _import
+#
+# 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(EXT_ACTION):
+ _method = url[url.rfind("/")+1:]
+
+ if _method.count("_") >= 1:
+ _method = _method[_method.find("_")+1:]
+
+ return _method.replace(EXT_ACTION, "")
+
+
+#
+# Ex.:
+#
+#
+#
+def template_file(self):
+ return "aaa"
+
@@ -56,6 +84,8 @@ def get(self):
template_values2['a'] = self.request.path
template_values2['import_from'] = import_from_statement(self)
+ template_values2['method_to_call'] = method_to_call(self)
+ template_values2['template_file'] = template_file(self)
path = os.path.join(TEMPLATE_DIR, 'index.html')
self.response.out.write(template.render(path, template_values2))
View
19 templates/index.html
@@ -2,12 +2,25 @@
<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>a:</b> <br> {{a}}
+
+ <b>method:</b> <br>
+ {{ method_to_call }}
<hr>
+
+ <b>template:</b> <br>
+ {{ template_file }}
+ <hr>
+
+ <b>a:</b> <br>
+ {{a}}
+ <hr>
+
+
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.