Git Product home page Git Product logo

dodotable's Introduction

dodotable

Latest PyPI version

Documentation Status

image

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 document1, 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>

  1. http://jinja.pocoo.org/docs/dev/api/#jinja2.Markup

dodotable's People

Contributors

dahlia avatar hanc1208 avatar heejongahn avatar kanghyojun avatar qria avatar superfluite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dodotable's Issues

Documentation

As there has been huge amount of changes recently, we could use some updated/appended documentation.

Abstract __query__ to support various backends of table

Now in dodotable __query__ build sqlalchemy.query.Query instance only. however if __query__ is implemented as a some abstract interface, dodotable can choice its way to populate datas from query.

so dodotable can get data from python's dict or list, sqlalchemy query, response JSON get from API call(using requests or any request library) and etc.

Write changelogs

Write changelog, then block a PR not to merge that dosen't write changelog.

There is no way to use an url parameter `IDENTIFIER.offset` to set offset of a table.

To set limit of a table, I can use a url parameter IDENTIFIER.limit with the code Limit(..., identifier='IDENTIFIER'). On the other hand, I can't use url parameter IDENTIFIER.offset to set the offset of a table.

The only way to set the offset of a table is the offset URL parameter. This limit can be produce confusion if there are more than one table on a page. It will be better if I can use IDENTIFIER.offset to set the offset of a table like limit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.