Coder Social home page Coder Social logo

shymonk / django-datatable Goto Github PK

View Code? Open in Web Editor NEW
168.0 168.0 55.0 622 KB

django-datatable is a customizable table application of django based on jquery datatable.

Home Page: https://github.com/shymonk/django-datatable

License: MIT License

Python 75.78% HTML 11.24% CSS 5.94% JavaScript 7.04%
datatable python

django-datatable's Introduction

shymonk

Personal blog based on Pelican

django-datatable's People

Contributors

azmeuk avatar daddz avatar darthpumpkin avatar ikenfin avatar metatrevor avatar rcarneva avatar reensami avatar shymonk avatar tevinjoseph avatar tomasra avatar vilos 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  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  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  avatar  avatar  avatar  avatar

django-datatable's Issues

Ajax data loading doesn't work in production

When serving requests with multiple processes in production the tables get registered in TableDataMap with different keys in each process, because each process creates random tokens as keys created by uuid4() function. Then if an ajax request is handled by different process from the one rendering templates the token in url cannot be found in TableDataMap.map and Ajax error is shown.

The problem can be solved by using consistent string for keys when registering models in TableDataMap, I have successfully used a hash of table class name.

Filtered datasource for ajax?

Hi,

Thank you for this package. It is very usefull.
I have one problem, though. In the examples, there is a clear example how to get customised source data for ajax by using FeedDataView, but it seems like this only works if you have a fixed value on which to filter (like '.filter(id__gt=5)' in the example). How could I make this more flexible, so I can change the value 5 on runtime?

\n is stripped in strings shown in the column; this should be optional

I have a string with '\n' elements in it:

A
B
C

in the columns this is changed to

A B C

I think this should be optional, because else my column width would increase undesirable.

Maybe you could point me to the place in the code where this is done, because I could not find it ...
Thanks

reverse_lazy

hi shymonk, I'm not able to run your example with the reverse_lazy option. can you please write a full example with urls.py, tables.py and views.py? that would be quite helpful. thx!

Typo in linkcolumn.py

Hello,
there is a typo in 'django-datatable/table/columns/linkcolumn.py' line 60:

for key, value in self.kwargs.itmes: 

instead of:

for key, value in self.kwargs.items:

:)

XSS vulnerability when using AJAX.

When I implemented datatables with AJAX for my own library I had this pitfall before tests, so I decided to check if the library had the issue, and after a quick test, it does.

To try it:

  1. Open example project.
  2. Open django shell (python manage.py shell).
  3. Add the following:
from app.models import *
Organization(name="<script>alert(1)</script>").save()
Person(name="<script>alert(1)</script>", organization=myorg).save()
  1. Run development server (python manage.py runserver)
  2. Select to load any of the two AJAX-based tables.

You fill find it gives you an alert(1) javascript popup.

Non-ajax tables load their columns escaped.

I was too lazy to validate where in your code you stop using escape() when rendering the column.

Footer

It is possible to create totals row, the end of the table, (footer)

Thank you

Unable to import with Django 1.7b4 and Python 3.4

After installing this and including it in my INSTALLED_APPS tuple, I get this error when I try to run a dev server.

Is this just not Python 3 compatible yet?

c:\code\Tools\MSAnalysis\massspec>python manage.py runserver 0.0.0.0:80
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django-1.7b4-py3.4.egg\django\core\management\__init__.py", line 4
27, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django-1.7b4-py3.4.egg\django\core\management\__init__.py", line 3
91, in execute
    django.setup()
  File "C:\Python34\lib\site-packages\django-1.7b4-py3.4.egg\django\__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python34\lib\site-packages\django-1.7b4-py3.4.egg\django\apps\registry.py", line 85, in popul
ate
    app_config = AppConfig.create(entry)
  File "C:\Python34\lib\site-packages\django-1.7b4-py3.4.egg\django\apps\config.py", line 87, in create
    module = import_module(entry)
  File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\django_table-1.0.0-py3.4.egg\table\__init__.py", line 5, in <module>
ImportError: No module named 'tables'

Warning deprecated in reverse url

When use linkcolumn, this warning appears:

/local/lib/python2.7/site-packages/django_datatable-0.1.4-py2.7.egg/table/columns/linkcolumn.py:72: RemovedInDjango110Warning: Reversing by dotted path is deprecated.
  return reverse(self.viewname, **params)

Full example using ajax

Interested in using this but I am a novice and having trouble with follow the ajax example.

I have a parent object with a list of child objects. I am trying to show the parent object with a table showing the fields from the related child object.

Could you please provide a complete example using ajax showing all relevant content from all files.

DatetimeColumn

When I try to initialize a DatetimeColumn I get the error

/lib/python2.7/site-packages/django_datatable-0.1.2-py2.7.egg/table/columns/datetimecolumn.py", line 17, in render return datetime.strftime(self.format)
AttributeError: 'SafeText' object has no attribute 'strftime'

I got around this sort of, I overrode get_quertset() and converted it there, but everytime the table is sorted it switches back to the default format.

Can't use LinkColumn with ajax = true

with ajax = true

i use this code
code = LinkColumn(header=u'Code', links=[Link(viewname='het', args=(A('code'),) , text=A('code'))])

it can pagination and link correctly and show complete list but when search it show errror
"Ajax error. For more information about this error, please see http://datatables.net/tn/7"

but i change it to
code = Column(field='code',header=u"Code")
it's fully function ( can search with ajax = true )

how can i use ajax=true with link collumn

Thanks

How to use 'colspan' in table?

I need to use 'colspan' to display two fields in the same header. I have not found in the documentation or source code a way to do this.
I solved setting an attribute in the header_attrs to not adding the column(header_row property on BaseTable) if it exists. Is this the way and is it worth a PR or is there another?

Can I use with Python 3?

A think that this package is awesome, but this is only on Python 2. There are plans to port it to Python 3? How can I help?

[SUGGESTION] Implements a Util to run functions

This is inspired in utils.Accessor class

Implements a method that call functions inside fields in table, like:

from table.utils import B

def my_function(my_dict):
    return [d['name'] for d in my_dict]

preferences = Column(field=B(my_function(A('preferences.values'))), header=_(u'Preferences'))

The preferences field in model is a ManyToManyField

This will produce something like:

>>> preferences.values
[{u'id': 1, 'name': u'One thing'}, {u'id': 2, 'name': u'Another thing'}]

>>> my_function(preferences.values)
[u'One thing', u'Another thing']

This is only an example, but with this fixture, it's possible to run any method that return a string to be used in field of Collumn. (Or another usage).

unable to set args in Link column

I have the following LinkColumn:

LinkColumn(header=u'Edit', links=[
                Link(text=u'edit', viewname='admin:auth_user_change', args=('id', )), ])

as shown in the wiki.

But in this case the link is evaluated like:

http://127.0.0.1:8000/admin/auth/user/id/

instead of

http://127.0.0.1:8000/admin/auth/user/1/

Somehow the LinkColumn does not provide the pk/id of the user, but the string 'id'

Version 0.3.1 produce "Error during template rendering"

On Ubuntu 16.04 amd64, django 1.6.1, virtualenv 15.0.1 I have following:
"Error during template rendering" on this string in html file {% render_table mytable %}).
Error is "'dict' object has no attribute 'render_context'".
Work around this bug is uninstalling version 0.3.1 and install version 0.2.1, which works correctly.

Apply mask to a field value

There is a way to put a mask (like a phone mask) for exhibition, since the database contais data without any format (just string without mask)?

ajax and search

when I set ajax to true,the search model seems to be error ,can you solve this?

404 static

in the example app "local static" 404

unable to use foreign key

Hi,
i am trying to use django-datatable with a model containing foreign key
but i get the error :

 (1054, "Unknown column 'event.name' in 'order clause'")
File "/django_datatable-0.1.2-py2.7.egg/table/views.py" in convert_queryset_to_values_list
  113.             for obj in queryset

My model:

class Notification(models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
    category = models.ForeignKey(Category)
    aknowledge = models.BooleanField(default=False)
    read = models.BooleanField(default=False)
    creation_date = models.DateTimeField(auto_now=True, blank=True)
    def __unicode__(self):
        return u'%s_%s_%s' % (self.id, self.user, self.event)
    def get_absolute_url(self):
        return reverse('server_edit', kwargs={'pk': self.pk})

my view:

def notification(request):
     notification = NotificationTable()
     return render(request, "notification.html", {'notification': notification})

class NotificationAPI(FeedDataView):
    token = NotificationTable.token
    def get_queryset(self):
        return super(NotificationAPI, self).get_queryset().filter(read=False)

My table:

class NotificationTable(Table):
    id = Column(field='id', header=u'id')
    user = Column(field='user.username', header=u'user')
    event = Column(field='event.name', header=u'event')
    category = Column(field='category.name', header=u'category')
    aknowledge = CheckGlyphicon(field='aknowledge', header=u'aknowledge')
    read = CheckGlyphicon(field='read', header=u'read')
    # creation_date = DatetimeColumn(field='creation_date', header=u'creationdate', format='%H:%M:%S %d-%m-%Y', searchable=False)
    class Meta:
        model = Notification
        info = True
        info_format = u"Total: _TOTAL_  First: _START_  Last: _END_"
        zero_records = u'No records found'
        ajax = True
        ajax_source = reverse_lazy('notification_api')
        attrs = {'class': 'table-striped'}
        # sort = [(4, 'asc'), (5, 'desc')]
        # ext_button = True

what's wrong ?

Widgets

Thanks to share this app. But the doc no say how can i implement widget

How can i implement inside my html?

How to add CheckboxColumn as checked on base of field value

Please provide one working example of checkbox column selected on base of field value .
And can I perform any action on this checkbox like enable and disable.
Or How can I add Image Link columns on base of field value, If field value true call view A and image A ,if field value false call view B and image B,

Py3 support

when django-datatable==0.1.5 some files (like tables/utils.py) aren't py3 compatible.
The code seems fixed in the repo but no version was published whit that changes

Move static files to "table" subdirectory for correct namespacing

The static files for this app are currently under table/static directory, while the best practice is for them to be under table/static/table, as written in the Django documentation:

Now we might be able to get away with putting our static files directly in my_app/static/ (rather than creating another my_app subdirectory), but it would actually be a bad idea. Django will use the first static file it finds whose name matches, and if you had a static file with the same name in a different application, Django would be unable to distinguish between them. We need to be able to point Django at the right one, and the easiest way to ensure this is by namespacing them. That is, by putting those static files inside another directory named for the application itself.

https://docs.djangoproject.com/en/dev/howto/static-files/

ajax and custom queryset

Hi,

i would like to use this module to show a very large amount of members of a group, with search using AJAX.

In the documentation, i saw the "static" filtered queryset "id__gt=5" in the example, but i would like it to be dynamic, using the group_id from GET in the URL.

Ex :
I have a view that shows the members : http://myapp/showmembers/[group_id]

I don't understand how to use the group_id from the URL to build a dynamic queryset when using ajax, so i only see the members of the group i'm looking at.

I need help please guys :)
Thanks.

Warning in ajax url

When import like:

import table.urls

urlpatterns = [
    url(r'table/', include(table.urls)),
]

This warning appears:

/local/lib/python2.7/site-packages/django_datatable-0.1.4-py2.7.egg/table/urls.py:5: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^ajax/(?P<token>\w{32})/$', FeedDataView.as_view(), name='feed_data'),

to add image in table without a link

How to add field image value in in Django table as image?
In templates {{ image.url }} automatically append base/host URL with image path , How can we do it using django-datatables

Is possible do customize queryset?

At the point I haven't found this option at wiki, I was trying to find this option on source code but I'm not an expert. Is possible to specify a custom queryset to fetch data from model?
This package is awesome, btw :)

Version 0.2.1 is not downloadable from PyPI

pip doesn't get me anything newer than 0.2.0:

$ pip install django-datatable
Collecting django-datatable
Requirement already up-to-date: django>=1.5 in ./venv_prod/lib/python2.7/site-packages (from django-datatable)
Installing collected packages: django-datatable
Successfully installed django-datatable-0.2.0

$ pip install -U django-datatable
Requirement already up-to-date: django-datatable in ./venv_prod/lib/python2.7/site-packages
Requirement already up-to-date: django>=1.5 in ./venv_prod/lib/python2.7/site-packages (from django-datatable)

Also there is no download button on the PyPI page

Using a top level variable in datatable template

Hello!

I am wondering if somebody knows an answer to the following question. I have a template 'top_level.html' which calls a table tag to render a datatable. I have a variable in that template and I want to use it in a datatable template 'share_table.html' similar to https://github.com/shymonk/django-datatable/blob/master/table/templates/table/table.html . How would I do it? If I simply use {{ some_variable }} in share_table.html it does not work.

=== top_level.html

{{ some_variable }}
{% render_share_table table %}

== table_tags.py

class ShareTableNode(TableNode):
template_name = "share_table.html" <-- need to use {{ some_variable }} here

@register.tag
def render_share_table(parser, token):
try:
tag, table = token.split_contents()
except ValueError:
msg = '%r tag requires a single arguments' % token.split_contents()[0]
raise template.TemplateSyntaxError(msg)
return ShareTableNode(table)

errors when installing on Mac

I get a bunch of syntax errors on the Mac. I cloned over https. Not sure if it matters.
Tried cloning using ssh - same problem. I also can't seem to use the example project

File "build/bdist.macosx-10.10-x86_64/egg/table/tests/test_columns.py", line 124
column1 = MonthsColumn(None, date(2012, 12, 18), date(2013, 07, 01))
^
SyntaxError: invalid token

byte-compiling build/bdist.macosx-10.10-x86_64/egg/table/tests/test_tables.py to test_tables.cpython-34.pyc
byte-compiling build/bdist.macosx-10.10-x86_64/egg/table/tests/test_views.py to test_views.cpython-34.pyc
byte-compiling build/bdist.macosx-10.10-x86_64/egg/table/tests/test_widgets.py to test_widgets.cpython-34.pyc
byte-compiling build/bdist.macosx-10.10-x86_64/egg/table/urls.py to urls.cpython-34.pyc
byte-compiling build/bdist.macosx-10.10-x86_64/egg/table/utils.py to utils.cpython-34.pyc
File "build/bdist.macosx-10.10-x86_64/egg/table/utils.py", line 45
except Exception, e:
^
SyntaxError: invalid syntax

PyPi support

Amazing module I love it, and extremely well documented. My only dislike is that it needs to be added to PyPi so we can pip install django-datatable

LinkColumn

Hi

This is very useful package and I was able to get basic stuff working pretty easily. However I am having hard time using LinkColumn functionality. Can you provide few more examples on how to use LinkColumn and ImageLink etc.

Thanks

Ritesh

Multiple tables with ajax_source

I have multiple tables in my app that have different structures. I want all of them to use ajax_source. The only way I would get it to work was to define two url's

url(r'^table/data/$', DataView1.as_view(), name='dataview1'),
url(r'^table2/data/$', DataView2.as_view(), name='dataview2'),

I tried inheritance method but kept on running issues with value of the token variable. Is t here a better way?

Column attrs does not work with ajax

I'm trying to use attrs like this:

class MyTable(Table):
    field1 = Column(field='field1', header='field 1', attrs={'class': 'danger'})

    class Meta:
        model = MyModel
        ajax = True

and the attrs field is not added, but if I comment ajax = True in class Meta, it works.

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.