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

added support of Django 2.0 #13

Open
wants to merge 2 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
Binary file removed dist/django-grappelli-filters-0.2.tar.gz
Binary file not shown.
2 changes: 0 additions & 2 deletions grappelli_filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from .filters import RelatedAutocompleteFilter, SearchFilter, SearchFilterC
from .admin import FiltersMixin
8 changes: 3 additions & 5 deletions grappelli_filters/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.contrib import admin
from django.templatetags.static import static


class FiltersMixin( admin.ModelAdmin ):

class FiltersMixin(admin.ModelAdmin):
class Media:
js = (static('grappelli_filters/filter.js'),)
js = ('grappelli_filters/filter.js', )
css = {
'all': (static('grappelli_filters/filter.css'),),
'all': ('grappelli_filters/filter.css', )
}
19 changes: 7 additions & 12 deletions grappelli_filters/filters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from django.contrib import admin
from django.contrib.contenttypes.models import ContentType


class AbstractFieldListFilter(admin.FieldListFilter):
tempalte = ''
filter_parameter = None
url_parameter = None

Expand All @@ -21,10 +19,6 @@ def has_output(self):
""" Whether to show filter """
return True

def lookups(self, request, model_admin):
""" Not using lookups """
return ()

def choices(self, cl):
""" Not used, but required by admin_list_filter template tag """
return ()
Expand Down Expand Up @@ -54,15 +48,17 @@ class RelatedAutocompleteFilter(AbstractFieldListFilter):
def get_parameter_name(self, field_path):
if self.url_parameter:
field_path = self.url_parameter
return u'{0}__id__exact'.format(field_path)
return '{0}__id__exact'.format(field_path)

def __init__(self, field, request, params, model, model_admin, field_path):
from django.contrib.contenttypes.models import ContentType

super(RelatedAutocompleteFilter, self).__init__(field, request, params, model, model_admin, field_path)
if self.model:
content_type = ContentType.objects.get_for_model(self.model)
else:
content_type = ContentType.objects.get_for_model(field.rel.to)
self.grappelli_trick = u'/{app_label}/{model_name}/'.format(
content_type = ContentType.objects.get_for_model(field.remote_field.model)
self.grappelli_trick = '/{app_label}/{model_name}/?_to_field=id'.format(
app_label=content_type.app_label,
model_name=content_type.model
)
Expand All @@ -72,12 +68,11 @@ class SearchFilter(AbstractFieldListFilter):
template = 'grappelli_filters/search.html'

def get_parameter_name(self, field_path):
return u'{0}__icontains'.format(field_path)
return '{0}__icontains'.format(field_path)


class SearchFilterC(SearchFilter):
""" Case-sensitive serach filter """

def get_parameter_name(self, field_path):
return u'{0}__contains'.format(field_path)

return '{0}__contains'.format(field_path)
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from setuptools import setup

README = open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8').read()
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
Expand All @@ -21,13 +21,17 @@
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Intended Audience :: Developers',
'License :: Freeware',
'Operating System :: OS Independent',
'Programming Language :: Python',
# Replace these appropriately if you are stuck on Python 2.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
Expand Down