Commits

Luke Plant committed 26d97ec

Initial import.

Basic app structure present, not much more!

Comments (0)

Files changed (17)

+Luke Plant <http://lukeplant.me.uk>
+Version 0.1
+-----------
+
+Initial release
+Copyright (c) 2010 Luke Plant
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+include *.rst
+include LICENSE
+include AUTHORS
+include docs/Makefile
+include docs/conf.py
+include manage.py
+include test_settings.py
+recursive-include docs *.rst
+====================
+ Django EasyFilters
+====================
+
+Overview
+========
+
+
+Usage
+=====
+
+
+
+Development
+===========
+
+First, ensure the directory containing this README is on your Python path
+(virtualenv recommended). Django is a required dependency.
+
+To run the test suite, do::
+
+   ./manage.py test django_easyfilters
+
+To edit the test fixtures, first create an empty db:
+
+   rm tests.db
+   ./manage.py syncdb
+
+Then load with current test fixture:
+
+   ./manage.py loaddata django_easyfilters_tests
+
+Then edit in admin at http://localhost:8000/admin/ ::
+
+   ./manage.py runserver
+
+Or from a Python shell.
+
+Then dump data::
+
+  ./manage.py dumpdata tests --format=json --indent=2 > django_easyfilters/tests/fixtures/django_easyfilters_tests.json

django_easyfilters/__init__.py

+from filterset import FilterSet

django_easyfilters/filterset.py

+
+standard_filter_mapping = {
+
+}
+
+class Filter(object):
+
+    def get_choices(self, qs, params, request=None):
+        pass
+
+    def get_remove_link(self, params, request=None):
+        pass
+
+class FilterSet(object):
+
+    filter_mapping = standard_filter_mapping
+    include_count = True
+
+
+    def __init__(self, params, queryset, request=None):
+        self.params = params
+        self.initial_queryset = queryset
+        self.qs = self.apply_filters(params, queryset)
+
+    def apply_filters(self, params, queryset):
+        return queryset
+
+    def render(self):
+        pass
+
+    def get_fields(self):
+        return self.fields
+
+    def get_filters(self):
+        filters = []
+        for f in fields:
+            if isinstance(basestring, f):
+                filters.append(get_filter_for_field(f))
+            else:
+                filters.append(f)
+        return filters

django_easyfilters/models.py

Empty file added.

django_easyfilters/tests/__init__.py

+from filterset import *
+

django_easyfilters/tests/admin.py

+# admin registration to make it easy to add more data for the test suite.
+
+from models import *
+from django.contrib import admin
+
+class BookAdmin(admin.ModelAdmin):
+    def authors(obj):
+        return ", ".join(unicode(a) for a in obj.authors.all())
+    list_display = ["name", authors, "binding", "genre", "price", "date_published"]
+    list_editable = ["binding", "genre", "price", "date_published"]
+    list_filter = ["genre", "authors", "binding", "price"]
+
+admin.site.register(Book, BookAdmin)
+admin.site.register(Author)
+admin.site.register(Genre)

django_easyfilters/tests/filterset.py

+import decimal
+
+from django.test import TestCase
+from django_easyfilters import FilterSet
+
+from models import Book, Genre
+
+
+class BookFilterSet(FilterSet):
+    fields = [
+        'binding',
+        ]
+    model = Book
+
+
+class TestFilterSet(TestCase):
+
+    fixtures = ['django_easyfilters_tests']
+
+    def test_no_filters(self):
+        qs = Book.objects.all()
+        data = {}
+        f = BookFilterSet(data, qs)
+        self.assertEqual(qs.count(), f.qs.count())

django_easyfilters/tests/fixtures/django_easyfilters_tests.json

+[
+  {
+    "pk": 1, 
+    "model": "tests.author", 
+    "fields": {
+      "name": "Jane Austen"
+    }
+  }, 
+  {
+    "pk": 2, 
+    "model": "tests.author", 
+    "fields": {
+      "name": "Charlotte Bronte"
+    }
+  }, 
+  {
+    "pk": 3, 
+    "model": "tests.author", 
+    "fields": {
+      "name": "Lewis Carroll"
+    }
+  }, 
+  {
+    "pk": 4, 
+    "model": "tests.author", 
+    "fields": {
+      "name": "A. A. Milne"
+    }
+  }, 
+  {
+    "pk": 5, 
+    "model": "tests.author", 
+    "fields": {
+      "name": "E. H. Shepard"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "tests.genre", 
+    "fields": {
+      "name": "Romance"
+    }
+  }, 
+  {
+    "pk": 2, 
+    "model": "tests.genre", 
+    "fields": {
+      "name": "Fantasy"
+    }
+  }, 
+  {
+    "pk": 3, 
+    "model": "tests.genre", 
+    "fields": {
+      "name": "Children's"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "tests.book", 
+    "fields": {
+      "name": "Pride and Prejudice", 
+      "price": "5.99", 
+      "binding": "P", 
+      "date_published": "1813-01-28", 
+      "authors": [
+        1
+      ], 
+      "genre": 1
+    }
+  }, 
+  {
+    "pk": 2, 
+    "model": "tests.book", 
+    "fields": {
+      "name": "Emma", 
+      "price": "4.99", 
+      "binding": "H", 
+      "date_published": "1815-12-01", 
+      "authors": [
+        1
+      ], 
+      "genre": 1
+    }
+  }, 
+  {
+    "pk": 3, 
+    "model": "tests.book", 
+    "fields": {
+      "name": "Jane Eyre", 
+      "price": "3.5", 
+      "binding": "P", 
+      "date_published": "1847-10-16", 
+      "authors": [
+        2
+      ], 
+      "genre": 1
+    }
+  }, 
+  {
+    "pk": 4, 
+    "model": "tests.book", 
+    "fields": {
+      "name": "Through The Looking Glass", 
+      "price": "10.99", 
+      "binding": "H", 
+      "date_published": "1871-01-02", 
+      "authors": [
+        3
+      ], 
+      "genre": 2
+    }
+  }, 
+  {
+    "pk": 5, 
+    "model": "tests.book", 
+    "fields": {
+      "name": "Winnie-the-Pooh", 
+      "price": "5.99", 
+      "binding": "C", 
+      "date_published": "1926-10-14", 
+      "authors": [
+        4, 
+        5
+      ], 
+      "genre": 3
+    }
+  }
+]

django_easyfilters/tests/models.py

+from django.db import models
+
+
+BINDING_CHOICES = [
+    ('H', 'Hardback'),
+    ('P', 'Paperback'),
+    ('C', 'Cloth'),
+]
+
+class Author(models.Model):
+    name = models.CharField(max_length=50)
+
+    def __unicode__(self):
+        return self.name
+
+
+class Genre(models.Model):
+    name = models.CharField(max_length=50)
+
+    def __unicode__(self):
+        return self.name
+
+class Book(models.Model):
+    name = models.CharField(max_length=100)
+    binding = models.CharField(max_length=2, choices=BINDING_CHOICES)
+    authors = models.ManyToManyField(Author)
+    genre = models.ForeignKey(Genre)
+    price = models.DecimalField(max_digits=6, decimal_places=2)
+    date_published = models.DateField()
+
+    def __unicode__(self):
+        return self.name
+

django_easyfilters/tests/urls.py

+# URLs to make it easy to add more data for the test suite.
+
+from django.conf.urls.defaults import *
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    # Normal views
+    (r'^admin/', include(admin.site.urls)),
+
+)
+
+#!/usr/bin/env python
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'
+from django.core import management
+if __name__ == "__main__":
+    management.execute_from_command_line()
+#!/usr/bin/env python
+from setuptools import setup, find_packages
+import os
+
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+
+setup(
+    name = "django-easyfilters",
+    version = '0.1',
+    packages = find_packages(),
+    include_package_data = True,
+
+    author = "Luke Plant",
+    author_email = "L.Plant.98@cantab.net",
+    url = "https://bitbucket.org/spookylukey/django-easyfilters/",
+    description = "Intelligently add links that filter a list of Django model objects.",
+    long_description = (
+                        read('README.rst')
+                        + "\n\n" +
+                        read('CHANGES.rst')
+    ),
+    license = "MIT",
+    keywords = "django filter autofilter drilldown",
+    classifiers = [
+        "Development Status :: 3 - Alpha",
+        "Environment :: Web Environment",
+        "Intended Audience :: Developers",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+        "Programming Language :: Python",
+        "Framework :: Django",
+        "Topic :: Software Development :: User Interfaces",
+        ],
+    install_requires = ['django >= 1.0'],
+)
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': 'tests.db',
+    },
+}
+
+INSTALLED_APPS = [
+    'django.contrib.auth',
+    'django.contrib.admin',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.contenttypes',
+    'django_easyfilters',
+    'django_easyfilters.tests',
+]
+
+ROOT_URLCONF = 'django_easyfilters.tests.urls'
+
+DEBUG = True
+
+SITE_ID = 1
+