本文整理汇总了Python中gluon.globals.Request.controller方法的典型用法代码示例。如果您正苦于以下问题:Python Request.controller方法的具体用法?Python Request.controller怎么用?Python Request.controller使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.globals.Request
的用法示例。
在下文中一共展示了Request.controller方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def setUp(self):
request = Request(env={})
request.application = "a"
request.controller = "c"
request.function = "f"
request.folder = "applications/admin"
response = Response()
session = Session()
T = translator("", "en")
session.connect(request, response)
from gluon.globals import current
current.request = request
current.response = response
current.session = session
current.T = T
self.db = DAL(DEFAULT_URI, check_reserved=["all"])
self.auth = Auth(self.db)
self.auth.define_tables(username=True, signature=False)
self.db.define_table("t0", Field("tt"), self.auth.signature)
self.auth.enable_record_versioning(self.db)
# Create a user
self.db.auth_user.insert(
first_name="Bart",
last_name="Simpson",
username="user1",
email="[email protected]",
password="password_123",
registration_key=None,
registration_id=None,
)
self.db.commit()
示例2: sim_request
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def sim_request():
"""Return test request."""
request = Request()
request.application = 'app'
request.controller = 'cont'
request.function = 'func'
return request
示例3: setUp
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def setUp(self):
request = Request(env={})
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.folder = 'applications/admin'
response = Response()
session = Session()
T = translator('', 'en')
session.connect(request, response)
from gluon.globals import current
current.request = request
current.response = response
current.session = session
current.T = T
self.db = DAL(DEFAULT_URI, check_reserved=['all'])
self.auth = Auth(self.db)
self.auth.define_tables(username=True, signature=False)
self.db.define_table('t0', Field('tt'), self.auth.signature)
self.auth.enable_record_versioning(self.db)
# Create a user
self.db.auth_user.insert(first_name='Bart',
last_name='Simpson',
username='user1',
email='[email protected]',
password='password_123',
registration_key=None,
registration_id=None)
self.db.commit()
示例4: build_web2py_environment
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def build_web2py_environment(self):
"build a namespace suitable for editor autocompletion and calltips"
# warning: this can alter current global variable, use with care!
try:
from gluon.globals import Request, Response, Session
from gluon.compileapp import build_environment, DAL
request = Request({})
response = Response()
session = Session()
# fake request values
request.folder = ""
request.application = "welcome"
request.controller = "default"
request.function = "index"
ns = build_environment(request, response, session)
# fake common model objects
db = ns["db"] = DAL("sqlite:memory")
from gluon.tools import Auth, Crud, Service
ns["auth"] = Auth(db)
ns["crud"] = Crud(db)
ns["service"] = Service()
except Exception, e:
traceback.print_exc()
ns = {}
示例5: env
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def env(a, import_models=False, c=None, f=None, dir="", extra_request={}):
"""
Return web2py execution environment for application (a), controller (c),
function (f).
If import_models is True the exec all application models into the
environment.
extra_request allows you to pass along any extra
variables to the request object before your models
get executed. This was mainly done to support
web2py_utils.test_runner, however you can use it
with any wrapper scripts that need access to the
web2py environment.
"""
request = Request({})
response = Response()
session = Session()
request.application = a
# Populate the dummy environment with sensible defaults.
if not dir:
request.folder = os.path.join("applications", a)
else:
request.folder = dir
request.controller = c or "default"
request.function = f or "index"
response.view = "%s/%s.html" % (request.controller, request.function)
request.env.http_host = "127.0.0.1:8000"
request.env.remote_addr = "127.0.0.1"
request.env.web2py_runtime_gae = global_settings.web2py_runtime_gae
for k, v in extra_request.items():
request[k] = v
path_info = "/%s/%s/%s" % (a, c, f)
if request.args:
path_info = "%s/%s" % (path_info, "/".join(request.args))
if request.vars:
vars = ["%s=%s" % (k, v) if v else "%s" % k for (k, v) in request.vars.iteritems()]
path_info = "%s?%s" % (path_info, "&".join(vars))
request.env.path_info = path_info
# Monkey patch so credentials checks pass.
def check_credentials(request, other_application="admin"):
return True
fileutils.check_credentials = check_credentials
environment = build_environment(request, response, session)
if import_models:
try:
run_models_in(environment)
except RestrictedError, e:
sys.stderr.write(e.traceback + "\n")
sys.exit(1)
示例6: setup_clean_session
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def setup_clean_session():
request = Request(env={})
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.folder = 'applications/admin'
response = Response()
session = Session()
session.connect(request, response)
from gluon.globals import current
current.request = request
current.response = response
current.session = session
return current
示例7: test_admin_compile
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def test_admin_compile(self):
request = Request(env={})
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.folder = 'applications/admin'
# remove any existing test app
app_path = os.path.join('applications', test_app2_name)
if os.path.exists(app_path):
shutil.rmtree(app_path)
self.assertTrue(app_create(test_app2_name, request))
self.assertTrue(os.path.exists('applications/%s/controllers/default.py' % test_app2_name))
self.assertIsNone(app_compile(test_app2_name, request))
self.assertTrue(app_cleanup(test_app2_name, request))
self.assertTrue(app_uninstall(test_app2_name, request))
示例8: testRun
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def testRun(self):
# setup
request = Request(env={})
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.folder = 'applications/admin'
response = Response()
session = Session()
T = translator('', 'en')
session.connect(request, response)
from gluon.globals import current
current.request = request
current.response = response
current.session = session
current.T = T
db = DAL(DEFAULT_URI, check_reserved=['all'])
auth = Auth(db)
auth.define_tables(username=True, signature=False)
self.assertTrue('auth_user' in db)
self.assertTrue('auth_group' in db)
self.assertTrue('auth_membership' in db)
self.assertTrue('auth_permission' in db)
self.assertTrue('auth_event' in db)
db.define_table('t0', Field('tt'), auth.signature)
auth.enable_record_versioning(db)
self.assertTrue('t0_archive' in db)
for f in ['login', 'register', 'retrieve_password',
'retrieve_username']:
html_form = getattr(auth, f)().xml()
self.assertTrue('name="_formkey"' in html_form)
for f in ['logout', 'verify_email', 'reset_password',
'change_password', 'profile', 'groups']:
self.assertRaisesRegexp(HTTP, "303*", getattr(auth, f))
self.assertRaisesRegexp(HTTP, "401*", auth.impersonate)
try:
for t in ['t0_archive', 't0', 'auth_cas', 'auth_event',
'auth_membership', 'auth_permission', 'auth_group',
'auth_user']:
db[t].drop()
except SyntaxError as e:
# GAE doesn't support drop
pass
return
示例9: env
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def env(
a,
import_models=False,
c=None,
f=None,
dir='',
):
"""
Return web2py execution environment for application (a), controller (c),
function (f).
If import_models is True the exec all application models into the
evironment.
"""
request = Request()
response = Response()
session = Session()
request.application = a
# Populate the dummy environment with sensible defaults.
if not dir:
request.folder = os.path.join('applications', a)
else:
request.folder = dir
request.controller = c or 'default'
request.function = f or 'index'
response.view = '%s/%s.html' % (request.controller,
request.function)
request.env.path_info = '/%s/%s/%s' % (a, c, f)
request.env.http_host = '127.0.0.1:8000'
request.env.remote_addr = '127.0.0.1'
# Monkey patch so credentials checks pass.
def check_credentials(request, other_application='admin'):
return True
gluon.fileutils.check_credentials = check_credentials
environment = build_environment(request, response, session)
if import_models:
run_models_in(environment)
return environment
示例10: test_admin_compile
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def test_admin_compile(self):
#apps = ['welcome', 'admin', 'examples']
request = Request(env={})
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.folder = 'applications/admin'
apps = ['welcome']
for appname in apps:
appname_path = os.path.join(os.getcwd(), 'applications', appname)
self.assertEqual(app_compile(appname_path, request), None)
# remove any existing test_app
new_app = 'test_app_%s' % (appname)
if(os.path.exists('applications/%s' % (new_app))):
shutil.rmtree('applications/%s' % (new_app))
self.assertEqual(app_create(new_app, request), True)
self.assertEqual(os.path.exists('applications/test_app_%s/controllers/default.py' % (appname)), True)
self.assertEqual(app_cleanup(new_app, request), True)
self.assertEqual(app_uninstall(new_app, request), True)
self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1)
return
示例11: setUp
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def setUp(self):
from gluon.globals import Request, Response, Session, current
from gluon.html import A, DIV, FORM, MENU, TABLE, TR, INPUT, URL, XML
from gluon.html import ASSIGNJS
from gluon.validators import IS_NOT_EMPTY
from gluon.compileapp import LOAD
from gluon.http import HTTP, redirect
from gluon.tools import Auth
from gluon.sql import SQLDB
from gluon.sqlhtml import SQLTABLE, SQLFORM
self.original_check_credentials = fileutils.check_credentials
fileutils.check_credentials = fake_check_credentials
request = Request(env={})
request.application = 'welcome'
request.controller = 'appadmin'
request.function = self._testMethodName.split('_')[1]
request.folder = 'applications/welcome'
request.env.http_host = '127.0.0.1:8000'
request.env.remote_addr = '127.0.0.1'
response = Response()
session = Session()
T = TranslatorFactory('', 'en')
session.connect(request, response)
current.request = request
current.response = response
current.session = session
current.T = T
db = DAL(DEFAULT_URI, check_reserved=['all'])
auth = Auth(db)
auth.define_tables(username=True, signature=False)
db.define_table('t0', Field('tt'), auth.signature)
# Create a user
db.auth_user.insert(first_name='Bart',
last_name='Simpson',
username='user1',
email='[email protected]',
password='password_123',
registration_key=None,
registration_id=None)
self.env = locals()
示例12: env
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
def env(
a,
import_models=False,
c=None,
f=None,
dir='',
extra_request={},
):
"""
Returns web2py execution environment for application (a), controller (c),
function (f).
If import_models is True the exec all application models into the
environment.
extra_request allows you to pass along any extra variables to the request
object before your models get executed. This was mainly done to support
web2py_utils.test_runner, however you can use it with any wrapper scripts
that need access to the web2py environment.
"""
request = Request({})
response = Response()
session = Session()
request.application = a
# Populate the dummy environment with sensible defaults.
if not dir:
request.folder = os.path.join('applications', a)
else:
request.folder = dir
request.controller = c or 'default'
request.function = f or 'index'
response.view = '%s/%s.html' % (request.controller,
request.function)
if global_settings.cmd_options:
ip = global_settings.cmd_options.ip
port = global_settings.cmd_options.port
request.is_shell = global_settings.cmd_options.shell is not None
request.is_scheduler = global_settings.cmd_options.scheduler is not None
else:
ip, port = '127.0.0.1', '8000'
request.env.http_host = '%s:%s' % (ip, port)
request.env.remote_addr = '127.0.0.1'
request.env.web2py_runtime_gae = global_settings.web2py_runtime_gae
for k, v in extra_request.items():
request[k] = v
path_info = '/%s/%s/%s' % (a, c, f)
if request.args:
path_info = '%s/%s' % (path_info, '/'.join(request.args))
if request.vars:
vars = ['%s=%s' % (k, v) if v else '%s' % k
for (k, v) in request.vars.iteritems()]
path_info = '%s?%s' % (path_info, '&'.join(vars))
request.env.path_info = path_info
# Monkey patch so credentials checks pass.
def check_credentials(request, other_application='admin'):
return True
fileutils.check_credentials = check_credentials
environment = build_environment(request, response, session)
if import_models:
try:
run_models_in(environment)
except RestrictedError, e:
sys.stderr.write(e.traceback + '\n')
sys.exit(1)
示例13: Request
# 需要导入模块: from gluon.globals import Request [as 别名]
# 或者: from gluon.globals.Request import controller [as 别名]
web2py_env_module.__dict__.update(web2py_environment)
sys.modules["web2py_env"] = web2py_env_module
application_name = request.application
application_folder_path = os.path.join("applications",application_name)
application = application_name
controller = "controller"
function = "function"
folder = os.path.join(os.getcwd(), "applications", application_name)
web2py_environment["Request"] = Request
request = Request()
request.application = application
request.controller = controller
request.function = function
request.folder = folder
web2py_environment["request"] = request
current.request = request
controller_configuration = OrderedDict()
for controller_name in ["default"]+glob.glob(
os.path.join(application_folder_path, "controllers", "*.py")
):
controller_configuration[controller_name] = Storage(
name_nice = controller_name,
description = controller_name,
restricted = False,
module_type = 0