Permalink
Browse files

criado diretorio de biblioteca: lib/gae_py

  • Loading branch information...
mangar committed Feb 10, 2013
1 parent 18af034 commit 67bc5544d63cee0c98fccccbdbfe3495006a17f2
View
No changes.
View
@@ -0,0 +1,12 @@
+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
@@ -3,69 +3,10 @@
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
-# /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
- _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(EXT_ACTION)):
- _from += ("." + s)
- else:
- 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"
-
-
+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
class Handler(webapp2.RequestHandler):
@@ -80,21 +21,14 @@ 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'] = import_from_statement(self)
- template_values2['method_to_call'] = method_to_call(self)
- template_values2['template_file'] = template_file(self)
+ 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()
- path = os.path.join(TEMPLATE_DIR, 'index.html')
+ path = os.path.join(Config.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
@@ -1,40 +0,0 @@
-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))
-
-
-
-
View
No changes.
View
No changes.
No changes.
@@ -0,0 +1,36 @@
+
+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
@@ -0,0 +1,31 @@
+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, "")
@@ -0,0 +1,35 @@
+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

0 comments on commit 67bc554

Please sign in to comment.