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

Fix template packaging #580

Merged
merged 3 commits into from
Jan 6, 2017
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
5 changes: 4 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ recursive-include docs *
recursive-include requirements *
recursive-include tests *
recursive-include django_filters/locale *
prune docs/_build
recursive-include django_filters/templates *.html
prune docs/_build
global-exclude __pycache__
global-exclude *.py[co]
39 changes: 5 additions & 34 deletions django_filters/rest_framework/backends.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@

from __future__ import absolute_import

from django.template import RequestContext, Template, TemplateDoesNotExist, loader
from django.template import loader
from django.utils import six

from .. import compat
from . import filterset


CRISPY_TEMPLATE = """
{% load crispy_forms_tags %}
{% load i18n %}

<h2>{% trans "Field filters" %}</h2>
{% crispy filter.form %}
"""


FILTER_TEMPLATE = """
{% load i18n %}
<h2>{% trans "Field filters" %}</h2>
<form class="form" action="" method="get">
{{ filter.form.as_p }}
<button type="submit" class="btn btn-primary">{% trans "Submit" %}</button>
</form>
"""


class DjangoFilterBackend(object):
default_filter_set = filterset.FilterSet

Expand All @@ -36,12 +17,6 @@ def template(self):
return 'django_filters/rest_framework/crispy_form.html'
return 'django_filters/rest_framework/form.html'

@property
def template_default(self):
if compat.is_crispy():
return CRISPY_TEMPLATE
return FILTER_TEMPLATE

def get_filter_class(self, view, queryset=None):
"""
Return the django-filters `FilterSet` used to filter the queryset.
Expand Down Expand Up @@ -82,16 +57,12 @@ def to_html(self, request, queryset, view):
return None
filter_instance = filter_class(request.query_params, queryset=queryset, request=request)

try:
template = loader.get_template(self.template)
except TemplateDoesNotExist:
template = Template(self.template_default)

context = RequestContext(request, {
template = loader.get_template(self.template)
context = {
'filter': filter_instance
})
}

return template.render(context)
return template.render(context, request)

def get_schema_fields(self, view):
# This is not compatible with widgets where the query param differs from the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load crispy_forms_tags %}
{% load i18n %}

<h2>{% trans "Field filters" %}</h2>
{% crispy filter.form %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n %}
<h2>{% trans "Field filters" %}</h2>
<form class="form" action="" method="get">
{{ filter.form.as_p }}
<button type="submit" class="btn btn-primary">{% trans "Submit" %}</button>
</form>
6 changes: 0 additions & 6 deletions docs/guide/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ Django-filter can be installed from PyPI with tools like ``pip``:

Then add ``'django_filters'`` to your ``INSTALLED_APPS``.

.. note::

django-filter provides *some* localization for *some* languages. If you do
not need these translations (or would rather provide your own), then it is
unnecessary to add django-filter to the ``INSTALLED_APPS`` setting.


Requirements
------------
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
maintainer_email='carlton.gibson@noumenal.es',
url='http://github.com/carltongibson/django-filter/tree/master',
packages=find_packages(exclude=['tests']),
package_data={
'django_filters': [
'locale/*/LC_MESSAGES/*',
],
},
include_package_data=True,
Copy link
Collaborator Author

@rpkilby rpkilby Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw - my understanding is that package_data isn't necessary, given the use of a manifest and the include_package_data param.

license='BSD',
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand All @@ -54,6 +50,5 @@
'Programming Language :: Python :: 3.5',
'Framework :: Django',
],
include_package_data=True,
zip_safe=False,
)
9 changes: 9 additions & 0 deletions tests/rest_framework/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ def test_DTL_missing(self):

reload(backends)

def test_multiple_engines(self):
# See: https://github.com/carltongibson/django-filter/issues/578
DTL = {'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True}
ALT = {'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, 'NAME': 'alt'}

# multiple DTL backends
with override_settings(TEMPLATES=[DTL, ALT]):
self.test_backend_output()


@override_settings(ROOT_URLCONF='tests.rest_framework.test_backends')
class IntegrationTestDetailFiltering(CommonFilteringTestCase):
Expand Down