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

Debian squeeze python/django version dependancies #59

Closed
brianmay opened this issue Mar 10, 2012 · 2 comments
Closed

Debian squeeze python/django version dependancies #59

brianmay opened this issue Mar 10, 2012 · 2 comments

Comments

@brianmay
Copy link
Contributor

Unfortunately Debian stable only has Python 2.6. Fortunately, the solution is a one line change:

commit 46f7128107b29ed6521aa78a4e70a189a80e05dd
Author: Brian May <brian@microcomaustralia.com.au>
Date:   Sat Mar 10 18:05:06 2012 +1100

    Use old style syntax for exception, making it compatable with Python 2.6

diff --git a/django_tables2/columns.py b/django_tables2/columns.py
index 31ec9eb..186bb41 100644
--- a/django_tables2/columns.py
+++ b/django_tables2/columns.py
@@ -276,7 +276,7 @@ class LinkColumn(Column):
         # and use that to decide whether to render a link or just the default
         try:
             raw = bound_column.accessor.resolve(record)
-        except (TypeError, AttributeError, KeyError, ValueError) as e:
+        except (TypeError, AttributeError, KeyError, ValueError), e:
             raw = None
         if raw is None:
             return self.default

Unfortunately this might break Python 3.x compatibility if that is desired.

django-tables2, unfortunately requires django >= 1.3, at least there is a backport available for Debian stable. This is required for django.test.client.RequestFactory

I see that django.test.client.RequestFactory is only required for one method; a method I don't use - would it be possible to make this import optional?

@brianmay
Copy link
Contributor Author

Was brain dead when I supplied that patch, the e variable isn't even used, so it should be possible to have to work it with any recent python version:

--- a/django_tables2/columns.py
+++ b/django_tables2/columns.py
@@ -276,7 +276,7 @@ class LinkColumn(Column):
         # and use that to decide whether to render a link or just the default
         try:
             raw = bound_column.accessor.resolve(record)
-        except (TypeError, AttributeError, KeyError, ValueError) as e:
+        except (TypeError, AttributeError, KeyError, ValueError):
             raw = None
         if raw is None:
             return self.default

Also suggest something like this to remove the dependancy on Django 1.3, unless code uses the as_html() function:

--- a/django_tables2/tables.py
+++ b/django_tables2/tables.py
@@ -6,7 +6,6 @@ from django.http import Http404
 from django.utils.datastructures import SortedDict
 from django.template import RequestContext
 from django.template.loader import get_template
-from django.test.client import RequestFactory
 from django.utils.encoding import StrAndUnicode
 import sys
 from .utils import Accessor, AttributeDict, OrderBy, OrderByTuple, Sequence
@@ -285,6 +284,7 @@ class Table(StrAndUnicode):
         generated will clobber the querystring of the request. Use the
         ``{% render_table %}`` template tag instead.
         """
+        from django.test.client import RequestFactory
         request = RequestFactory().get('/')
         template = get_template(self.template)
         return template.render(RequestContext(request, {'table': self}))

@bradleyayers
Copy link
Collaborator

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants