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

Re-enable support for Django 1.3. #60

Merged
merged 8 commits into from
Oct 20, 2012
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python:
env:
- DJANGO=https://github.com/django/django/zipball/master
- DJANGO=django==1.4.1 --use-mirrors
- DJANGO=django==1.3.3 --use-mirrors

install:
- pip install $DJANGO
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Requirements
------------

* Python 2.6+
* Django 1.4+
* Django 1.3+

Installation
------------
Expand Down
8 changes: 7 additions & 1 deletion django_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from django.db.models import Q
from django.db.models.sql.constants import QUERY_TERMS
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now

# timezone support is new in Django 1.4.
try:
from django.utils.timezone import now
except ImportError:
from datetime import datetime
now = datetime.now

from django_filters.fields import RangeField, LookupTypeField

Expand Down
126 changes: 126 additions & 0 deletions django_filters/tests/fixtures/test_data_django_13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[
{
"fields": {
"favorite_books": [
1,
2
],
"first_name": "",
"is_active": false,
"last_name": "",
"status": 1,
"username": "alex"
},
"model": "tests.user",
"pk": 1
},
{
"fields": {
"favorite_books": [
1,
3
],
"first_name": "",
"is_active": false,
"last_name": "",
"status": 0,
"username": "aaron"
},
"model": "tests.user",
"pk": 2
},
{
"fields": {
"favorite_books": [],
"first_name": "",
"is_active": true,
"last_name": "",
"status": 0,
"username": "jacob"
},
"model": "tests.user",
"pk": 3
},
{
"fields": {
"author": 1,
"date": "2010-01-30",
"text": "super awesome!",
"time": "03:04:05"
},
"model": "tests.comment",
"pk": 1
},
{
"fields": {
"author": 2,
"date": "2010-01-27",
"text": "psycadelic!",
"time": "05:04:03"
},
"model": "tests.comment",
"pk": 2
},
{
"fields": {
"author": 3,
"date": "2009-12-31",
"text": "funky fresh!",
"time": "12:55:00"
},
"model": "tests.comment",
"pk": 3
},
{
"fields": {
"author": 1,
"published": "2010-07-08 00:00:00"
},
"model": "tests.article",
"pk": 1
},
{
"fields": {
"author": 1,
"published": "2010-08-08 00:00:00"
},
"model": "tests.article",
"pk": 2
},
{
"fields": {
"author": 3,
"published": "2010-09-03 00:00:00"
},
"model": "tests.article",
"pk": 3
},
{
"fields": {
"average_rating": 4.7999999999999998,
"price": "10",
"title": "Ender's Game"
},
"model": "tests.book",
"pk": 1
},
{
"fields": {
"average_rating": 4.5999999999999996,
"price": "15",
"title": "Rainbox Six"
},
"model": "tests.book",
"pk": 2
},
{
"fields": {
"average_rating": 4.2999999999999998,
"price": "20",
"title": "Snowcrash"
},
"model": "tests.book",
"pk": 3
}
]

6 changes: 5 additions & 1 deletion django_filters/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.conf.urls import patterns
# The patterns method moved in Django 1.4.
try:
from django.conf.urls import patterns
except ImportError:
from django.conf.urls.defaults import patterns

from django_filters.tests.models import Book

Expand Down
43 changes: 35 additions & 8 deletions django_filters/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from django import forms
from django.conf import settings
from django.test import TestCase
from django.utils.timezone import now

# timezone support is new in Django 1.4
try:
from django.utils.timezone import now
except ImportError:
from datetime import datetime
now = datetime.now

from django_filters.filterset import FilterSet
from django_filters.filters import (AllValuesFilter, CharFilter, ChoiceFilter,
Expand All @@ -13,10 +19,31 @@

from django_filters.tests.models import User, Comment, Book, Restaurant, Article, STATUS_CHOICES

import django
if django.VERSION[:2] >= (1,4):
test_fixture_name = 'test_data'
else:
# Same as test_data except that datetime values don't have timezones.
test_fixture_name = 'test_data_django_13'


class TestCase(TestCase):
"""
Redefined TestCase to add assertQuerysetEqual() with an 'ordered' parameter.
The 'ordered' parameter was added in Django 1.4.
"""

def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True):
items = map(transform, qs)
if not ordered:
return self.assertEqual(set(items), set(values))
return self.assertEqual(list(items), values)


class GenericViewTests(TestCase):
urls = 'django_filters.tests.test_urls'
fixtures = ['test_data']

fixtures = [test_fixture_name]
template_dirs = [
os.path.join(os.path.dirname(__file__), 'templates'),
]
Expand Down Expand Up @@ -87,7 +114,7 @@ class Meta:


class AllValuesFilterTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_filter(self):
class F(FilterSet):
Expand All @@ -109,7 +136,7 @@ class Meta:


class InitialValueTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_initial(self):
class F(FilterSet):
Expand All @@ -124,7 +151,7 @@ class Meta:


class RelatedObjectTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_foreignkey(self):
class F(FilterSet):
Expand Down Expand Up @@ -154,7 +181,7 @@ class Meta:


class MultipleChoiceFilterTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_all_choices_selected(self):
class F(FilterSet):
Expand All @@ -166,7 +193,7 @@ class Meta:


class MultipleLookupTypesTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_no_GET_params(self):
class F(FilterSet):
Expand All @@ -180,7 +207,7 @@ class Meta:


class FilterSetTest(TestCase):
fixtures = ['test_data']
fixtures = [test_fixture_name]

def test_base_filters(self):
class F(FilterSet):
Expand Down