[PATCH 5/5] REST: Order 'filters' code

Stephen Finucane stephen at that.guru
Mon Mar 26 05:28:23 AEDT 2018


Group custom filters and fields together followed by the actual filter
sets. This makes the file a little easier to comprehend.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/api/filters.py | 86 +++++++++++++++++++++++++-----------------------
 1 file changed, 45 insertions(+), 41 deletions(-)

diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py
index d207b2b6..eed7995d 100644
--- a/patchwork/api/filters.py
+++ b/patchwork/api/filters.py
@@ -35,12 +35,7 @@ from patchwork.models import Series
 from patchwork.models import State
 
 
-class TimestampMixin(FilterSet):
-
-    # TODO(stephenfin): These should filter on a 'updated_at' field instead
-    before = IsoDateTimeFilter(name='date', lookup_expr='lt')
-    since = IsoDateTimeFilter(name='date', lookup_expr='gte')
-
+# custom fields, filters
 
 class ModelMultiChoiceField(ModelChoiceField):
 
@@ -75,12 +70,6 @@ class ProjectFilter(ModelChoiceFilter):
     field_class = ProjectChoiceField
 
 
-class ProjectMixin(FilterSet):
-
-    project = ProjectFilter(to_field_name='linkname',
-                            queryset=Project.objects.all())
-
-
 class PersonChoiceField(ModelMultiChoiceField):
 
     def _get_filters(self, value):
@@ -95,24 +84,6 @@ class PersonFilter(ModelChoiceFilter):
     field_class = PersonChoiceField
 
 
-class SeriesFilter(ProjectMixin, TimestampMixin, FilterSet):
-
-    submitter = PersonFilter(queryset=Person.objects.all())
-
-    class Meta:
-        model = Series
-        fields = ('submitter', 'project')
-
-
-class CoverLetterFilter(ProjectMixin, TimestampMixin, FilterSet):
-
-    submitter = PersonFilter(queryset=Person.objects.all())
-
-    class Meta:
-        model = CoverLetter
-        fields = ('project', 'series', 'submitter')
-
-
 class StateChoiceField(ModelChoiceField):
 
     def prepare_value(self, value):
@@ -138,17 +109,6 @@ class StateFilter(ModelChoiceFilter):
     field_class = StateChoiceField
 
 
-class PatchFilter(ProjectMixin, TimestampMixin, FilterSet):
-
-    state = StateFilter(queryset=State.objects.all())
-    submitter = PersonFilter(queryset=Person.objects.all())
-
-    class Meta:
-        model = Patch
-        fields = ('project', 'series', 'submitter', 'delegate',
-                  'state', 'archived')
-
-
 class UserChoiceField(ModelMultiChoiceField):
 
     def _get_filters(self, value):
@@ -163,6 +123,50 @@ class UserFilter(ModelChoiceFilter):
     field_class = UserChoiceField
 
 
+# filter sets
+
+class TimestampMixin(FilterSet):
+
+    # TODO(stephenfin): These should filter on a 'updated_at' field instead
+    before = IsoDateTimeFilter(name='date', lookup_expr='lt')
+    since = IsoDateTimeFilter(name='date', lookup_expr='gte')
+
+
+class ProjectMixin(FilterSet):
+
+    project = ProjectFilter(to_field_name='linkname',
+                            queryset=Project.objects.all())
+
+
+class SeriesFilter(ProjectMixin, TimestampMixin, FilterSet):
+
+    submitter = PersonFilter(queryset=Person.objects.all())
+
+    class Meta:
+        model = Series
+        fields = ('submitter', 'project')
+
+
+class CoverLetterFilter(ProjectMixin, TimestampMixin, FilterSet):
+
+    submitter = PersonFilter(queryset=Person.objects.all())
+
+    class Meta:
+        model = CoverLetter
+        fields = ('project', 'series', 'submitter')
+
+
+class PatchFilter(ProjectMixin, TimestampMixin, FilterSet):
+
+    state = StateFilter(queryset=State.objects.all())
+    submitter = PersonFilter(queryset=Person.objects.all())
+
+    class Meta:
+        model = Patch
+        fields = ('project', 'series', 'submitter', 'delegate',
+                  'state', 'archived')
+
+
 class CheckFilter(TimestampMixin, FilterSet):
 
     user = UserFilter(queryset=User.objects.all())
-- 
2.14.3



More information about the Patchwork mailing list