Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
version 1.20211228.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Dec 29, 2021
1 parent e6c29b4 commit 32256e6
Show file tree
Hide file tree
Showing 37 changed files with 505 additions and 595 deletions.
2 changes: 1 addition & 1 deletion apps/_documentation/static/en/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: b0d1b44aaa6df3fedbf2f70b449fe55f
config: 8acc48e146f3d3c47ffa901083878970
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified apps/_documentation/static/en/.doctrees/chapter-01.doctree
Binary file not shown.
Binary file modified apps/_documentation/static/en/.doctrees/chapter-05.doctree
Binary file not shown.
Binary file modified apps/_documentation/static/en/.doctrees/chapter-10.doctree
Binary file not shown.
Binary file modified apps/_documentation/static/en/.doctrees/chapter-14.doctree
Binary file not shown.
Binary file modified apps/_documentation/static/en/.doctrees/chapter-15.doctree
Binary file not shown.
Binary file modified apps/_documentation/static/en/.doctrees/environment.pickle
Binary file not shown.
8 changes: 4 additions & 4 deletions apps/_documentation/static/en/_sources/chapter-01.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ details if you come from web2py):
now exclusively on the regular Python import mechanism.
- PY4WEB, like web2py, can serve multiple applications concurrently, as
long as the apps are submodules of the apps module.
- PY4WEB, unlike web2py, is based on bottlepy and in particular uses
the Bottle request object and the Bottle routing mechanism. This is
achieved with `ombott (One More BOTTle) <https://github.com/valq7711/ombott>`__,
which is a fast bottlepy spin-off.
- PY4WEB, unlike web2py, is based on ombott
(a reduced and faster spin-off of Bottle) and in particular uses
a Bottle-compatible request object and routing mechanism.

- PY4WEB, unlike web2py, does not create a new environment at every
request. It introduces the concept of fixtures to explicitly declare
which objects need to be (re)initialized when a new http request arrives
Expand Down
13 changes: 6 additions & 7 deletions apps/_documentation/static/en/_sources/chapter-05.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ The newly created file will be accessible at
Notice that ``static`` is a special path for py4web and only files under
the ``static`` folder are served.

Important: internally py4web uses the bottle
`static_file <https://bottlepy.org/docs/dev/tutorial.html#static-files>`__
method for serving static files, which means it supports streaming,
partial content, range requests, and if-modified-since. This is all
Important: internally py4web uses the ombott
(One More BOTTle) <https://github.com/valq7711/ombott>`__,
It supports streaming, partial content, range requests,
and if-modified-since. This is all
handled automatically based on the HTTP request headers.

Dynamic Web Pages
Expand Down Expand Up @@ -218,7 +218,7 @@ This action can be accessed at:



Notice that the request object is a `Bottle request object <https://bottlepy.org/docs/dev/api.html#the-request-object>`__.
Notice that the request object is equivalent to a `Bottle request object <https://bottlepy.org/docs/dev/api.html#the-request-object>`__.
with one additional attribute:

::
Expand Down Expand Up @@ -364,8 +364,7 @@ The scaffold app contains an example of a more complex action:
Notice the following:

- ``request``, ``response``, ``abort`` are defined by Bottle, using
`ombott (One More BOTTle) <https://github.com/valq7711/ombott>`__,
- ``request``, ``response``, ``abort`` are defined by
which is a fast bottlepy spin-off.
- ``redirect`` and ``URL`` are similar to their web2py counterparts
- helpers (``A``, ``DIV``, ``SPAN``, ``IMG``, etc) must be imported
Expand Down
42 changes: 38 additions & 4 deletions apps/_documentation/static/en/_sources/chapter-10.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,48 @@ that match the specified attributes will be searched for text.
>>> print(a)
<div><div><span class="abc">x</span><div><span class="efg">hello</span><span class="abc">z</span></div></div></div>
Import modules from templates
-----------------------------
Using Inject
------------

Normally all the code should be called from the controller program, and only the
necessary data is passed to the template in order to be displayed.
But sometimes it's useful to use a python function as a helper called from a template.
But sometimes it's useful to pass variables or even use a python function as a helper called from a template.

In this case you can use ``Inject``. For example if your helper function is called *sidebar_menu*
In this case you can use the fixture ``Inject`` from py4web.utils.factories.

This is a simple example for injecting a variable:

.. code:: python
from py4web.utils.factories import Inject
my_var = "Example variable to be passed to a Template"
...
@unauthenticated("index", "index.html")
@action.uses(Inject(my_var=my_var))
def index():
...
Then in ``index.html`` you can use the injected variable:

.. code:: html

[[=my_var]]


You can also use ``Inject`` to add variables to the auth.enable line;
in this way auth forms would have access to that variable.

.. code:: python
auth.enable(uses=(session, T, db, Inject(TIMEOFFSET=settings.TIMEOFFSET)))
A more complex usage of Inject is for passing python functions to templates.
For example if your helper function is called *sidebar_menu*
and it's inside the libs/helpers.py module of your app, you could use this in **controllers.py**:

.. code:: python
Expand Down
Loading

0 comments on commit 32256e6

Please sign in to comment.