Skip to content

Commit

Permalink
Merge pull request #92 from asfaltboy/release/1.1.0
Browse files Browse the repository at this point in the history
Release: 1.1.0
  • Loading branch information
asfaltboy authored Sep 23, 2018
2 parents 67dc98a + 048a430 commit 92fa398
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 160 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ tests/db.sqlite*
/.eggs/
/htmlcov/
/advanced_filters/.coverage

.DS_Store
.pytest_cache
/tests/local.db
62 changes: 39 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,62 @@ language: python
sudo: false
cache: pip
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "pypy"
matrix:
include:
- python: "2.6"
env: DJANGO="Django>=1.5,<1.6"
- python: "2.6"
env: DJANGO="Django>=1.6,<1.7"
- python: "3.4"
env: DJANGO="Django>=1.9,<1.10"
- python: "3.4"
env: DJANGO="Django>=1.10,<1.11"
- python: "3.5"
env: DJANGO="Django>=1.9,<1.10"
- python: "3.5"
env: DJANGO="Django>=1.10,<1.11"
- python: "3.6"
env: DJANGO="Django>=1.11,<1.12"
- python: "3.6"
env: DJANGO="Django>=2.0,<2.1"
- python: "3.6"
env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
# - python: "3.7"
# env: DJANGO="Django>=2.0,<2.1"
# - python: "3.7"
# env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
exclude:
- python: "2.6"
- python: "2.7"
env: DJANGO="Django>=2.0,<2.1"
- python: "2.7"
env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
- python: "3.5"
env: DJANGO="Django>=1.7,<1.8"
- python: "3.3"
env: DJANGO="Django>=1.9,<1.10"
- python: "3.3"
env: DJANGO="Django>=1.10,<1.11"
- python: "3.3"
env: DJANGO="Django>=1.11,<1.12"
- python: "3.3"
env: DJANGO="Django>=2.0,<2.1"
- python: "pypy"
env: DJANGO="Django>=2.0,<2.1"
- python: "3.3"
env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
- python: "3.4"
- python: "3.5"
env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
- python: "pypy"
env: DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
env:
- DJANGO="Django>=1.5,<1.6"
- DJANGO="Django>=1.6,<1.7"
- DJANGO="Django>=1.7,<1.8"
- DJANGO="Django>=1.8,<1.9"
- DJANGO="Django>=1.9,<1.10"
- DJANGO="Django>=1.10,<1.11"
global:
- PYTEST_DJANGO=pytest-django==2.9.1
matrix:
- DJANGO="Django>=1.7,<1.8"
- DJANGO="Django>=1.8,<1.9"
- DJANGO="Django>=1.9,<1.10"
- DJANGO="Django>=1.10,<1.11"
- DJANGO="Django>=1.11,<1.12"
- DJANGO="Django>=2.0,<2.1"
- DJANGO="Django>=2.1,<2.2" PYTEST_DJANGO="pytest-django==3.4.2"
install:
- pip install $DJANGO
- pip install -e .[test]
- pip install -e .[test] $PYTEST_DJANGO
script:
- coverage run -m py.test advanced_filters
- pep8 --exclude=*urls.py --exclude=*migrations advanced_filters -v
after_success:
coveralls
coveralls
41 changes: 41 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
Changelog
=========

1.1.0 - The future is bright
----------------------------

This release highlights support for Django 2.0 and 2.1 as well as
deprecating support for versions Django < 1.7 and Python 2.6 and 3.3

Bug fixes
~~~~~~~~~

- bump django-braces==1.13 for Django 2 support (Merge 80e055e)
- use request context processor in test_project (Merge 80e055e)

Misc.
~~~~~

- ignore .DS_Store
- fixes for Django 2.0 and 1.11, update tests (Merge 80e055e)
- test in Django 2.1 (Merge d8d236d)
- add updated migrations of model attributes (Merge 80e055e)
- fix ValueError while creating empty form (Merge d8d236d)
- python 2.6 and django < 1.7 are deprecated
- lower and upper bounds in install_requires
- avoid all-catch except clause (Merge 80e055e)

Tests
~~~~~

- correct tox env django spec for ver 1.11 (Merge 80e055e)
- correct make_query assertion for Django>=2 (Merge 80e055e)
- update pytest-django in diff. envs + tox (Merge d8d236d)

Contributors
~~~~~~~~~~~~

- Goncalo Gomes
- predatell
- Petr Dlouhý
- benny daon
- Pavel Savchenko


1.0.7.1 - Fix PyPi fail
-----------------------

Expand Down
15 changes: 10 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ For release notes, see `Changelog <https://raw.githubusercontent.com/modlinltd/d
Requirements
============

- Django >= 1.5 (Django 1.5 - 1.9 on Python 2/3/PyPy2)
- Django >= 1.7 (Django 1.7 - 2.1 on Python 2/3/PyPy2)
- django-braces == 1.4.0
- simplejson == 3.6.5

*NOTE*: While the latest Django 1.5.X is supported, the bundled jQuery it includes is outdated (1.4.2) and as such, most of our admin frontend scripts fail. This means that to use advanced-filters in Django 1.5 admin, you'd have to probably include your own jQuery (1.9 or later) and add it to global namespace prior to other scripts in `AdvancedFilterForm.Meta`.

Installation & Set up
=====================
Expand All @@ -53,11 +52,17 @@ Extending a ModelAdmin is pretty straightforward:
class ProfileAdmin(AdminAdvancedFiltersMixin, models.ModelAdmin):
list_filter = ('name', 'language', 'ts') # simple list filters
# select from these fields in the advanced filter creation form
# specify which fields can be selected in the advanced filter
# creation form
advanced_filter_fields = (
'name', 'language', 'ts'
'name',
'language',
'ts',
# even use related fields as lookup fields
'country__name', 'posts__title', 'comments__content'
'country__name',
'posts__title',
'comments__content',
)
Adding a new advanced filter (see below) will display a new list filter
Expand Down
2 changes: 1 addition & 1 deletion advanced_filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.7.1'
__version__ = '1.1.0'
15 changes: 2 additions & 13 deletions advanced_filters/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

from django.conf import settings
from django.contrib import admin, messages
from django.contrib.admin.utils import unquote
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _

try:
from django.contrib.admin.utils import unquote
except ImportError:
# django < 1.7 support
from django.contrib.admin.util import unquote
from django.shortcuts import resolve_url
from django.utils.translation import ugettext_lazy as _

from .forms import AdvancedFilterForm
from .models import AdvancedFilter
Expand Down Expand Up @@ -39,12 +34,6 @@ def queryset(self, request, queryset):
filters = AdvancedFilter.objects.filter(id=self.value())
if hasattr(filters, 'first'):
advfilter = filters.first()
else:
# django == 1.5 support
try:
advfilter = filters.order_by()[0]
except IndexError:
advfilter = None
if not advfilter:
logger.error("AdvancedListFilters.queryset: Invalid filter id")
return queryset
Expand Down
40 changes: 8 additions & 32 deletions advanced_filters/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@

from django import forms

try:
from django.apps import apps
get_model = apps.get_model
except ImportError:
# django < 1.7 support
from django.db.models import get_model
from django.apps import apps

from django.conf import settings
from django.contrib import admin

try:
from django.contrib.admin.utils import get_fields_from_path
except ImportError:
# django < 1.7 support
from django.contrib.admin.util import get_fields_from_path

from django.contrib.admin.utils import get_fields_from_path
from django.db.models import Q, FieldDoesNotExist
from django.db.models.fields import DateField
from django.forms.formsets import formset_factory, BaseFormSet
Expand Down Expand Up @@ -209,24 +198,10 @@ def __init__(self, *args, **kwargs):
form = self.forms[0]
self.fields = form.visible_fields()

@property
def empty_form(self):
form = self.form(
model_fields=self.model_fields,
auto_id=self.auto_id,
prefix=self.add_prefix('__prefix__'),
empty_permitted=True,
)
self.add_fields(form, None)
return form

def _construct_forms(self):
# not strictly required, but Django 1.5 calls this on init
# django == 1.5 support
self.forms = []
for i in range(min(self.total_form_count(), self.absolute_max)):
self.forms.append(self._construct_form(
i, model_fields=self.model_fields))
def get_form_kwargs(self, index):
kwargs = super(AdvancedFilterFormSet, self).get_form_kwargs(index)
kwargs['model_fields'] = self.model_fields
return kwargs

@cached_property
def forms(self):
Expand All @@ -236,6 +211,7 @@ def forms(self):
forms.append(self.empty_form) # add initial empty form
return forms


AFQFormSet = formset_factory(
AdvancedFilterQueryForm, formset=AdvancedFilterFormSet,
extra=1, can_delete=True)
Expand Down Expand Up @@ -300,7 +276,7 @@ def __init__(self, *args, **kwargs):
self._model = model_admin.model
elif instance and instance.model:
# get existing instance model
self._model = get_model(*instance.model.split('.'))
self._model = apps.get_model(*instance.model.split('.'))
try:
model_admin = admin.site._registry[self._model]
except KeyError:
Expand Down
45 changes: 45 additions & 0 deletions advanced_filters/migrations/0003_auto_20180610_0718.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 2.0.6 on 2018-06-10 07:18

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('advanced_filters', '0002_advancedfilter_created_at'),
]

operations = [
migrations.AlterField(
model_name='advancedfilter',
name='created_at',
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Created at'),
),
migrations.AlterField(
model_name='advancedfilter',
name='created_by',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='created_advanced_filters', to=settings.AUTH_USER_MODEL, verbose_name='Created by'),
),
migrations.AlterField(
model_name='advancedfilter',
name='groups',
field=models.ManyToManyField(blank=True, to='auth.Group', verbose_name='Groups'),
),
migrations.AlterField(
model_name='advancedfilter',
name='title',
field=models.CharField(max_length=255, verbose_name='Title'),
),
migrations.AlterField(
model_name='advancedfilter',
name='url',
field=models.CharField(max_length=255, verbose_name='URL'),
),
migrations.AlterField(
model_name='advancedfilter',
name='users',
field=models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL, verbose_name='Users'),
),
]
8 changes: 6 additions & 2 deletions advanced_filters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class Meta:
verbose_name_plural = _('Advanced Filters')

title = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('Title'))
created_by = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='created_advanced_filters', verbose_name=_('Created by'))
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name='created_advanced_filters',
verbose_name=_('Created by'),
on_delete=models.CASCADE,
)
created_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name=_('Created at'))
url = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('URL'))
users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, verbose_name=_('Users'))
Expand Down
2 changes: 1 addition & 1 deletion advanced_filters/q_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def dumps(self, obj):
raise SerializationError
string = json.dumps(self.serialize(obj), default=dt2ts)
if self.b64_enabled:
return base64.b64encode(six.b(string))
return base64.b64encode(six.b(string)).decode("utf-8")
return string

def loads(self, string, raw=False):
Expand Down
4 changes: 1 addition & 3 deletions advanced_filters/templates/admin/advanced_filters.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends original_change_list_template %}
{% load i18n static admin_modify %}
{# django == 1.5 support #}
{# {% load cycle from future %} #}

{% block extrastyle %}
{{ advanced_filters.media.css }}
Expand Down Expand Up @@ -79,7 +77,7 @@ <h1>{% trans "Create advanced filter" %}:</h1>
// Do nothing if target element is select2 input
if( $(e.target).hasClass('select2-input') ) {
return true;
}
}
// Else call parent method
$.magnificPopup.proto._onFocusIn.call(this,e);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% extends "admin/change_form.html" %}

{% load i18n admin_static admin_modify admin_urls %}
{# django == 1.5 support #}
{# {% load cycle from future %} #}

{% block extrastyle %}
{{ adminform.media.css }}
Expand Down Expand Up @@ -51,7 +49,7 @@ <h1>{% trans "Change advanced filter" %}:</h1>
{% submit_row %}
<input method="POST" name="_save_goto" type="submit" value="{% trans "Save & Filter Now!" %}">
{% endblock %}

<!-- JS for prepopulated fields -->
{% prepopulated_fields_js %}
{{ adminform.media.js }}
Expand Down
Loading

0 comments on commit 92fa398

Please sign in to comment.