Skip to content

Commit 1264979

Browse files
committed
removed reference to non-existane GridActionButton in chapter14
1 parent 1daca89 commit 1264979

File tree

1 file changed

+24
-91
lines changed

1 file changed

+24
-91
lines changed

docs/chapter-14.rst

Lines changed: 24 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -435,109 +435,42 @@ the Grid **init** method.
435435
You can build your own Action Button class to pass to pre/post action
436436
buttons based on the template below (this is not provided with py4web).
437437
438-
Sample Action Button Class
439-
~~~~~~~~~~~~~~~~~~~~~~~~~~
438+
Here is an example:
440439
441440
.. code:: python
442441
443-
class GridActionButton:
444-
def __init__(
445-
self,
446-
url,
447-
text=None,
448-
icon=None,
449-
additional_classes="",
450-
additional_styles="",
451-
override_classes="",
452-
override_styles="",
453-
message="",
454-
append_id=False,
455-
name=None,
456-
ignore_attribute_plugin=False,
457-
**attrs
458-
):
459-
self.url = url
460-
self.text = text
461-
self.icon = icon
462-
self.additional_classes = additional_classes
463-
self.additional_styles = additional_styles
464-
self.override_classes = override_classes
465-
self.override_styles = override_styles
466-
self.message = message
467-
self.append_id = append_id
468-
self.name = name
469-
self.ignore_attribute_plugin = ignore_attribute_plugin
470-
self.attrs = attrs
471-
472-
"fa-calendar" for IconStyleFontawesome.
473-
the button element
474-
added to additional classes
475-
for the button
476-
477-
After defining the custom GridActionButton class, you need to define
478-
your Action buttons:
479-
480-
.. code:: python
481-
482-
pre_action_buttons = [
483-
lambda row: GridActionButton(
484-
lambda row: f"https://www.google.com/search?q={row.superhero}",
485-
text= f"Google for {row.superhero}",
486-
)
487-
]
488-
489-
Finally, you need to reference them in the Grid definition:
490-
491-
.. code:: python
442+
pre_action_buttons = [
443+
lambda row: dict(
444+
url = f"https://www.google.com/search?q={row.superhero}",
445+
text = f"Google for {row.superhero}",
446+
_style = "font-weight: 200"
447+
)
448+
]
492449
493450
grid = Grid(... pre_action_buttons = pre_action_buttons ...)
494451
452+
Notice that a button can be represented by a dict with the following keys:
495453
496-
Using callable parameters
497-
~~~~~~~~~~~~~~~~~~~~~~~~~
498-
499-
A recent improvement to py4web allows you to pass a **callable** instead of a GridActionButton. This allow you to more easily change the behaviour
500-
of standard and custom Actions.
454+
- url: the url the button points to (required)
455+
- text: the text of the button (required)
456+
- icon: the optional name of the icon in the button, for example ``fa-gear``
457+
- classes: optional classes to be added to the button tag
458+
- kind: optional kind of button used to retrieve style infro from the GridStyle. Defaults to "grid-button"
459+
- _{name}: optional attributes to be passed to the ``A(..., _{name}=...)`` helper building the button.
501460
502-
503-
- override_classes
504-
- override_styles
505-
506-
507-
Example usage:
461+
A button can also be built explicitely using helpers for added flexibility and less magic:
508462
509463
.. code:: python
510464
511-
@action("example")
512-
def example():
513-
514-
pre_action_buttons = [
515-
lambda row: GridActionButton(
516-
URL("test", row.id),
517-
text="Click me",
518-
icon=IconStyleFontawsome.add_button, # same as "fa-plus"
519-
additional_classes=row.id,
520-
additional_styles=["height: 10px" if row.bar else None],
521-
)
522-
]
523-
524-
post_action_buttons = [
525-
lambda row: GridActionButton(
526-
URL("test", row.id),
527-
text="Click me!!!",
528-
icon="fa-plus",
529-
additional_classes=row.id,
530-
additional_styles=["height: 10px" if row.bar else None],
531-
)
532-
]
533-
534-
grid = Grid(
535-
query=db.foo,
536-
pre_action_buttons=pre_action_buttons,
537-
post_action_buttons=post_action_buttons,
538-
)
465+
pre_action_buttons = [
466+
lambda row: A(
467+
f"Google for {row.superhero}",
468+
_href = f"https://www.google.com/search?q={row.superhero}",
469+
_style = "font-weight: 200",
470+
)
471+
]
539472
540-
return dict(grid=grid.render())
473+
grid = Grid(... pre_action_buttons = pre_action_buttons ...)
541474
542475
543476
Reference Fields

0 commit comments

Comments
 (0)