Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
0f239fa2
Commit
0f239fa2
authored
3 years ago
by
Mario Raciti
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-736
: Add (partially) filtering and ordering metadata
parent
0f870d33
No related branches found
No related tags found
1 merge request
!438
Resolve TMSS-736
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/src/tmss/tmssapp/viewsets/metadata.py
+49
-1
49 additions, 1 deletion
SAS/TMSS/backend/src/tmss/tmssapp/viewsets/metadata.py
with
49 additions
and
1 deletion
SAS/TMSS/backend/src/tmss/tmssapp/viewsets/metadata.py
+
49
−
1
View file @
0f239fa2
from
collections
import
OrderedDict
from
django.utils.encoding
import
force_str
from
rest_framework.metadata
import
SimpleMetadata
import
logging
...
...
@@ -10,6 +12,52 @@ class LOFARDefaultMetadata(SimpleMetadata):
"""
def
determine_metadata
(
self
,
request
,
view
):
metadata
=
super
(
LOFARDefaultMetadata
,
self
).
determine_metadata
(
request
,
view
)
# TODO: Add filtering and ordering information.
if
hasattr
(
view
,
'
filter_backends
'
):
# TODO: Add filter_backends.
pass
if
hasattr
(
view
,
'
filter_class
'
):
# Add filters
filters
=
OrderedDict
()
for
filter_name
,
filter_type
in
view
.
filter_class
.
base_filters
.
items
():
filter_parts
=
filter_name
.
split
(
'
__
'
)
filter_name
=
filter_parts
[
0
]
attrs
=
OrderedDict
()
# Type
attrs
[
'
type
'
]
=
filter_type
.
__class__
.
__name__
# Lookup fields
if
len
(
filter_parts
)
>
1
:
# Has a lookup type (__gt, __lt, etc.)
lookup_type
=
filter_parts
[
1
]
if
filters
.
get
(
filter_name
)
is
not
None
:
# Filter name already in, just append the value
attrs
[
'
lookup_types
'
]
=
filters
[
filter_name
][
'
lookup_types
'
]
attrs
[
'
lookup_types
'
].
append
(
lookup_type
)
else
:
attrs
[
'
lookup_types
'
]
=
[
lookup_type
]
else
:
attrs
[
'
lookup_types
'
]
=
[
'
exact
'
]
# Do choices
choices
=
filter_type
.
extra
.
get
(
'
choices
'
,
False
)
if
choices
:
attrs
[
'
choices
'
]
=
[
{
'
value
'
:
choice_value
,
'
display_name
'
:
force_str
(
choice_name
,
strings_only
=
True
)
}
for
choice_value
,
choice_name
in
choices
]
filters
[
filter_name
]
=
attrs
# Add filters info
metadata
[
'
filters
'
]
=
filters
# Add ordering info
if
hasattr
(
view
,
'
ordering
'
):
metadata
[
'
ordering
'
]
=
view
.
ordering
return
metadata
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment