Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added other templatetag #61

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ nosetests.xml
.project
.pydevproject
.settings
.idea/
.env/
/example/settings_custom.py
4 changes: 4 additions & 0 deletions example/app/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class AjaxTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
organization = Column(field='organization.name', header=u'ORG')
organization1 = Column(field='organization.name', header=u'ORG1')
organization2 = Column(field='organization.name', header=u'ORG2')
organization3 = Column(field='organization.name', header=u'ORG3')
organization4 = Column(field='organization.name', header=u'ORG4')

class Meta:
model = Person
Expand Down
1 change: 1 addition & 0 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django>1.5
8 changes: 8 additions & 0 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@
},
}
}

ALLOWED_HOSTS = ['127.0.0.1',]


try:
from example.settings_custom import *
except ImportError:
pass
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

setup(
name='django-datatable',
version='0.2.1',
author='shymonk',
author_email='hellojohn201@gmail.com',
url='https://github.com/shymonk/django-datatable',
version='0.2.10',
author='gpannullo',
author_email='giuseppe.pannullo@gmail.com',
url='https://github.com/gpannullo/django-datatable',
description='A simple Django app to origanize data in tabular form.',
long_description=open('README.rst').read(),
packages=find_packages(exclude=['test*', 'example*']),
Expand All @@ -17,7 +17,7 @@
install_requires=["django>=1.5"],
license='MIT License',
classifiers=[
'Development Status :: 3 - Alpha',
'Development Status :: 3',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
Expand All @@ -26,6 +26,8 @@
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries',
],
Expand Down
9 changes: 8 additions & 1 deletion table/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ class Column(object):

def __init__(self, field=None, header=None, attrs=None, header_attrs=None,
header_row_order=0, sortable=True, searchable=True, safe=True,
visible=True, space=True):
visible=True, space=True, html=False, width='auto', model_function=''):
self.field = field
self.attrs = attrs or {}
self.width = width
self.sortable = sortable
self.searchable = searchable
self.safe = safe
self.visible = visible
self.space = space
self.html = html
self.model_function = model_function
self.header = ColumnHeader(header, header_attrs, header_row_order)

self.instance_order = Column.instance_order
Expand All @@ -30,7 +33,11 @@ def __str__(self):
return self.header.text

def render(self, obj):
if self.model_function:
self.field = self.model_function
text = Accessor(self.field).resolve(obj)
if self.html:
return text
return escape(text)


Expand Down
3 changes: 2 additions & 1 deletion table/columns/datetimecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# coding: utf-8
from django.utils.html import escape

from table.settings import TABLE_ATTR_DEFAULT_DATE_FORMAT
from table.utils import Accessor
from .base import Column


class DatetimeColumn(Column):

DEFAULT_FORMAT = "%Y-%m-%d %H:%M:%S"
DEFAULT_FORMAT = TABLE_ATTR_DEFAULT_DATE_FORMAT

def __init__(self, field, header=None, format=None, **kwargs):
self.format = format or DatetimeColumn.DEFAULT_FORMAT
Expand Down
14 changes: 12 additions & 2 deletions table/columns/linkcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ class Link(object):
Represents a html <a> tag.
"""
def __init__(self, text=None, viewname=None, args=None, kwargs=None, urlconf=None,
current_app=None, attrs=None):
current_app=None, attrs=None, html=None):
self.basetext = text
self.viewname = viewname
self.args = args or []
self.kwargs = kwargs or {}
self.urlconf = urlconf
self.current_app = current_app
self.base_attrs = attrs or {}
self.basehtml = html

@property
def html(self):
if self.basehtml:
return self.basehtml
return None

@property
def text(self):
Expand Down Expand Up @@ -86,13 +93,16 @@ def render(self, obj):
""" Render link as HTML output tag <a>.
"""
self.obj = obj
text = escape(self.text)
if self.html:
text = self.html
attrs = ' '.join([
'%s="%s"' % (attr_name, attr.resolve(obj))
if isinstance(attr, Accessor)
else '%s="%s"' % (attr_name, attr)
for attr_name, attr in self.attrs.items()
])
return mark_safe(u'<a %s>%s</a>' % (attrs, self.text))
return mark_safe(u'<a %s>%s</a>' % (attrs, text))


class ImageLink(Link):
Expand Down
50 changes: 50 additions & 0 deletions table/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.conf import settings

TABLE_ATTR_ATTRS = getattr(settings, 'TABLE_ATTR_ATTRS', {})
# scrolling option
TABLE_ATTR_SCROLLABLE = getattr(settings, 'TABLE_ATTR_SCROLLABLE', False)
TABLE_ATTR_SCROLLINNER = getattr(settings, 'TABLE_ATTR_SCROLLINNER', "150%")
TABLE_ATTR_FIXED_COLUMNS = getattr(settings, 'TABLE_ATTR_FIXED_COLUMNS', None)
TABLE_ATTR_FIXED_COLUMNS_WIDTH = getattr(settings, 'TABLE_ATTR_FIXED_COLUMNS_WIDTH', None)
# sort
TABLE_ATTR_SEARCH = getattr(settings, 'TABLE_ATTR_SEARCH', True)
TABLE_ATTR_SEARCH_PLACEHOLDER = getattr(settings, 'TABLE_ATTR_SEARCH_PLACEHOLDER', None)

TABLE_ATTR_INFO = getattr(settings, 'TABLE_ATTR_INFO', True)
TABLE_ATTR_INFO_FORMAT = getattr(settings, 'TABLE_ATTR_INFO_FORMAT', None)

TABLE_ATTR_PAGINATION = getattr(settings, 'TABLE_ATTR_PAGINATION', True)
TABLE_ATTR_PAGE_LENGTH = getattr(settings, 'TABLE_ATTR_PAGE_LENGTH', 10)
TABLE_ATTR_PAGINATION_FIRST = getattr(settings, 'TABLE_ATTR_PAGINATION_FIRST', None)
TABLE_ATTR_PAGINATION_LAST = getattr(settings, 'TABLE_ATTR_PAGINATION_LAST', None)
TABLE_ATTR_PAGINATION_PREV = getattr(settings, 'TABLE_ATTR_PAGINATION_PREV', None)
TABLE_ATTR_PAGINATION_NEXT = getattr(settings, 'TABLE_ATTR_PAGINATION_NEXT', None)

TABLE_ATTR_LENGTH_MENU = getattr(settings, 'TABLE_ATTR_LENGTH_MENU', True)

TABLE_ATTR_EXT_BUTTON = getattr(settings, 'TABLE_ATTR_EXT_BUTTON', False)
TABLE_ATTR_EXT_BUTTON_TEMPLATE = getattr(settings, 'TABLE_ATTR_EXT_BUTTON_TEMPLATE', None)
TABLE_ATTR_EXT_BUTTON_TEMPLATE_NAME = getattr(settings, 'TABLE_ATTR_EXT_BUTTON_TEMPLATE_NAME', None)
TABLE_ATTR_EXT_BUTTON_CONTEXT = getattr(settings, 'TABLE_ATTR_EXT_BUTTON_CONTEXT', None)

TABLE_ATTR_ZERO_RECORDS = getattr(settings, 'TABLE_ATTR_ZERO_RECORDS', 'No records')
TABLE_ATTR_THEME_CSS_FILE = getattr(settings, 'TABLE_ATTR_THEME_CSS_FILE', 'table/css/datatable.bootstrap.css')
TABLE_ATTR_THEME_JS_FILE = getattr(settings, 'TABLE_ATTR_THEME_JS_FILE', 'table/js/bootstrap.dataTables.js')

TABLE_ATTR_MEDIA_JS = getattr(settings, 'TABLE_ATTR_MEDIA_JS', ('table/js/jquery.dataTables.min.js',
'table/js/jquery.browser.min.js',
'table/js/dataTables.fixedColumns.min.js'
)) # option cutomize list of static to load
# option stateSave
TABLE_ATTR_STATESAVE = getattr(settings, 'TABLE_ATTR_STATESAVE', False)
TABLE_ATTR_STATEDURATION = getattr(settings, 'TABLE_ATTR_STATEDURATION', 604800)

# option responsive
TABLE_ATTR_RESPONSIVE = getattr(settings, 'TABLE_ATTR_RESPONSIVE', False)

# option language json
TABLE_ATTR_LANGUAGE_STATIC_JSON = getattr(settings, 'TABLE_ATTR_LANGUAGE_STATIC_JSON',
'datatables/i18n/datatables.english.json')


TABLE_ATTR_DEFAULT_DATE_FORMAT = getattr(settings, 'TABLE_ATTR_DEFAULT_DATE_FORMAT',"%Y-%m-%d %H:%M:%S")
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading