Skip to content

Commit

Permalink
Fix confusing inconsistencies with RepositoryVersion filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Apr 12, 2018
1 parent dda4d7d commit 56a553a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions pulpcore/pulpcore/app/viewsets/custom_filters.py
Expand Up @@ -11,6 +11,14 @@
from rest_framework import serializers


class NumberRangeFilter(filters.BaseRangeFilter, filters.NumberFilter):
"""
Enables the user to filter a field by comma separated numbers, allowing them to retrieve more
than one object in a single query.
"""
pass


class CharInFilter(filters.BaseInFilter, filters.CharFilter):
"""
Enables the user to filter a field by comma separated strings, allowing them to retrieve more
Expand Down
15 changes: 9 additions & 6 deletions pulpcore/pulpcore/app/viewsets/repository.py
Expand Up @@ -30,7 +30,7 @@
RepositoryVersionSerializer
)
from pulpcore.app.viewsets import NamedModelViewSet, AsyncUpdateMixin, AsyncRemoveMixin
from pulpcore.app.viewsets.custom_filters import CharInFilter
from pulpcore.app.viewsets.custom_filters import CharInFilter, NumberRangeFilter


class RepositoryFilter(filterset.FilterSet):
Expand Down Expand Up @@ -133,6 +133,10 @@ class RepositoryVersionContentFilter(Filter):
3. Calculate and return the versions that the content can be found on
"""

def __init__(self, *args, **kwargs):
kwargs.setdefault('help_text', _('Content Unit referenced by HREF'))
super().__init__(*args, **kwargs)

def filter(self, qs, value):
"""
Args:
Expand Down Expand Up @@ -187,16 +191,15 @@ def filter(self, qs, value):

class RepositoryVersionFilter(filterset.FilterSet):

version_min = filters.NumberFilter(name='number', lookup_expr='gte')
version_max = filters.NumberFilter(name='number', lookup_expr='lte')

number = filters.NumberFilter(name='number')
number__range = NumberRangeFilter(name='number', lookup_expr='range')

created = filters.IsoDateTimeFilter(name='created')
content = RepositoryVersionContentFilter(label="Content HREF is equivalent to")
content = RepositoryVersionContentFilter(name='content')

class Meta:
model = RepositoryVersion
fields = ['version_min', 'version_max', 'created', 'content']
fields = ['number', 'created', 'content']


class RepositoryVersionViewSet(NamedModelViewSet,
Expand Down

0 comments on commit 56a553a

Please sign in to comment.