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

Add Python 3 compatibility via 2to3 #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and mainly for the purpose of learning. I really appreciate that anyone make pul

## Requirement

* Python 2.x
* Python 2.x or 3.x

* jQuery 1.6+

Expand Down
2 changes: 1 addition & 1 deletion example/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
2 changes: 1 addition & 1 deletion example/app/migrations/0002_auto_20150328_1648.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
134 changes: 67 additions & 67 deletions example/app/tables.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
#!/usr/bin/env python
# coding: utf-8
from datetime import date
from django.core.urlresolvers import reverse_lazy
from table.columns import Column
from table.columns.calendarcolumn import CalendarColumn
from table.columns.sequencecolumn import SequenceColumn
from table.columns.linkcolumn import LinkColumn, Link, ImageLink
from table import Table
from table.utils import A
from app.models import Person
class ModelTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
class Meta:
model = Person
class AjaxTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
organization = Column(field='organization.name', header=u'ORG')
class Meta:
model = Person
ajax = True
class AjaxSourceTable(Table):
id = Column(field='id', header=u'#')
name = Column(field='name', header=u'NAME')
class Meta:
model = Person
ajax = True
ajax_source = reverse_lazy('ajax_source_api')
class SequenceColumnTable(Table):
id = Column(field='id', header=u'#')
seq = SequenceColumn(field='calendar', headers=["A", "B", "C", "D", "E"])
class CalendarColumnTable(Table):
id = Column(field='id', header=u'#', header_attrs={'rowspan': '3'})
name = Column(field='name', header=u'NAME', header_attrs={'rowspan': '3'})
calendar = CalendarColumn(field='calendar', start_date=date(2014, 4, 27), end_date=date(2014, 5, 9))
image_url = 'https://cdn0.iconfinder.com/data/icons/users-android-l-lollipop-icon-pack/24/user-32.png'
class LinkColumnTable(Table):
id = Column(field='id', header=u'#')
name = LinkColumn(header=u'NAME', links=[
Link(viewname='user_profile', args=(A('id'),), text=A('name'))])
avatar = LinkColumn(header=u'AVATAR', links=[
ImageLink(viewname='user_profile', args=(A('id'),), image=image_url, image_title='avatar')])
class Meta:
model = Person
#!/usr/bin/env python
# coding: utf-8

from datetime import date

from django.core.urlresolvers import reverse_lazy
from table.columns import Column
from table.columns.calendarcolumn import CalendarColumn
from table.columns.sequencecolumn import SequenceColumn
from table.columns.linkcolumn import LinkColumn, Link, ImageLink
from table import Table
from table.utils import A

from app.models import Person


class ModelTable(Table):
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')

class Meta:
model = Person


class AjaxTable(Table):
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')
organization = Column(field='organization.name', header='ORG')

class Meta:
model = Person
ajax = True


class AjaxSourceTable(Table):
id = Column(field='id', header='#')
name = Column(field='name', header='NAME')

class Meta:
model = Person
ajax = True
ajax_source = reverse_lazy('ajax_source_api')


class SequenceColumnTable(Table):
id = Column(field='id', header='#')
seq = SequenceColumn(field='calendar', headers=["A", "B", "C", "D", "E"])


class CalendarColumnTable(Table):
id = Column(field='id', header='#', header_attrs={'rowspan': '3'})
name = Column(field='name', header='NAME', header_attrs={'rowspan': '3'})
calendar = CalendarColumn(field='calendar', start_date=date(2014, 4, 27), end_date=date(2014, 5, 9))


image_url = 'https://cdn0.iconfinder.com/data/icons/users-android-l-lollipop-icon-pack/24/user-32.png'


class LinkColumnTable(Table):
id = Column(field='id', header='#')
name = LinkColumn(header='NAME', links=[
Link(viewname='user_profile', args=(A('id'),), text=A('name'))])
avatar = LinkColumn(header='AVATAR', links=[
ImageLink(viewname='user_profile', args=(A('id'),), image=image_url, image_title='avatar')])

class Meta:
model = Person
6 changes: 3 additions & 3 deletions example/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def sequence_column(request):

def calendar_column(request):
data = [
Foo(1, 'A', range(1, 14)),
Foo(2, 'B', range(1, 14)),
Foo(3, 'C', range(1, 14))
Foo(1, 'A', list(range(1, 14))),
Foo(2, 'B', list(range(1, 14))),
Foo(3, 'C', list(range(1, 14)))
]
table = CalendarColumnTable(data)
return render(request, "index.html", {'people': table})
Expand Down
2 changes: 1 addition & 1 deletion example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding: utf-8
from django.conf.urls import patterns, include, url

from app.views import MyDataView
from .app.views import MyDataView


urlpatterns = patterns('',
Expand Down
175 changes: 88 additions & 87 deletions table/columns/base.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,88 @@
#!/usr/bin/env python
# coding: utf-8

from django.utils.html import escape

from table.utils import Accessor, AttributesDict


class Column(object):
""" Represents a single column.
"""

instance_order = 0

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):
self.field = field
self.attrs = attrs or {}
self.sortable = sortable
self.searchable = searchable
self.safe = safe
self.visible = visible
self.space = space
self.header = ColumnHeader(header, header_attrs, header_row_order)

self.instance_order = Column.instance_order
Column.instance_order += 1

def __str__(self):
return self.header.text

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


class BoundColumn(object):
""" A run-time version of Column. The difference between
BoundColumn and Column is that BoundColumn objects include the
relationship between a Column and a object. In practice, this
means that a BoundColumn knows the "field value" given to the
Column when it was declared on the Table.
"""
def __init__(self, obj, column):
self.obj = obj
self.column = column
self.base_attrs = column.attrs.copy()

# copy non-object-related attributes to self directly
self.field = column.field
self.sortable = column.sortable
self.searchable = column.searchable
self.safe = column.safe
self.visible = column.visible
self.header = column.header

@property
def html(self):
text = self.column.render(self.obj)
if text is None:
return ''
else:
return text

@property
def attrs(self):
attrs = {}
for attr_name, attr in self.base_attrs.items():
if callable(attr):
attrs[attr_name] = attr(self.obj, self.field)
elif isinstance(attr, Accessor):
attrs[attr_name] = attr.resolve(self.obj)
else:
attrs[attr_name] = attr
return AttributesDict(attrs).render()


class ColumnHeader(object):
def __init__(self, text=None, attrs=None, row_order=0):
self.text = text
self.base_attrs = attrs or {}
self.row_order = row_order

@property
def attrs(self):
return AttributesDict(self.base_attrs).render()
#!/usr/bin/env python
# coding: utf-8

from django.utils.html import escape

from table.utils import Accessor, AttributesDict
import collections


class Column(object):
""" Represents a single column.
"""

instance_order = 0

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):
self.field = field
self.attrs = attrs or {}
self.sortable = sortable
self.searchable = searchable
self.safe = safe
self.visible = visible
self.space = space
self.header = ColumnHeader(header, header_attrs, header_row_order)

self.instance_order = Column.instance_order
Column.instance_order += 1

def __str__(self):
return self.header.text

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


class BoundColumn(object):
""" A run-time version of Column. The difference between
BoundColumn and Column is that BoundColumn objects include the
relationship between a Column and a object. In practice, this
means that a BoundColumn knows the "field value" given to the
Column when it was declared on the Table.
"""
def __init__(self, obj, column):
self.obj = obj
self.column = column
self.base_attrs = column.attrs.copy()

# copy non-object-related attributes to self directly
self.field = column.field
self.sortable = column.sortable
self.searchable = column.searchable
self.safe = column.safe
self.visible = column.visible
self.header = column.header

@property
def html(self):
text = self.column.render(self.obj)
if text is None:
return ''
else:
return text

@property
def attrs(self):
attrs = {}
for attr_name, attr in list(self.base_attrs.items()):
if isinstance(attr, collections.Callable):
attrs[attr_name] = attr(self.obj, self.field)
elif isinstance(attr, Accessor):
attrs[attr_name] = attr.resolve(self.obj)
else:
attrs[attr_name] = attr
return AttributesDict(attrs).render()


class ColumnHeader(object):
def __init__(self, text=None, attrs=None, row_order=0):
self.text = text
self.base_attrs = attrs or {}
self.row_order = row_order

@property
def attrs(self):
return AttributesDict(self.base_attrs).render()
6 changes: 3 additions & 3 deletions table/columns/linkcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def url(self):
for arg in self.args]
if self.kwargs:
params['kwargs'] = {}
for key, value in self.kwargs.items():
for key, value in list(self.kwargs.items()):
params['kwargs'][key] = (value.resolve(self.obj)
if isinstance(value, Accessor) else value)
if self.urlconf:
Expand Down Expand Up @@ -85,9 +85,9 @@ def render(self, obj):
'%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()
for attr_name, attr in list(self.attrs.items())
])
return mark_safe(u'<a %s>%s</a>' % (attrs, self.text))
return mark_safe('<a %s>%s</a>' % (attrs, self.text))


class ImageLink(Link):
Expand Down
2 changes: 1 addition & 1 deletion table/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QueryDataForm(forms.Form):

def __init__(self, data=None, *args, **kwargs):
super(QueryDataForm, self).__init__(data, *args, **kwargs)
for key in data.keys():
for key in list(data.keys()):
if key.startswith("iSortCol"):
self.fields[key] = forms.IntegerField()
if key.startswith("sSortDir"):
Expand Down
Loading