Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
AURA
steering
Commits
aa7e7f41
Verified
Commit
aa7e7f41
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
refactor: use camelCase for query parameters
To be honest I'm not sure this is the right way to do it.
parent
702fa463
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#3432
passed
1 year ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/filters.py
+60
-46
60 additions, 46 deletions
program/filters.py
program/views.py
+58
-1
58 additions, 1 deletion
program/views.py
with
118 additions
and
47 deletions
program/filters.py
+
60
−
46
View file @
aa7e7f41
...
...
@@ -39,7 +39,17 @@ class IntegerInFilter(filters.BaseInFilter):
class
ShowFilterSet
(
StaticFilterHelpTextMixin
,
filters
.
FilterSet
):
active
=
filters
.
BooleanFilter
(
categoryIds
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given category or categories.
"
,
)
categorySlug
=
filters
.
CharFilter
(
field_name
=
"
category
"
,
help_text
=
"
Return only shows of the given category slug.
"
)
hostIds
=
IntegerInFilter
(
field_name
=
"
hosts
"
,
help_text
=
"
Return only shows assigned to the given host(s).
"
,
)
isActive
=
filters
.
BooleanFilter
(
field_name
=
"
is_active
"
,
method
=
"
filter_active
"
,
help_text
=
(
...
...
@@ -47,46 +57,36 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
"
or past or upcoming shows if false.
"
),
)
host
=
IntegerInFilter
(
field_name
=
"
hosts
"
,
help_text
=
"
Return only shows assigned to the given host(s).
"
,
isPublic
=
filters
.
BooleanFilter
(
field_name
=
"
is_public
"
,
help_text
=
"
Return only shows that are public/non-public.
"
,
)
languageIds
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given language(s).
"
,
)
music
_f
ocus
=
IntegerInFilter
(
music
F
ocus
Ids
=
IntegerInFilter
(
field_name
=
"
music_focus
"
,
help_text
=
"
Return only shows with given music focus(es).
"
,
)
music
_f
ocus
__s
lug
=
filters
.
CharFilter
(
music
F
ocus
S
lug
=
filters
.
CharFilter
(
field_name
=
"
music_focus
"
,
help_text
=
"
Return only shows with the give music focus slug.
"
)
owner
=
IntegerInFilter
(
owner
Ids
=
IntegerInFilter
(
field_name
=
"
owners
"
,
help_text
=
"
Return only shows that belong to the given owner(s).
"
,
)
category
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given category or categories.
"
,
)
category__slug
=
filters
.
CharFilter
(
field_name
=
"
category
"
,
help_text
=
"
Return only shows of the given category slug.
"
)
language
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given language(s).
"
,
)
topic
=
IntegerInFilter
(
topicIds
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given topic(s).
"
,
)
topic
__s
lug
=
filters
.
CharFilter
(
topic
S
lug
=
filters
.
CharFilter
(
field_name
=
"
topic
"
,
help_text
=
"
Return only shows of the given topic slug.
"
)
type
=
IntegerInFilter
(
type
Id
=
IntegerInFilter
(
help_text
=
"
Return only shows of a given type.
"
,
)
type
__s
lug
=
filters
.
CharFilter
(
type
S
lug
=
filters
.
CharFilter
(
field_name
=
"
type
"
,
help_text
=
"
Return only shows of the given type slug.
"
)
public
=
filters
.
BooleanFilter
(
field_name
=
"
is_public
"
,
help_text
=
"
Return only shows that are public/non-public.
"
,
)
def
filter_active
(
self
,
queryset
:
QuerySet
,
name
:
str
,
value
:
bool
):
# Filter currently running shows
...
...
@@ -128,15 +128,19 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
class
Meta
:
model
=
models
.
Show
fields
=
[
"
active
"
,
"
category
"
,
"
host
"
,
"
language
"
,
"
music_focus
"
,
"
owner
"
,
"
public
"
,
"
topic
"
,
"
type
"
,
"
categoryIds
"
,
"
categorySlug
"
,
"
hostIds
"
,
"
isActive
"
,
"
isPublic
"
,
"
languageIds
"
,
"
musicFocusIds
"
,
"
musicFocusSlug
"
,
"
ownerIds
"
,
"
topicIds
"
,
"
topicSlug
"
,
"
typeId
"
,
"
typeSlug
"
,
]
...
...
@@ -231,35 +235,45 @@ class TimeSlotFilterSet(filters.FilterSet):
class
NoteFilterSet
(
StaticFilterHelpTextMixin
,
filters
.
FilterSet
):
show
=
IntegerInFilter
(
field_name
=
"
timeslot__show
"
,
help_text
=
"
Return only notes that belong to the specified show(s).
"
,
)
timeslot
=
IntegerInFilter
(
field_name
=
"
timeslot
"
,
help_text
=
"
Return only notes that belong to the specified timeslot(s).
"
,
)
ids
=
IntegerInFilter
(
field_name
=
"
id
"
,
help_text
=
"
Return only notes matching the specified id(s).
"
,
)
show_owner
=
IntegerInFilter
(
ownerIds
=
IntegerInFilter
(
field_name
=
"
owner
"
,
help_text
=
"
Return only notes that belong to the specified owner(s).
"
,
)
showIds
=
IntegerInFilter
(
field_name
=
"
timeslot__show
"
,
help_text
=
"
Return only notes that belong to the specified show(s).
"
,
)
showOwnerIds
=
IntegerInFilter
(
field_name
=
"
timeslot__show__owners
"
,
help_text
=
"
Return only notes by show the specified owner(s): all notes the user may edit.
"
,
)
timeslotIds
=
IntegerInFilter
(
field_name
=
"
timeslot
"
,
help_text
=
"
Return only notes that belong to the specified timeslot(s).
"
,
)
class
Meta
:
model
=
models
.
Note
help_texts
=
{
"
owner
"
:
"
Return only notes created by the specified user.
"
,
"
owner
Id
"
:
"
Return only notes created by the specified user.
"
,
}
fields
=
[
"
ids
"
,
"
owner
"
,
"
show
"
,
"
timeslot
"
,
"
show_owner
"
]
fields
=
[
"
ids
"
,
"
ownerIds
"
,
"
showIds
"
,
"
showOwnerIds
"
,
"
timeslotIds
"
,
]
class
ActiveFilterSet
(
StaticFilterHelpTextMixin
,
filters
.
FilterSet
):
a
ctive
=
filters
.
BooleanFilter
(
field_name
=
"
is_active
"
)
isA
ctive
=
filters
.
BooleanFilter
(
field_name
=
"
is_active
"
)
class
Meta
:
fields
=
[
"
a
ctive
"
,
"
isA
ctive
"
,
]
This diff is collapsed.
Click to expand it.
program/views.py
+
58
−
1
View file @
aa7e7f41
...
...
@@ -381,8 +381,25 @@ class APIShowViewSet(DisabledObjectPermissionCheckMixin, viewsets.ModelViewSet):
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
filter_kwargs
=
{}
for
key
,
value
in
request
.
query_params
.
items
():
filter_kwargs
[
key
]
=
value
# map query parameters to filter names
if
key
==
"
host_ids
"
or
key
==
"
owner_ids
"
:
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
s__id__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
s__id
"
]
=
value
elif
key
.
endswith
(
"
_ids
"
):
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
__id__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
__id
"
]
=
value
elif
key
.
endswith
(
"
_id
"
):
filter_kwargs
[
f
"
{
key
[
:
-
3
]
}
__id
"
]
=
value
elif
key
.
endswith
(
"
_slug
"
):
filter_kwargs
[
f
"
{
key
[
:
-
5
]
}
__slug
"
]
=
value
else
:
filter_kwargs
[
key
]
=
value
try
:
queryset
=
get_list_or_404
(
self
.
get_queryset
(),
**
filter_kwargs
)
...
...
@@ -792,6 +809,46 @@ class APINoteViewSet(
pagination_class
=
LimitOffsetPagination
filterset_class
=
filters
.
NoteFilterSet
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
filter_kwargs
=
{}
# map query parameters to filter names
for
key
,
value
in
request
.
query_params
.
items
():
if
key
==
"
ids
"
:
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
"
id__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
"
id
"
]
=
value
elif
key
==
"
show_ids
"
:
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
"
timeslot__show__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
"
timeslot__show
"
]
=
value
elif
key
==
"
show_owner_ids
"
:
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
"
timeslot__show__owners__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
"
timeslot__show__owners
"
]
=
value
elif
key
.
endswith
(
"
_ids
"
):
if
value
.
count
(
"
,
"
)
>
0
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
__in
"
]
=
value
.
split
(
"
,
"
)
else
:
filter_kwargs
[
f
"
{
key
[
:
-
4
]
}
"
]
=
value
else
:
filter_kwargs
[
key
]
=
value
try
:
queryset
=
get_list_or_404
(
self
.
get_queryset
(),
**
filter_kwargs
)
except
FieldError
:
queryset
=
None
if
page
:
=
self
.
paginate_queryset
(
queryset
)
is
not
None
:
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
return
self
.
get_paginated_response
(
serializer
.
data
)
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
get_serializer_context
(
self
):
# the serializer needs the request in the context
context
=
super
().
get_serializer_context
()
...
...
This diff is collapsed.
Click to expand it.
Konrad Mohrfeldt
@kmohrf
mentioned in commit
d72df7c1
·
1 year ago
mentioned in commit
d72df7c1
mentioned in commit d72df7c120680cc669a4e7ce76474ccdca3ab1c1
Toggle commit list
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