Skip to main content

dodotable

Latest PyPI version Documentation Status https://travis-ci.org/spoqa/dodotable.svg?branch=master

HTML table representation for SQLAlchemy .

SQLAlchemy to <table>

Assume you have an entity called Music. It looks like the below.

class Music(Base):

    id = Column(Integer, primary_key=True)

    name = Column(Unicode, nullable=False)

The following code renders a sortable <table> consisting of a list of music.

from dodotable.schema import Table, Column

table = Table(
    cls=Music,
    label='music table',
    columns=[
        Column(attr='id', label=u'id', order_by='id.desc'),
        Column(attr='name', label=u'name'),
    ],
    sqlalchemy_session=session
)
print(table.select(offset=0, limit=10).__html__())

Using with Flask

Flask uses Jinja2 as the template engine. As they mentioned on document[1]_, it is one of strategy that implement __html__ on every class inherit dodotable.schema.Renderable to convert a instance into HTML directly in Jinja2. Re-write the example written before with Flask.

from dodotable.schema import Table, Column
from flask import Flask, render_template, request

app = Flask(__name__)


@app.route('/musics/', methods=['GET'])
def list_musics():
    table = Table(
        cls=Music,
        label='music table',
        columns=[
            Column(attr='id', label=u'id',
                   order_by=request.args.get('order_by')),
            Column(attr='name', label=u'name'),
        ],
        sqlalchemy_session=session
    )
    return render_template(
        'list_musics.html',
        table=table.select(limit=request.args.get('limit'),
                           offset=request.args.get('offset'))
    )

And list_musics.html which is jinja2 template is look like below.

<html>
  <body>
    {{ table }}
  </body>
</html>

Metadata

Release files for dodotable 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dodotable 0.2.1
File Size Uploaded
dodotable-0.2.1.tar.gz 14.3 kB Details

Release files / dodotable-0.2.1.tar.gz

Download URL dodotable-0.2.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ae63c0bbb7e37d1a3efdcc25f1bea973e2603af3e0422408af56b78bcc0ab918
BLAKE2b-256 checksum
How to use checksums
5102ccc05b8e4ae267fd9bdd39b89f5a649733b2f009f9f2b65c7a1c07b6e24f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.1

1 release file

0.6.0

1 release file

0.4.0

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

This release

0.2.1 This release

1 release file

0.2.0

1 release file

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page