Commit 8ef7f5a5 authored by Alex Pyrgiotis's avatar Alex Pyrgiotis Committed by Athina Bekakou

admin: Use abbreviations for all model filters

Normally, we would like to name our model filters more verbosely: e.g.
proj --> project, net --> network. However, django-filter fails to
understand that the filter we create has nothing to do with the actual
model field and crashes, if defined like so:

    project = django_filters.ChartFilter(..., action=my_action)

If we try to circumvent it like so:

    proj = django_filters.ChartFilter(..., name='project',
                                      action=my_action)

then no results are printed since the query value gets incorrectly
cleared by the FilterSet form.

There doesn't seem to be an easy or clear way to circumvent this issue
so, for now, use as filter names the abbreviations of their model names
in order to be consistent across views.
parent 727abc55
......@@ -64,7 +64,7 @@ class NetworkFilterSet(django_filters.FilterSet):
This filter collection is based on django-filter's FilterSet.
"""
network = django_filters.CharFilter(label='Network', action=filter_network)
net = django_filters.CharFilter(label='Network', action=filter_network)
user = django_filters.CharFilter(label='OF User', action=filter_user)
vm = django_filters.CharFilter(label='HAS VM', action=filter_vm)
ip = django_filters.CharFilter(label='HAS IP', action=filter_ip)
......@@ -74,5 +74,5 @@ class NetworkFilterSet(django_filters.FilterSet):
class Meta:
model = Network
fields = ('network', 'state', 'public', 'drained', 'user', 'vm', 'ip',
fields = ('net', 'state', 'public', 'drained', 'user', 'vm', 'ip',
'proj')
......@@ -116,11 +116,10 @@ class ProjectFilterSet(django_filters.FilterSet):
This filter collection is based on django-filter's FilterSet.
"""
project = django_filters.CharFilter(label='Project', action=filter_project)
proj = django_filters.CharFilter(label='Project', action=filter_project)
user = django_filters.CharFilter(label='OF User', action=filter_user)
vm = django_filters.CharFilter(label='HAS VM', action=filter_vm)
volume = django_filters.CharFilter(label='HAS Volume',
action=filter_volume)
vol = django_filters.CharFilter(label='HAS Volume', action=filter_volume)
net = django_filters.CharFilter(label='HAS Network', action=filter_network)
ip = django_filters.CharFilter(label='HAS IP', action=filter_ip)
project_status = django_filters.MultipleChoiceFilter(
......@@ -133,5 +132,5 @@ class ProjectFilterSet(django_filters.FilterSet):
class Meta:
model = Project
fields = ('project', 'project_status', 'application_status', 'is_base',
'user', 'vm', 'volume', 'net', 'ip',)
fields = ('proj', 'project_status', 'application_status', 'is_base',
'user', 'vm', 'vol', 'net', 'ip',)
......@@ -140,13 +140,10 @@ class UserFilterSet(django_filters.FilterSet):
user = django_filters.CharFilter(label='User', action=filter_user)
vm = django_filters.CharFilter(label='HAS VM', action=filter_vm)
volume = django_filters.CharFilter(label='HAS Volume',
action=filter_volume)
network = django_filters.CharFilter(label='HAS Network',
action=filter_network)
vol = django_filters.CharFilter(label='HAS Volume', action=filter_volume)
net = django_filters.CharFilter(label='HAS Network', action=filter_network)
ip = django_filters.CharFilter(label='HAS IP', action=filter_ip)
proj = django_filters.CharFilter(label='IN Project',
action=filter_project)
proj = django_filters.CharFilter(label='IN Project', action=filter_project)
status = django_filters.MultipleChoiceFilter(
label='Status', action=filter_status, choices=choice2query.keys())
groups = django_filters.MultipleChoiceFilter(
......@@ -161,5 +158,4 @@ class UserFilterSet(django_filters.FilterSet):
class Meta:
model = AstakosUser
fields = ('user', 'status', 'groups', 'has_auth_providers',
'has_not_auth_providers', 'vm', 'volume', 'network', 'ip',
'proj')
'has_not_auth_providers', 'vm', 'vol', 'net', 'ip', 'proj')
......@@ -83,6 +83,12 @@ def filter_disk_template(queryset, choices):
return queryset.filter(q)
def filter_index(queryset, query):
if not query.isdigit():
return queryset.none()
return queryset.filter(index=query)
class VolumeFilterSet(django_filters.FilterSet):
"""A collection of filters for volumes.
......@@ -90,20 +96,20 @@ class VolumeFilterSet(django_filters.FilterSet):
This filter collection is based on django-filter's FilterSet.
"""
volume = django_filters.CharFilter(label='Volume', action=filter_volume)
vol = django_filters.CharFilter(label='Volume', action=filter_volume)
user = django_filters.CharFilter(label='OF User', action=filter_user)
vm = django_filters.CharFilter(label='OF VM', action=filter_vm)
project = django_filters.CharFilter(label='OF Project',
action=filter_project)
proj = django_filters.CharFilter(label='OF Project', action=filter_project)
status = django_filters.MultipleChoiceFilter(
label='Status', name='status', choices=Volume.STATUS_VALUES)
disk_template = django_filters.MultipleChoiceFilter(
label="Disk template", choices=get_disk_template_choices(),
action=filter_disk_template)
index = django_filters.CharFilter(label="Index", action=filter_index)
source = django_filters.CharFilter(label="Soure image", name="source",
lookup_type='icontains')
class Meta:
model = Volume
fields = ('volume', 'status', 'disk_template', 'index', 'source',
'user', 'vm', 'project')
fields = ('vol', 'status', 'disk_template', 'index', 'source',
'user', 'vm', 'proj')
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