Merge pull request #60 from onepercentclub/django-1.3-compat
Re-enable support for Django 1.3.
This commit is contained in:
commit
99542655ab
|
@ -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
|
||||
|
|
|
@ -13,7 +13,7 @@ Requirements
|
|||
------------
|
||||
|
||||
* Python 2.6+
|
||||
* Django 1.4+
|
||||
* Django 1.3+
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
|
|
@ -4,7 +4,13 @@ from django import forms
|
|||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
@ -3,7 +3,13 @@ import os
|
|||
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,
|
||||
|
@ -13,10 +19,31 @@ from django_filters.widgets import LinkWidget
|
|||
|
||||
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'),
|
||||
]
|
||||
|
@ -87,7 +114,7 @@ class FilterSetForm(TestCase):
|
|||
|
||||
|
||||
class AllValuesFilterTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_filter(self):
|
||||
class F(FilterSet):
|
||||
|
@ -109,7 +136,7 @@ class AllValuesFilterTest(TestCase):
|
|||
|
||||
|
||||
class InitialValueTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_initial(self):
|
||||
class F(FilterSet):
|
||||
|
@ -124,7 +151,7 @@ class InitialValueTest(TestCase):
|
|||
|
||||
|
||||
class RelatedObjectTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_foreignkey(self):
|
||||
class F(FilterSet):
|
||||
|
@ -154,7 +181,7 @@ class RelatedObjectTest(TestCase):
|
|||
|
||||
|
||||
class MultipleChoiceFilterTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_all_choices_selected(self):
|
||||
class F(FilterSet):
|
||||
|
@ -166,7 +193,7 @@ class MultipleChoiceFilterTest(TestCase):
|
|||
|
||||
|
||||
class MultipleLookupTypesTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_no_GET_params(self):
|
||||
class F(FilterSet):
|
||||
|
@ -180,7 +207,7 @@ class MultipleLookupTypesTest(TestCase):
|
|||
|
||||
|
||||
class FilterSetTest(TestCase):
|
||||
fixtures = ['test_data']
|
||||
fixtures = [test_fixture_name]
|
||||
|
||||
def test_base_filters(self):
|
||||
class F(FilterSet):
|
||||
|
|
Loading…
Reference in New Issue