Skip to content

Commit d6e68f4

Browse files
prepare 0.3.1
1 parent 8e9eb74 commit d6e68f4

File tree

20 files changed

+163
-84
lines changed

20 files changed

+163
-84
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
0.3.1
5+
-----
6+
2019-03-26
7+
8+
- More tests.
9+
- Addition to docs.
10+
411
0.3
512
---
613
2019-03-25

README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,25 @@ Usage
9898
9999
**Sample view**
100100

101+
With function-based views:
102+
101103
.. code-block:: python
102104
103105
def person_list(request):
104106
filter = PersonFilter(request.GET, queryset=Person.objects())
105107
return render(request, "dfm_app/person_list.html", {"objects": filter.qs})
106108
109+
Or class-based views:
110+
111+
.. code-block:: python
112+
113+
from django_mongoengine_filter.views import FilterView
114+
115+
class PersonListView(FilterView):
116+
117+
filterset_class = PersonFilter
118+
template_name = "dfm_app/person_list.html"
119+
107120
**Sample template**
108121

109122
.. code-block:: html

django_mongoengine_filter/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from .filterset import FilterSet
44
from .filters import *
55

6-
VERSION = (0, 2)
6+
VERSION = (0, 3, 1)
77

8-
__title__ = 'django-mongoengine-filter'
9-
__version__ = '.'.join([str(_i) for _i in VERSION])
10-
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
11-
__copyright__ = '2019 Artur Barseghyan'
12-
__license__ = 'GPL 2.0/LGPL 2.1'
8+
__title__ = "django-mongoengine-filter"
9+
__version__ = ".".join([str(_i) for _i in VERSION])
10+
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
11+
__copyright__ = "2019 Artur Barseghyan"
12+
__license__ = "GPL 2.0/LGPL 2.1"

django_mongoengine_filter/fields.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77

88
from .widgets import RangeWidget, LookupTypeWidget
99

10-
__all__ = (
11-
"Lookup",
12-
"LookupTypeField",
13-
"RangeField",
14-
)
10+
__all__ = ("Lookup", "LookupTypeField", "RangeField")
1511

1612

1713
class RangeField(forms.MultiValueField):
@@ -41,7 +37,6 @@ def __init__(self, field, lookup_choices, *args, **kwargs):
4137
def compress(self, data_list):
4238
if len(data_list) == 2:
4339
return Lookup(
44-
value=data_list[0],
45-
lookup_type=data_list[1] or "exact"
40+
value=data_list[0], lookup_type=data_list[1] or "exact"
4641
)
4742
return Lookup(value=None, lookup_type="exact")

django_mongoengine_filter/filters.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ def __init__(
7373
def field(self):
7474
if not hasattr(self, "_field"):
7575
help_text = _("This is an exclusion filter") if self.exclude else ""
76-
if self.lookup_type is None or isinstance(self.lookup_type, (list, tuple)):
76+
if self.lookup_type is None or isinstance(
77+
self.lookup_type, (list, tuple)
78+
):
7779
if self.lookup_type is None:
7880
lookup = [(x, x) for x in LOOKUP_TYPES]
7981
else:
80-
lookup = [(x, x) for x in LOOKUP_TYPES if x in self.lookup_type]
82+
lookup = [
83+
(x, x) for x in LOOKUP_TYPES if x in self.lookup_type
84+
]
8185
self._field = LookupTypeField(
8286
self.field_class(
8387
required=self.required, widget=self.widget, **self.extra
@@ -175,7 +179,9 @@ def filter(self, qs, value):
175179
if value:
176180
start_lookup = "%s__gte" % self.name
177181
stop_lookup = "%s__lte" % self.name
178-
return qs.filter(**{start_lookup: value.start, stop_lookup: value.stop})
182+
return qs.filter(
183+
**{start_lookup: value.start, stop_lookup: value.stop}
184+
)
179185
return qs
180186

181187

@@ -207,7 +213,10 @@ class DateRangeFilter(ChoiceFilter):
207213
3: (
208214
_("This month"),
209215
lambda qs, name: qs.filter(
210-
**{"%s__year" % name: now().year, "%s__month" % name: now().month}
216+
**{
217+
"%s__year" % name: now().year,
218+
"%s__month" % name: now().month,
219+
}
211220
),
212221
),
213222
4: (

django_mongoengine_filter/filterset.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ def __new__(cls, name, bases, attrs):
141141
# We are defining FilterSet itself here
142142
parents = None
143143
declared_filters = get_declared_filters(bases, attrs, False)
144-
new_class = super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
144+
new_class = super(FilterSetMetaclass, cls).__new__(
145+
cls, name, bases, attrs
146+
)
145147

146148
if not parents:
147149
return new_class
148150

149-
opts = new_class._meta = FilterSetOptions(getattr(new_class, "Meta", None))
151+
opts = new_class._meta = FilterSetOptions(
152+
getattr(new_class, "Meta", None)
153+
)
150154
if opts.model:
151155
filters = filters_for_model(
152156
opts.model,
@@ -161,7 +165,8 @@ def __new__(cls, name, bases, attrs):
161165

162166
if None in filters.values():
163167
raise TypeError(
164-
"Meta.fields contains a field that isn't defined " "on this FilterSet"
168+
"Meta.fields contains a field that isn't defined "
169+
"on this FilterSet"
165170
)
166171

167172
new_class.declared_filters = declared_filters
@@ -258,7 +263,9 @@ def qs(self):
258263
pass
259264

260265
if ordered_value in EMPTY_VALUES and self.strict:
261-
ordered_value = self.form.fields[self.order_by_field].choices[0][0]
266+
ordered_value = self.form.fields[
267+
self.order_by_field
268+
].choices[0][0]
262269

263270
if ordered_value:
264271
qs = qs.order_by(*self.get_order_by(ordered_value))
@@ -274,11 +281,16 @@ def count(self):
274281
def form(self):
275282
if not hasattr(self, "_form"):
276283
fields = OrderedDict(
277-
[(name, filter_.field) for name, filter_ in six.iteritems(self.filters)]
284+
[
285+
(name, filter_.field)
286+
for name, filter_ in six.iteritems(self.filters)
287+
]
278288
)
279289
fields[self.order_by_field] = self.ordering_field
280290
Form = type(
281-
str("%sForm" % self.__class__.__name__), (self._meta.form,), fields
291+
str("%sForm" % self.__class__.__name__),
292+
(self._meta.form,),
293+
fields,
282294
)
283295
if self.is_bound:
284296
self._form = Form(self.data, prefix=self.form_prefix)
@@ -312,11 +324,16 @@ def get_ordering_field(self):
312324
(fltr.name or f, fltr.label or capfirst(f)),
313325
(
314326
"-%s" % (fltr.name or f),
315-
_("%s (descending)" % (fltr.label or capfirst(f))),
327+
_(
328+
"%s (descending)"
329+
% (fltr.label or capfirst(f))
330+
),
316331
),
317332
]
318333
)
319-
return forms.ChoiceField(label="Ordering", required=False, choices=choices)
334+
return forms.ChoiceField(
335+
label="Ordering", required=False, choices=choices
336+
)
320337

321338
@property
322339
def ordering_field(self):
@@ -383,6 +400,8 @@ class FilterSet(six.with_metaclass(FilterSetMetaclass, BaseFilterSet)):
383400
def filterset_factory(model):
384401
meta = type(str("Meta"), (object,), {"model": model})
385402
filterset = type(
386-
str("%sFilterSet" % model._meta.object_name), (FilterSet,), {"Meta": meta}
403+
str("%sFilterSet" % model._meta.object_name),
404+
(FilterSet,),
405+
{"Meta": meta},
387406
)
388407
return filterset

django_mongoengine_filter/views.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88

99
from .filterset import filterset_factory
1010

11-
__all__ = (
12-
"BaseFilterView",
13-
"FilterMixin",
14-
"FilterView",
15-
"object_filter",
16-
)
11+
__all__ = ("BaseFilterView", "FilterMixin", "FilterView", "object_filter")
1712

1813

1914
class FilterMixin(object):

django_mongoengine_filter/widgets.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
from django.utils.safestring import mark_safe
2525
from django.utils.translation import ugettext as _
2626

27-
__all__ = (
28-
"LinkWidget",
29-
"LookupTypeWidget",
30-
"RangeWidget",
31-
)
27+
__all__ = ("LinkWidget", "LookupTypeWidget", "RangeWidget")
3228

3329

3430
class LinkWidget(forms.Widget):

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
0.3.1
5+
-----
6+
2019-03-26
7+
8+
- More tests.
9+
- Addition to docs.
10+
411
0.3
512
---
613
2019-03-25

docs/conf.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ class Settings(object):
3838

3939
docs_settings = Settings()
4040
docs_settings.DATABASES = {
41-
"default": {
42-
"ENGINE": "django.db.backends.sqlite3",
43-
"NAME": ":memory:"
44-
}
41+
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
4542
}
4643

4744
docs_settings.SECRET_KEY = "top-secret"
@@ -75,11 +72,7 @@ class Settings(object):
7572
}
7673
]
7774

78-
docs_settings.ALLOWED_HOSTS = [
79-
'*',
80-
'127.0.0.1',
81-
'localhost',
82-
]
75+
docs_settings.ALLOWED_HOSTS = ["*", "127.0.0.1", "localhost"]
8376

8477
# -- Django configuration ------------------------------------------------------
8578
from django.conf import settings

0 commit comments

Comments
 (0)