datatables

Installation
The package is available on PyPI and is tested on Python 2.7 to 3.4
pip install datatables
Usage
Using Datatables is simple. Construct a DataTable instance by passing it your request parameters (or another dict-like object), your model class, a base query and a set of columns. The columns list can contain simple strings which are column names, or tuples containing (datatable_name, model_name), (datatable_name, model_name, filter_function) or (datatable_name, filter_function).
Additional data such as hyperlinks can be added via DataTable.add_data, which accepts a callable that is called for each instance. Check out the usage example below for more info.
Example
models.py
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
full_name = Column(Text)
created_at = Column(DateTime, default=datetime.datetime.utcnow)
# Use lazy=joined to prevent O(N) queries
address = relationship("Address", uselist=False, backref="user", lazy="joined")
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
description = Column(Text, unique=True)
user_id = Column(Integer, ForeignKey('users.id'))
views.py
@view_config(route_name="data", request_method="GET", renderer="json")
def users_data(request):
# User.query = session.query(User)
table = DataTable(request.GET, User, User.query, [
"id",
("name", "full_name", lambda i: "User: {}".format(i.full_name)),
("address", "address.description"),
])
table.add_data(link=lambda o: request.route_url("view_user", id=o.id))
table.searchable(lambda queryset, user_input: perform_some_search(queryset, user_input))
return table.json()
template.jinja2
<table class="table" id="clients_list">
<thead>
<tr>
<th>Id</th>
<th>User name</th>
<th>Address</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$("#clients_list").dataTable({
serverSide: true,
processing: true,
ajax: "{{ request.route_url("data") }}",
columns: [
{
data: "id",
"render": function(data, type, row){
return $("<div>").append($("<a/>").attr("href", row.DT_RowData.link).text(data)).html();
}
},
{ data: "name" },
{ data: "address" }
]
</script>
Metadata
Release files for datatables 0.4.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datatables-0.4.9.zip | 9.1 kB | Without provenance | Details for datatables-0.4.9.zip |
Release files / datatables-0.4.9.zip
| Download URL | datatables-0.4.9.zip |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9cbe8261e2abf134987de22a3313558c7f4b1b842596d0987c06326b1ea7a2b
|
|
BLAKE2b-256 checksum How to use checksums |
d0a253397d6f6f3322007741b1677e203f5c31db5236098cf25123f4ebecd1ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for datatables 0.4.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.