Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@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())
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)
"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
@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"),
)
@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)
@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)
@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)