This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Abstract

Library to implement reusable queryset filtering for django-powered websites.

This library provides a way to declaratively define filter specifications in a django-forms manner. Such forms can be used as ordinary django forms and they also provides a method filter to perform filtering of arbitrary querysets.

This approach is somewhat differs from one in django-admin, but it looks more intuitive and straightforward for the author.

Main features:

  • forms-based declaration and usage;
  • simple API;
  • easy to implement and reuse abstract filter specs of any complexity (from standard lookups to QuerySet.extra calls);
  • runtime-aware filtering;
  • a number of builtin specs for simple cases.

Usage

For concrete usage example, see sample_proj/polls/views.py.

To perform filtering one must define a subclass of datafilters.filterform.FilterForm (base class for filter forms). The typical declaration consists of class attributes declaring filter specifications, subclasses of datafilters.filterspec.FilterSpec. This tandem is very much like the Form and Field pair. FilterSpec subclass defines a corresponding form field that will be used to render and validate a django form and it also defines a method to get lookup conditions based on user input (to_lookup). There is a bunch of builtin specs so typicaly it is not necessary to implement your own filter specs for simple filtering.

For example purposes we will use models from django tutorial: Choice and Question.

The typical filter form looks like that:

from datafilters.filterform import FilterForm
from datafilters.specs import ContainsFilterSpec, \
    SelectBoolFilterSpec

class ChoicesFilterForm(FilterForm):
    choice_text = ContainsFilterSpec('choice',
                                     label='Choice contains text')
    question_text = ContainsFilterSpec('poll__question',
                                       label='Question contains text')
    has_votes = GreaterThanZeroFilterSpec('votes')

Direct usage of filter form

Defined form can be used directly:

from django.shortcuts import render_to_response
from polls.models import Choice

def choice_list(request):
    choices = Choice.objects.all()
    filterform = ChoicesFilterForm(request.GET)
    if filterform.is_valid():
        choices = filterform.filter(choices)

    return render_to_response('polls/choice_list.html',
        {
            'choices': choices,
            'filterform': filterform,
        })

filter_powered decorator

There is a decorator to remove bottlenecks when using filtering extensively:

from django.template.response import TemplateResponse
from datafilters.decorators import filter_powered

@filter_powered(ChoicesFilterForm, queryset_name='choices')
def choice_list(request):
    choices = Choice.objects.all()
    return TemplateResponse('polls/choice_list.html',
        {'choices': choices})

View mixin

If you are using django class-based views there is another option to take: a view mixin FilterFormMixin. Example:

from django.views.generic import ListView

class ChoiceListView(FilterFormMixin, ListView):
    model = Choice
    filter_form_cls = ChoicesFilterForm

choice_list = ChoiceListView.as_view()

Usage in templates

In our template we can use new context variable filterform as an ordinary django form:

<form class="filter" method="get" action="">
    {{ filterform.as_p }}
    <input type="submit" value="Apply filter" />
</form>

Requirements

Release History

Release History

0.3.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
datafilters-0.3.3.win-amd64.exe (246.0 kB) Copy SHA256 Checksum SHA256 any Windows Installer Jul 24, 2013
datafilters-0.3.3.zip (25.0 kB) Copy SHA256 Checksum SHA256 Source Jul 24, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting