DataTables with MongoEngine
The DataTablesManager class can be used instead of the default MongoEngine
QuerySet class to add a datatables method for returning results as required by the
jQuery plugin DataTables.
Installation
pip install datatables-mongoengine
Example
Here's an example for Flask.
models.py
from mongoengine import Document, StringField, ListField
from datatables_mongoengine import DataTablesManager
class Links(Document):
"""The MongoEngine ODM class for the links collection."""
meta = {
"queryset_class": DataTablesManager
}
name = StringField()
category = StringField()
link = StringField()
group = ListField()
routes.py
from flask import request, g, jsonify
from app import app
from app.models import Links
@app.route("/ajax/links", methods=["POST"])
def ajax_links():
"""Get results from MongoDB for DataTables."""
data = request.get_json()
custom_filter = {
'group': g.user.group
}
results = Links.objects.datatables(data, **custom_filter)
return jsonify(results)
Note that you can inject any filter you want server-side, like I do above to make sure the results all match the current user's group.
app.js
$(document).ready( function () {
$('#example').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '/ajax/links',
dataSrc: 'data',
type: 'POST',
contentType: 'application/json',
data: function (d) {
return JSON.stringify(d)
}
},
columns: [
{ data: 'name'},
{ data: 'category'},
{ data: 'link'}
],
});
Metadata
Release files for datatables-mongoengine 0.1.7
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_mongoengine-0.1.7.tar.gz | 3.5 kB | Without provenance | Details for datatables_mongoengine-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datatables_mongoengine-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for datatables_mongoengine-0.1.7-py3-none-any.whl |
Total release size: 8.4 kB
Release files / datatables_mongoengine-0.1.7.tar.gz
| Download URL | datatables_mongoengine-0.1.7.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a344bcfbdd39dac3f1a370cc0f970dbe0b095dde9bbe667288925233e6df60d1
|
|
BLAKE2b-256 checksum How to use checksums |
96d9395396b217d660eca9cafe28a7216b0f0e819b1267172d03a96d8289bef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
|
Release files / datatables_mongoengine-0.1.7-py3-none-any.whl
| Download URL | datatables_mongoengine-0.1.7-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81744380740f7dd71033f5f54a09f1957afcb3ec911922fa43403300ed3da3e3
|
|
BLAKE2b-256 checksum How to use checksums |
0d41133fab6c645cf2e511ee6960aca459535856b322c46717032c6885f7bc4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
|
Security for datatables-mongoengine 0.1.7
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.