Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grid refactoring #893

Merged
merged 3 commits into from
Aug 4, 2024
Merged

grid refactoring #893

merged 3 commits into from
Aug 4, 2024

Conversation

mdipierro
Copy link
Contributor

  • added support for Expressions in columns
  • added support for virtual fields in joins
  • _make_field was unused so was eliminated
  • eliminated self.formatters (was unused and better handled in Column definition
  • changed meaning of self.formatters_by_type. the type key is no longer the Field type but the actual python type of the value to be displayed. In this way it does not conflict with field represent.
  • made more consistent use of - and . in class names.
  • added a class grid-cell-{name}

This now works for example:

db.define_table(
    'thing',
    Field('name', requires=IS_NOT_EMPTY()),
    Field.Virtual('name2', lambda row: row["name"]),
    Field('in_stock', 'boolean', default=True),
    Field('f_date', 'date', default=datetime.date.today()),
    Field('f_datetime', 'datetime', default=datetime.datetime.now()),
    Field('f_time', 'time', default="12:30"),
    Field('properties', 'list:string'),
    Field('image', 'upload', download_url=lambda name: URL('download', name)),
)

db.define_table(
    'part',
    Field('thing_id', "reference thing"),
    Field('name', requires=IS_NOT_EMPTY()),
    Field('weight', "float"),
)

@action('index')
@action('index/{path:path}')
@action.uses('generic.html', db)
def _(path=None):
    query = db.thing.id > 0
    weight = db.part.weight.sum()
    left = db.part.on(db.thing.id==db.part.thing_id)
    grid = Grid(path, query=query, left=left, groupby=db.thing.id, 
                columns=[
                    db.thing.name,
                    db.thing.name2,
                    db.thing.in_stock,  # shows as checkbox, was broken, use unicode now
                    db.thing.f_date,
                    db.thing.f_datetime,
                    db.thing.f_time,
                    db.thing.properties,
                    weight, # did not work before
                    Column("weight", lambda row: row[weight], required_fields=[weight]) # same as above
                ])
    return locals()

@mdipierro
Copy link
Contributor Author

Got no feedback except on mailing list. Approving my own PR. :-(

@mdipierro mdipierro merged commit fb0df93 into master Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant