Commit a3674879 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

plug django_filters on DRF

parent 277462c0
Pipeline #1091 passed with stages
in 1 minute and 1 second
...@@ -148,6 +148,12 @@ LOGGING = { ...@@ -148,6 +148,12 @@ LOGGING = {
}, },
} }
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
}
DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html' DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html'
RAINBOARD_DATA = Path('/srv/dashboard') RAINBOARD_DATA = Path('/srv/dashboard')
RAINBOARD_GITS = RAINBOARD_DATA / 'repositories' RAINBOARD_GITS = RAINBOARD_DATA / 'repositories'
......
...@@ -3,7 +3,7 @@ import django_filters ...@@ -3,7 +3,7 @@ import django_filters
from . import models from . import models
class ProjectFilter(django_filters.FilterSet): class ProjectFilter(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains') name = django_filters.CharFilter(lookup_expr='icontains')
class Meta: class Meta:
...@@ -11,7 +11,7 @@ class ProjectFilter(django_filters.FilterSet): ...@@ -11,7 +11,7 @@ class ProjectFilter(django_filters.FilterSet):
fields = ('name',) fields = ('name',)
class ContributorFilter(django_filters.FilterSet): class ContributorFilter(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(field_name='contributorname__name', label='name', lookup_expr='icontains') name = django_filters.CharFilter(field_name='contributorname__name', label='name', lookup_expr='icontains')
mail = django_filters.CharFilter(field_name='contributormail__mail', label='mail', lookup_expr='icontains') mail = django_filters.CharFilter(field_name='contributormail__mail', label='mail', lookup_expr='icontains')
project = django_filters.CharFilter(field_name='projects__name', label='project', lookup_expr='icontains') project = django_filters.CharFilter(field_name='projects__name', label='project', lookup_expr='icontains')
......
...@@ -131,26 +131,31 @@ class AuthenticatedOrReadOnlyModelViewSet(viewsets.ModelViewSet): ...@@ -131,26 +131,31 @@ class AuthenticatedOrReadOnlyModelViewSet(viewsets.ModelViewSet):
class NamespaceViewSet(AuthenticatedOrReadOnlyModelViewSet): class NamespaceViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Namespace.objects.all() queryset = models.Namespace.objects.all()
serializer_class = serializers.NamespaceSerializer serializer_class = serializers.NamespaceSerializer
filterset_fields = ('name', 'slug')
class LicenseViewSet(AuthenticatedOrReadOnlyModelViewSet): class LicenseViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.License.objects.all() queryset = models.License.objects.all()
serializer_class = serializers.LicenseSerializer serializer_class = serializers.LicenseSerializer
filterset_fields = ('name', 'spdx_id')
class ForgeViewSet(AuthenticatedOrReadOnlyModelViewSet): class ForgeViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Forge.objects.all() queryset = models.Forge.objects.all()
serializer_class = serializers.ForgeSerializer serializer_class = serializers.ForgeSerializer
filterset_fields = ('name', 'slug')
class ProjectViewSet(AuthenticatedOrReadOnlyModelViewSet): class ProjectViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Project.objects.all() queryset = models.Project.objects.all()
serializer_class = serializers.ProjectSerializer serializer_class = serializers.ProjectSerializer
filterset_class = filters.ProjectFilter
class RepoViewSet(AuthenticatedOrReadOnlyModelViewSet): class RepoViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Repo.objects.all() queryset = models.Repo.objects.all()
serializer_class = serializers.RepoSerializer serializer_class = serializers.RepoSerializer
filterset_fields = ('name', 'slug')
class BranchViewSet(AuthenticatedOrReadOnlyModelViewSet): class BranchViewSet(AuthenticatedOrReadOnlyModelViewSet):
...@@ -159,13 +164,15 @@ class BranchViewSet(AuthenticatedOrReadOnlyModelViewSet): ...@@ -159,13 +164,15 @@ class BranchViewSet(AuthenticatedOrReadOnlyModelViewSet):
class TargetViewSet(AuthenticatedOrReadOnlyModelViewSet): class TargetViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Target.objects.all() queryset = models.Target.objects.active()
serializer_class = serializers.TargetSerializer serializer_class = serializers.TargetSerializer
filterset_fields = ('name', 'slug')
class RobotpkgViewSet(AuthenticatedOrReadOnlyModelViewSet): class RobotpkgViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Robotpkg.objects.all() queryset = models.Robotpkg.objects.all()
serializer_class = serializers.RobotpkgSerializer serializer_class = serializers.RobotpkgSerializer
filterset_fields = ('name', 'slug')
class ImageViewSet(AuthenticatedOrReadOnlyModelViewSet): class ImageViewSet(AuthenticatedOrReadOnlyModelViewSet):
...@@ -176,6 +183,7 @@ class ImageViewSet(AuthenticatedOrReadOnlyModelViewSet): ...@@ -176,6 +183,7 @@ class ImageViewSet(AuthenticatedOrReadOnlyModelViewSet):
class ContributorViewSet(AuthenticatedOrReadOnlyModelViewSet): class ContributorViewSet(AuthenticatedOrReadOnlyModelViewSet):
queryset = models.Contributor.objects.all() queryset = models.Contributor.objects.all()
serializer_class = serializers.ContributorSerializer serializer_class = serializers.ContributorSerializer
filterset_class = filters.ContributorFilter
class ContributorNameViewSet(AuthenticatedOrReadOnlyModelViewSet): class ContributorNameViewSet(AuthenticatedOrReadOnlyModelViewSet):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment