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
706567c7
Verified
Commit
706567c7
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
refactor: remove filter_active
parent
988b0d7d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/filters.py
+2
-34
2 additions, 34 deletions
program/filters.py
with
2 additions
and
34 deletions
program/filters.py
+
2
−
34
View file @
706567c7
...
...
@@ -5,7 +5,7 @@ from django_filters import rest_framework as filters
from
django_filters
import
widgets
from
django
import
forms
from
django.db.models
import
Exists
,
OuterRef
,
Q
,
QuerySet
from
django.db.models
import
Exists
,
OuterRef
,
QuerySet
from
django.utils
import
timezone
from
program
import
models
...
...
@@ -74,11 +74,7 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
)
is_active
=
filters
.
BooleanFilter
(
field_name
=
"
is_active
"
,
method
=
"
filter_active
"
,
help_text
=
(
"
Return only currently running shows (with timeslots in the future) if true
"
"
or past or upcoming shows if false.
"
),
help_text
=
"
Return only currently active/inactive shows.
"
,
)
is_writable
=
filters
.
BooleanFilter
(
method
=
"
filter_writable
"
,
...
...
@@ -121,34 +117,6 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
help_text
=
"
Return only shows of the given type slug.
"
,
)
def
filter_active
(
self
,
queryset
:
QuerySet
,
name
:
str
,
value
:
bool
):
# Filter currently running shows
# Get currently running schedules to filter by first
# For single dates we test if there'll be one in the future (and ignore the until date)
# TODO: Really consider first_date? (=currently active, not just upcoming ones)
# Add limit for future?
show_ids
=
(
models
.
Schedule
.
objects
.
filter
(
# not "once" schedules with first_date in the past and last_date in the future
Q
(
rrule__freq__gt
=
0
,
first_date__lte
=
timezone
.
now
(),
last_date__gte
=
timezone
.
now
(),
)
# "once" schedules with first_date in the future
|
Q
(
rrule__freq
=
0
,
first_date__gte
=
timezone
.
now
())
)
.
distinct
()
.
values_list
(
"
show_id
"
,
flat
=
True
)
)
if
value
:
# Filter active shows based on timeslots as well as on the is_active flag
# Even if there are future timeslots but is_active=True the show will be considered as
# inactive
return
queryset
.
filter
(
id__in
=
show_ids
,
is_active
=
True
)
else
:
return
queryset
.
exclude
(
id__in
=
show_ids
,
is_active
=
True
)
def
filter_writable
(
self
,
queryset
:
QuerySet
,
_
:
str
,
value
:
bool
)
->
QuerySet
:
user
=
self
.
request
.
user
if
self
.
request
.
user
.
is_authenticated
else
None
...
...
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