How to use the py4web.action.uses 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_action.py View on Github external
@action.uses(db, session)
@action.requires(lambda: True)
def index():
    db.thing.insert(name="test")
    session["number"] = session.get("number", 0) + 1
    return "ok %s %s" % (session["number"], db(db.thing).count())
github web2py / py4web / py4web / utils / publisher.py View on Github external
def __init__(self, db, policy=None, auth=None, path="service/{uuid}/"):
        self.db = db
        self.policy = policy
        self.restapi = RestAPI(self.db, policy)
        self.path = path.format(uuid=str(uuid.uuid4()))
        args = [db, auth] if auth else [db]
        f = action.uses(*args)(self.api)
        f = action(self.path, method=["GET", "POST"])(f)
        f = action(self.path + "/", method=["PUT", "DELETE"])(f)
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
"name": t._tablename,
                        "fields": t.fields,
                        "link": url(name, t._tablename) + "?model=true",
                    }
                    for t in getattr(module, name)
                ]

            return {
                "databases": [
                    {"name": name, "tables": tables(name)} for name in databases
                ]
            }
        elif len(args) > 2 and args[1] in databases:
            db = getattr(module, args[1])
            id = args[3] if len(args) == 4 else None
            data = action.uses(db, T)(
                lambda: RestAPI(db, policy)(
                    request.method, args[2], id, request.query, request.json
                )
            )()
        else:
            data = {}
        if "code" in data:
            response.status = data["code"]
        return data
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
    @action.uses("index.html", session, T)
    def index():
        return dict(
            languages=dumps(T.local.language),
            mode=MODE,
            user_id=(session.get("user") or {}).get("id"),
        )
github web2py / py4web / apps / todo / __init__.py View on Github external
@action.uses(session)  # action needs a session object (read/write cookies)
def index():
    session["counter"] = session.get("counter", 0) + 1
    session["user"] = {"id": 1}  # store a user in session
    return dict(session=session)
github web2py / py4web / apps / examples / controllers.py View on Github external
@action.uses("form.html", db, session, T)
def example_form(id=None):
    form = Form(db.person, id, deletable=False, formstyle=FormStyleBulma)
    rows = db(db.person).select()
    return dict(form=form, rows=rows)
github web2py / py4web / apps / todo / __init__.py View on Github external
@action.uses("index.html")  # we use the template index.html to render it
@action.uses(session)  # action needs a session object (read/write cookies)
def index():
    session["counter"] = session.get("counter", 0) + 1
    session["user"] = {"id": 1}  # store a user in session
    return dict(session=session)