How to use the py4web.request function in py4web

To help you get started, we’ve selected a few py4web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github web2py / py4web / tests / test_session.py View on Github external
def test_session_in_db(self):
        request.app_name = "myapp"
        db = DAL("sqlite:memory")
        session = Session(secret="a", expiration=10, storage=DBStore(db))
        request.cookies.clear()
        session.on_request()
        session["key"] = "value"
        session.on_success()
        cookie_name = session.local.session_cookie_name

        a, b = str(response._cookies)[len("Set-Cookie: ") :].split(";")[0].split("=", 1)
        request.cookies[a] = b
        request.cookies = response._cookies
        session.local.data.clear()

        session = Session(expiration=10, storage=DBStore(db))
        session.on_request()
        self.assertEqual(session.get("key"), "value")
github web2py / py4web / tests / test_session.py View on Github external
def test_session(self):
        request.app_name = "myapp"
        session = Session(secret="a", expiration=10)
        session.on_request()
        session["key"] = "value"
        session.on_success()
        cookie_name = session.local.session_cookie_name

        a, b = str(response._cookies)[len("Set-Cookie: ") :].split(";")[0].split("=", 1)
        request.cookies[a] = b
        request.cookies = response._cookies
        session.local.data.clear()

        session = Session(secret="b", expiration=10)
        session.on_request()
        self.assertEqual(session.get("key"), None)

        session = Session(secret="a", expiration=10)
github web2py / py4web / tests / test_url.py View on Github external
def test_url(self):
        request.app_name = "_default"
        self.assertEqual(URL("index"), "/index")
        request.app_name = "app"
        self.assertEqual(URL("index"), "/app/index")
        self.assertEqual(URL("a", "b", vars=dict(x=1), hash="y"), "/app/a/b?x=1#y")
github web2py / py4web / tests / test_url.py View on Github external
def test_url(self):
        request.app_name = "_default"
        self.assertEqual(URL("index"), "/index")
        request.app_name = "app"
        self.assertEqual(URL("index"), "/app/index")
        self.assertEqual(URL("a", "b", vars=dict(x=1), hash="y"), "/app/a/b?x=1#y")
github web2py / py4web / py4web / utils / form.py View on Github external
self.readonly = readonly
        self.deletable = deletable and not readonly and self.record
        self.formstyle = formstyle
        self.dbio = dbio
        self.keep_values = True if keep_values or self.record else False
        self.vars = {}
        self.errors = {}
        self.submitted = False
        self.deleted = False
        self.accepted = False
        self.form_name = form_name or table._tablename
        self.hidden = hidden
        self.formkey = None
        self.cached_helper = None

        if readonly or request.method == "GET":
            if self.record:
                self.vars = self.record
        else:
            post_vars = request.forms
            self.submitted = True
            process = False

            # We only a process a form if it is POST and the formkey matches (correct formname and crsf)
            # Notice: we never expose the crsf uuid, we only use to sign the form uuid
            if request.method == "POST":
                if post_vars.get("_formkey") == self.form_name:
                    process = True
            if process:
                if not post_vars.get("_delete"):
                    for field in self.table:
                        if field.writable:
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def url(*args):
            return request.url + "/" + "/".join(args)