Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
asfaltboy committed Mar 20, 2016
2 parents e1a70de + b82c691 commit 3642c6e
Show file tree
Hide file tree
Showing 29 changed files with 444 additions and 46 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
*.pyc
/.tox/
/.coverage
local_settings.py
/tests/test_project/host_settings.py
build/
dist/
django_advanced_filters.egg-info/
tests/db.sqlite3
tests/db.sqlite*
/.python-version
/.cache/
/.eggs/
/htmlcov/
/advanced_filters/.coverage
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ python:
- "3.4"
- "pypy"
matrix:
exclude:
include:
- python: "2.6"
env: DJANGO="Django>=1.5,<1.6"
- python: "2.6"
env: DJANGO="Django>=1.7,<1.8"
env: DJANGO="Django>=1.6,<1.7"
exclude:
- python: "2.6"
env: DJANGO="Django>=1.8,<1.9"
- python: "3.3"
env: DJANGO="Django>=1.9,<1.10"
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.9a"
- DJANGO="Django>=1.9,<1.10"
install:
- pip install $DJANGO
- pip install -e .[test]
script:
- coverage run -m py.test advanced_filters
- pep8 --exclude=*urls.py advanced_filters -v
- pep8 --exclude=*urls.py --exclude=*migrations advanced_filters -v
after_success:
coveralls
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 1.0.2 - A Better Future

This release features better test coverage and support for Django 1.9.

### Bugs
- stretch formset table to the modal container width
- toggle advanced `vendor/jquery` dir according to Django version
- retain support older Django versions
- clean up legacy tags in templates

### Tests
- add admin views tests
- add Django 1.9 to test matrix
- other minor improvements

### Docs
- Improve README with a newer screenshot and pretty tables for badges

### Contributors:
- Pavel Savchenko
- Leonardo J. Caballero G
- Schuyler Duveen

## 1.0.1 - A Public Release

### Bugs
Expand Down
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
## Django Advanced Filters

[![PyPI](https://img.shields.io/pypi/pyversions/django-advanced-filters.svg)](https://pypi.python.org/pypi/django-advanced-filters)
[![Build Status](https://travis-ci.org/modlinltd/django-advanced-filters.svg?branch=master)](https://travis-ci.org/modlinltd/django-advanced-filters)
[![Coverage Status](https://coveralls.io/repos/modlinltd/django-advanced-filters/badge.svg)](https://coveralls.io/r/modlinltd/django-advanced-filters)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/modlinltd/django-advanced-filters?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
| Branch | Build | Coverage | PyPI | Gitter |
| ------ | ----- | -------- | ---- | ------ |
| Master | [![Build Status][5]][7] | [![Coverage Status][8]][10] | [![PyPI][1]][2] | [![Gitter][3]][4] |
| Develop | [![Build Status][6]][7] | [![Coverage Status][9]][11] | 🔺 | 🔺 |


[1]: https://img.shields.io/pypi/pyversions/django-advanced-filters.svg
[2]: https://pypi.python.org/pypi/django-advanced-filters
[3]: https://badges.gitter.im/Join%20Chat.svg
[4]: https://gitter.im/modlinltd/django-advanced-filters?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[5]: https://travis-ci.org/modlinltd/django-advanced-filters.svg?branch=master
[6]: https://travis-ci.org/modlinltd/django-advanced-filters.svg?branch=develop
[7]: https://travis-ci.org/modlinltd/django-advanced-filters
[8]: https://coveralls.io/repos/modlinltd/django-advanced-filters/badge.svg?branch=master
[9]: https://coveralls.io/repos/modlinltd/django-advanced-filters/badge.svg?branch=develop
[10]: https://coveralls.io/github/modlinltd/django-advanced-filters?branch=master
[11]: https://coveralls.io/github/modlinltd/django-advanced-filters?branch=develop


A django ModelAdmin mixin which adds advanced filtering abilities to the admin.

Mimics the advanced search feature in [VTiger](https://www.vtiger.com/),
[see here for more info](https://wiki.vtiger.com/index.php/Create_Custom_Filters)

For release notes, see [Changelog](https://raw.githubusercontent.com/modlinltd/django-advanced-filters/develop/CHANGELOG.md)
![screenshot](https://raw.githubusercontent.com/modlinltd/django-advanced-filters/develop/screenshot.png "Creating via a modal")

For release notes, see [Changelog](https://raw.githubusercontent.com/modlinltd/django-advanced-filters/develop/CHANGELOG.md)

## Requirements

Expand Down Expand Up @@ -84,10 +99,6 @@ Regardless of the above, you can easily write your own template which uses
context variables `{{ advanced_filters }}` and
`{{ advanced_filters.formset }}`, to render the advanced filter creation form.

Here's a screenshot

![alt text](https://raw.githubusercontent.com/modlinltd/django-advanced-filters/master/screenshot.png "Creating via a modal")

## Structure

Each advanced filter has only a couple of required fields when constructed
Expand Down Expand Up @@ -185,8 +196,9 @@ list of valid field choices when creating/changing an `AdvancedFilter`.

## TODO

* Add more tests (specifically the admin and view parts)
* ~~Add more tests (specifically the admin and view parts)~~
* ~~Add packaging (setup.py, etc...)~~
* ~~Add edit/view functionality to the filters~~
* Add permission user/group selection functionality to the filter form
* Allow toggling of predefined templates (grappelli / vanilla django admin), and front-end features.
* Support more (newer) python/django versions
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.1'
__version__ = '1.0.2'
21 changes: 17 additions & 4 deletions advanced_filters/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin.util import unquote

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 .forms import AdvancedFilterForm
Expand All @@ -30,7 +35,15 @@ def lookups(self, request, model_admin):

def queryset(self, request, queryset):
if self.value():
advfilter = AdvancedFilter.objects.filter(id=self.value()).first()
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 Expand Up @@ -61,7 +74,7 @@ def save_advanced_filter(self, request, form):
request, messages.SUCCESS,
_('Advanced filter added successfully.')
)
if '_save_goto' in request.REQUEST:
if '_save_goto' in (request.GET or request.POST):
url = "{path}{qparams}".format(
path=request.path, qparams="?_afilter={id}".format(
id=afilter.id))
Expand All @@ -70,7 +83,7 @@ def save_advanced_filter(self, request, form):
logger.info('Failed saving advanced filter, params: %s', form.data)

def adv_filters_handle(self, request, extra_context={}):
data = request.POST if request.REQUEST.get(
data = request.POST if request.POST.get(
'action') == 'advanced_filters' else None
adv_filters_form = self.advanced_filter_form(
data=data, model_admin=self, extra_form=True)
Expand Down
27 changes: 23 additions & 4 deletions advanced_filters/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@
import operator

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.conf import settings
from django.contrib import admin
from django.contrib.admin.util import get_fields_from_path
from django.db.models import Q, get_model, FieldDoesNotExist

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.db.models import Q, FieldDoesNotExist
from django.db.models.fields import DateField
from django.forms.formsets import formset_factory, BaseFormSet
from django.templatetags.static import static
Expand All @@ -16,12 +30,16 @@
from django.utils.six.moves import range, reduce
from django.utils.text import capfirst

import django

from easy_select2.widgets import SELECT2_WIDGET_JS, SELECT2_CSS

from .models import AdvancedFilter
from .form_helpers import CleanWhiteSpacesMixin, VaryingTypeCharField


# django < 1.9 support
USE_VENDOR_DIR = django.VERSION >= (1, 9)
logger = logging.getLogger('advanced_filters.forms')


Expand Down Expand Up @@ -190,6 +208,7 @@ def empty_form(self):

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(
Expand Down Expand Up @@ -219,7 +238,8 @@ class Meta:
fields = ('title',)

class Media:
required_js = [static('admin/js/jquery.min.js'),
required_js = [static('admin/js/%sjquery.min.js' %
('vendor/jquery/' if USE_VENDOR_DIR else '')),
static('orig_inlines%s.js' %
('' if settings.DEBUG else '.min')),
static('magnific-popup/jquery.magnific-popup.js'),
Expand Down Expand Up @@ -274,7 +294,6 @@ def __init__(self, *args, **kwargs):

self._filter_fields = filter_fields or getattr(
model_admin, 'advanced_filter_fields', ())
print(filter_fields, model_admin, self._filter_fields)

super(AdvancedFilterForm, self).__init__(*args, **kwargs)

Expand Down
37 changes: 37 additions & 0 deletions advanced_filters/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-07 23:02
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='AdvancedFilter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('url', models.CharField(max_length=255)),
('b64_query', models.CharField(max_length=2048)),
('model', models.CharField(blank=True, max_length=64, null=True)),
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='created_advanced_filters', to=settings.AUTH_USER_MODEL)),
('groups', models.ManyToManyField(blank=True, to='auth.Group')),
('users', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'Advanced Filters',
'verbose_name': 'Advanced Filter',
},
),
]
Empty file.
4 changes: 4 additions & 0 deletions advanced_filters/static/advanced-filters/advanced-filters.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#form-group {
width: 100%;
}

.grp-object-tools li div {
display: block;
padding: 4px 15px;
Expand Down
3 changes: 2 additions & 1 deletion advanced_filters/templates/admin/advanced_filters.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "admin/change_list.html" %}
{% load i18n static admin_modify %}
{% load cycle from future %}
{# django == 1.5 support #}
{# {% load cycle from future %} #}

{% block extrastyle %}
{{ advanced_filters.media.css }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends "admin/change_form_orig.html" %}
{% extends "admin/change_form.html" %}

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

{% block extrastyle %}
{{ adminform.media.css }}
Expand Down
Loading

0 comments on commit 3642c6e

Please sign in to comment.