Skip to content

Commit

Permalink
fixed form update in form and grid, fixed link to download in grid
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Aug 22, 2024
1 parent d7b5ab0 commit 887a440
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
26 changes: 16 additions & 10 deletions py4web/utils/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
import jwt
from pydal._compat import to_native
from pydal.objects import FieldVirtual
from yatl.helpers import (CAT, DIV, FORM, INPUT, LABEL, OPTION, SELECT, SPAN,
TEXTAREA, XML, A, P)
from yatl.helpers import (
CAT,
DIV,
FORM,
INPUT,
LABEL,
OPTION,
SELECT,
SPAN,
TEXTAREA,
XML,
A,
P,
)

from py4web import HTTP, request, response
from py4web.utils.param import Param
Expand Down Expand Up @@ -328,7 +340,6 @@ def __call__(
if "_virtual_fields" in dir(table):
all_fields += table._virtual_fields
for field in all_fields:

is_virtual = isinstance(field, FieldVirtual)

# only display field if readable or writable
Expand Down Expand Up @@ -389,7 +400,6 @@ def __call__(
if readonly or not field.writable or field.type == "id" or is_virtual:
# for boolean readonly we use a readonly checbox
if field.type == "boolean":

control = CheckboxWidget().make(
field, value, error, title, readonly=True
)
Expand Down Expand Up @@ -520,7 +530,6 @@ def __call__(
form.append(INPUT(_name="id", _value=vars["id"], _hidden=True))

if deletable:

deletable_record_attributes = dict()

deletable_field_name = "_delete"
Expand Down Expand Up @@ -822,6 +831,7 @@ def __init__(
if validation:
validation(self)
if not self.errors:
"""
for file in uploaded_files:
if field.name not in self.vars:
field, value = file
Expand All @@ -830,13 +840,9 @@ def __init__(
)
if value is not None:
self.vars[field.name] = value
"""
self.accepted = True
if dbio:
validated_vars = {
k: v
for k, v in self.vars.items()
if k != "id"
}
self.update_or_insert(validated_vars)
elif dbio:
self.accepted = True
Expand Down
11 changes: 9 additions & 2 deletions py4web/utils/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,21 @@ def col2key(col):

for index, col in enumerate(self.param.columns):
if isinstance(col, Column):

if not col.key:
col.key = f"column-{index}"
self.columns.append(col)

elif isinstance(col, Field):
# what about represe

def compute(row, col=col):
value = row(str(col))
return col.represent(value) if col.represent else value
if col.represent:
value = col.represent(value)
# deal with download links in special manner if no representation
if col.type == "upload" and value and col.download_url:
value = A("download", _href=col.download_url(value))
return value

self.columns.append(
Column(
Expand Down

0 comments on commit 887a440

Please sign in to comment.