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
6da85ff5
Commit
6da85ff5
authored
3 years ago
by
Richard Blechinger
Browse files
Options
Downloads
Patches
Plain Diff
Add ?surrounding as query param
parent
e1ff439a
No related branches found
No related tags found
1 merge request
!15
Add customizable ordering and new request type for timeslot queryset
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/views.py
+12
-1
12 additions, 1 deletion
program/views.py
with
12 additions
and
1 deletion
program/views.py
+
12
−
1
View file @
6da85ff5
...
...
@@ -19,6 +19,7 @@
#
import
json
import
logging
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
django.contrib.auth.models
import
User
...
...
@@ -37,6 +38,7 @@ from program.serializers import TypeSerializer, LanguageSerializer, MusicFocusSe
UserSerializer
from
program.utils
import
get_cached_shows
logger
=
logging
.
getLogger
(
__name__
)
def
json_day_schedule
(
request
,
year
=
None
,
month
=
None
,
day
=
None
):
if
year
is
None
and
month
is
None
and
day
is
None
:
...
...
@@ -528,7 +530,6 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
start
=
datetime
.
combine
(
date
.
today
(),
time
(
0
,
0
))
end
=
start
+
timedelta
(
days
=
60
)
if
(
'
start
'
in
self
.
request
.
query_params
)
and
(
'
end
'
in
self
.
request
.
query_params
):
start
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
query_params
.
get
(
'
start
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
0
,
0
))
end
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
query_params
.
get
(
'
end
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
23
,
59
))
...
...
@@ -536,6 +537,15 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
# Is this safe?
order
=
self
.
request
.
query_params
.
get
(
'
order
'
,
'
-start
'
)
if
(
'
surrounding
'
in
self
.
request
.
query_params
):
today
=
datetime
.
today
()
nearest_timeslots_in_future
=
TimeSlot
.
objects
.
filter
(
start__gte
=
today
).
order_by
(
'
start
'
).
values_list
(
'
id
'
,
flat
=
True
)[:
5
]
nearest_timeslots_in_past
=
TimeSlot
.
objects
.
filter
(
start__lt
=
today
).
order_by
(
'
-start
'
).
values_list
(
'
id
'
,
flat
=
True
)[:
5
]
relevant_timeslot_ids
=
list
(
nearest_timeslots_in_future
)
+
list
(
nearest_timeslots_in_past
)
return
TimeSlot
.
objects
.
filter
(
id__in
=
relevant_timeslot_ids
).
order_by
(
order
)
# Endpoints
#
...
...
@@ -566,6 +576,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
pk
=
int_or_none
(
'
pk
'
,
self
.
kwargs
)
show_pk
=
int_or_none
(
'
show_pk
'
,
self
.
kwargs
)
if
show_pk
:
timeslot
=
get_object_or_404
(
TimeSlot
,
pk
=
pk
,
show
=
show_pk
)
else
:
...
...
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