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
c1d1225e
Commit
c1d1225e
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/api-docs' of
ssh://gitlab.servus.at:22022/aura/steering
into feature/api-docs
parents
c217852f
a5239bfb
No related branches found
No related tags found
1 merge request
!21
Add API documentation
Pipeline
#1771
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/filters.py
+15
-28
15 additions, 28 deletions
program/filters.py
with
15 additions
and
28 deletions
program/filters.py
+
15
−
28
View file @
c1d1225e
...
...
@@ -3,7 +3,7 @@ import datetime
from
django_filters
import
rest_framework
as
filters
from
django_filters
import
widgets
from
django
.contrib.auth.models
import
User
from
django
import
forms
from
django.db.models
import
Q
,
QuerySet
from
django.utils
import
timezone
from
program
import
models
...
...
@@ -19,7 +19,7 @@ class StaticFilterHelpTextMixin:
return
_filter
class
ModelMultipleChoiceFilter
(
filters
.
ModelMultipleChoice
Filter
):
class
IntegerInFilter
(
filters
.
BaseIn
Filter
):
class
QueryArrayWidget
(
widgets
.
QueryArrayWidget
):
# see: https://github.com/carltongibson/django-filter/issues/1047
def
value_from_datadict
(
self
,
data
,
files
,
name
):
...
...
@@ -31,17 +31,12 @@ class ModelMultipleChoiceFilter(filters.ModelMultipleChoiceFilter):
new_data
[
key
]
=
data
.
getlist
(
key
)
return
super
().
value_from_datadict
(
new_data
,
files
,
name
)
field_class
=
forms
.
IntegerField
def
__init__
(
self
,
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
"
widget
"
,
self
.
QueryArrayWidget
())
kwargs
[
"
lookup_expr
"
]
=
"
in
"
super
().
__init__
(
*
args
,
**
kwargs
)
def
get_filter_predicate
(
self
,
v
):
# There is something wrong with using ModelMultipleChoiceFilter
# along the CSVWidget that causes lookups to fail.
# May be related to: https://github.com/carltongibson/django-filter/issues/1103
return
super
().
get_filter_predicate
([
v
.
pk
])
class
ShowFilterSet
(
StaticFilterHelpTextMixin
,
filters
.
FilterSet
):
active
=
filters
.
BooleanFilter
(
...
...
@@ -52,34 +47,31 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
"
or past or upcoming shows if false.
"
),
)
host
=
ModelMultipleChoiceFilter
(
queryset
=
models
.
Host
.
objects
.
all
(),
host
=
IntegerInFilter
(
field_name
=
"
hosts
"
,
help_text
=
"
Return only shows assigned to the given host(s).
"
,
)
# TODO: replace `musicfocus` with `music_focus` when dashboard is updated
musicfocus
=
ModelMultipleChoiceFilter
(
queryset
=
models
.
MusicFocus
.
objects
.
all
(),
musicfocus
=
IntegerInFilter
(
field_name
=
"
music_focus
"
,
help_text
=
"
Return only shows with given music focus(es).
"
,
)
owner
=
ModelMultipleChoiceFilter
(
queryset
=
User
.
objects
.
all
(),
owner
=
IntegerInFilter
(
field_name
=
"
owners
"
,
help_text
=
"
Return only shows that belong to the given owner(s).
"
,
)
category
=
ModelMultipleChoiceFilter
(
queryset
=
models
.
Category
.
objects
.
all
(),
category
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given category or categories.
"
,
)
language
=
ModelMultipleChoiceFilter
(
queryset
=
models
.
Language
.
objects
.
all
(),
language
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given language(s).
"
,
)
topic
=
ModelMultipleChoiceFilter
(
queryset
=
models
.
Topic
.
objects
.
all
(),
topic
=
IntegerInFilter
(
help_text
=
"
Return only shows of the given topic(s).
"
,
)
type
=
IntegerInFilter
(
help_text
=
"
Return only shows of a given type.
"
,
)
public
=
filters
.
BooleanFilter
(
field_name
=
"
is_public
"
,
help_text
=
"
Return only shows that are public/non-public.
"
,
...
...
@@ -113,9 +105,6 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
class
Meta
:
model
=
models
.
Show
help_texts
=
{
"
type
"
:
"
Return only shows of a given type.
"
,
}
fields
=
[
"
active
"
,
"
category
"
,
...
...
@@ -224,14 +213,12 @@ class TimeSlotFilterSet(filters.FilterSet):
class
NoteFilterSet
(
StaticFilterHelpTextMixin
,
filters
.
FilterSet
):
ids
=
ModelMultipleChoice
Filter
(
ids
=
IntegerIn
Filter
(
field_name
=
"
id
"
,
queryset
=
models
.
Note
.
objects
.
all
(),
help_text
=
"
Return only notes matching the specified id(s).
"
,
)
owner
=
ModelMultipleChoice
Filter
(
owner
=
IntegerIn
Filter
(
field_name
=
"
show__owners
"
,
queryset
=
models
.
User
.
objects
.
all
(),
help_text
=
"
Return only notes by show the specified owner(s): all notes the user may edit.
"
,
)
...
...
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