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
fd4d2206
Verified
Commit
fd4d2206
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into develop
parents
f3384681
c3474fc6
No related branches found
No related tags found
No related merge requests found
Pipeline
#7366
passed
1 year ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/filters.py
+31
-45
31 additions, 45 deletions
program/filters.py
program/serializers.py
+5
-0
5 additions, 0 deletions
program/serializers.py
with
36 additions
and
45 deletions
program/filters.py
+
31
−
45
View file @
fd4d2206
...
...
@@ -170,6 +170,19 @@ class ScheduleFilterSet(filters.FilterSet):
field_name
=
"
show
"
,
help_text
=
"
Return only schedules that belong to the specified show(s).
"
,
)
exclude_inactive
=
filters
.
BooleanFilter
(
method
=
"
filter_exclude_inactive
"
,
help_text
=
"
Excludes all schedules that don’t have timeslots in the future.
"
,
)
def
filter_exclude_inactive
(
self
,
queryset
:
QuerySet
,
name
:
str
,
value
:
bool
):
if
not
value
:
return
queryset
return
queryset
.
filter
(
Exists
(
models
.
TimeSlot
.
objects
.
filter
(
schedule
=
OuterRef
(
"
pk
"
),
end__gte
=
timezone
.
now
())
)
)
class
TimeSlotFilterSet
(
filters
.
FilterSet
):
...
...
@@ -184,29 +197,30 @@ class TimeSlotFilterSet(filters.FilterSet):
"
If specified without a datetime value the current date and time is assumed.
"
),
)
# The start/end filters will always be applied even if no query parameter has been set.
# This is because we enforce a value in the clean_start and clean_end methods
# of the filterset form.
start
=
filters
.
DateFilter
(
method
=
"
filter_start
"
,
help_text
=
(
"
Only returns timeslots after that start on or after the specified date.
"
"
By default, this is set to the current date.
"
),
starts_before
=
filters
.
DateTimeFilter
(
field_name
=
"
start
"
,
lookup_expr
=
"
lt
"
,
help_text
=
"
Only returns timeslots that start before the specified datetime.
"
,
)
end
=
filters
.
DateFilter
(
method
=
"
filter_end
"
,
help_text
=
(
"
Only returns timeslots that end on or before the specified date.
"
"
By default, this is set to value of the start filter + 60 days.
"
),
starts_after
=
filters
.
DateTimeFilter
(
field_name
=
"
start
"
,
lookup_expr
=
"
gte
"
,
help_text
=
"
Only returns timeslots that start at or after the specified datetime.
"
,
)
ends_before
=
filters
.
DateTimeFilter
(
field_name
=
"
end
"
,
lookup_expr
=
"
lt
"
,
help_text
=
"
Only returns timeslots that end before the specified datetime.
"
,
)
ends_after
=
filters
.
DateTimeFilter
(
field_name
=
"
end
"
,
lookup_expr
=
"
gte
"
,
help_text
=
"
Only returns timeslots that end at or after the specified datetime.
"
,
)
schedule_ids
=
IntegerInFilter
(
field_name
=
"
schedule
"
,
help_text
=
"
Return only timeslots that belong to the specified schedule(s).
"
,
)
show_ids
=
IntegerInFilter
(
field_name
=
"
schedule__show
"
,
help_text
=
"
Return only timeslots that belong to the specified show(s).
"
,
...
...
@@ -226,14 +240,6 @@ class TimeSlotFilterSet(filters.FilterSet):
relevant_timeslot_ids
=
list
(
nearest_timeslots_in_future
)
+
list
(
nearest_timeslots_in_past
)
return
queryset
.
filter
(
id__in
=
relevant_timeslot_ids
)
def
filter_start
(
self
,
queryset
:
QuerySet
,
name
:
str
,
value
:
datetime
.
date
):
start
=
timezone
.
make_aware
(
datetime
.
datetime
.
combine
(
value
,
datetime
.
time
.
min
))
return
queryset
.
filter
(
start__gte
=
start
)
def
filter_end
(
self
,
queryset
:
QuerySet
,
name
:
str
,
value
:
datetime
.
date
):
end
=
timezone
.
make_aware
(
datetime
.
datetime
.
combine
(
value
,
datetime
.
time
.
max
))
return
queryset
.
filter
(
end__lte
=
end
)
def
filter_queryset
(
self
,
queryset
):
queryset
=
super
().
filter_queryset
(
queryset
)
# This is for backwards compatibility as the surrounding-filter was formerly implemented
...
...
@@ -242,26 +248,6 @@ class TimeSlotFilterSet(filters.FilterSet):
queryset
=
self
.
filter_surrounding
(
queryset
,
"
surrounding
"
,
timezone
.
now
())
return
queryset
def
get_form_class
(
self
):
form_cls
=
super
().
get_form_class
()
class
TimeSlotFilterSetFormWithDefaults
(
form_cls
):
def
clean_start
(
self
):
start
=
self
.
cleaned_data
.
get
(
"
start
"
,
None
)
return
start
or
timezone
.
now
().
date
()
def
clean_end
(
self
):
end
=
self
.
cleaned_data
.
get
(
"
end
"
,
None
)
return
end
or
self
.
cleaned_data
[
"
start
"
]
+
datetime
.
timedelta
(
days
=
60
)
# We only want defaults to apply in the context of the list action.
# When accessing individual timeslots we don’t want the queryset to be restricted
# to the default range of 60 days as get_object would yield a 404 otherwise.
if
self
.
request
.
parser_context
[
"
view
"
].
action
==
"
list
"
:
return
TimeSlotFilterSetFormWithDefaults
else
:
return
form_cls
class
Meta
:
model
=
models
.
TimeSlot
fields
=
[
...
...
This diff is collapsed.
Click to expand it.
program/serializers.py
+
5
−
0
View file @
fd4d2206
...
...
@@ -681,7 +681,12 @@ class RRuleSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
RRule
fields
=
(
"
by_set_pos
"
,
"
by_weekdays
"
,
"
count
"
,
"
freq
"
,
"
id
"
,
"
interval
"
,
"
name
"
,
)
read_only_fields
=
fields
...
...
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