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
e1ff439a
Commit
e1ff439a
authored
3 years ago
by
Richard Blechinger
Browse files
Options
Downloads
Patches
Plain Diff
Add customizable ordering for timeslot queryset
parent
50a4b9b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+7
-4
7 additions, 4 deletions
program/views.py
with
7 additions
and
4 deletions
program/views.py
+
7
−
4
View file @
e1ff439a
...
@@ -522,17 +522,20 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -522,17 +522,20 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
def
get_queryset
(
self
):
def
get_queryset
(
self
):
show_pk
=
int_or_none
(
'
show_pk
'
,
self
.
kwargs
)
show_pk
=
int_or_none
(
'
show_pk
'
,
self
.
kwargs
)
schedule_pk
=
int_or_none
(
'
schedule_pk
'
,
self
.
kwargs
)
schedule_pk
=
int_or_none
(
'
schedule_pk
'
,
self
.
kwargs
)
# Filters
# Filters
# Return next 60 days by default
# Return next 60 days by default
start
=
datetime
.
combine
(
date
.
today
(),
time
(
0
,
0
))
start
=
datetime
.
combine
(
date
.
today
(),
time
(
0
,
0
))
end
=
start
+
timedelta
(
days
=
60
)
end
=
start
+
timedelta
(
days
=
60
)
if
(
'
start
'
in
self
.
request
.
query_params
)
and
(
'
end
'
in
self
.
request
.
query_params
):
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
))
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
))
end
=
datetime
.
combine
(
datetime
.
strptime
(
self
.
request
.
query_params
.
get
(
'
end
'
),
'
%Y-%m-%d
'
).
date
(),
time
(
23
,
59
))
# Is this safe?
order
=
self
.
request
.
query_params
.
get
(
'
order
'
,
'
-start
'
)
# Endpoints
# Endpoints
#
#
...
@@ -541,7 +544,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -541,7 +544,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
# Returns timeslots of the given show and schedule
# Returns timeslots of the given show and schedule
#
#
if
show_pk
and
schedule_pk
:
if
show_pk
and
schedule_pk
:
return
TimeSlot
.
objects
.
filter
(
show
=
show_pk
,
schedule
=
schedule_pk
,
start__gte
=
start
,
end__lte
=
end
).
order_by
(
'
start
'
)
return
TimeSlot
.
objects
.
filter
(
show
=
show_pk
,
schedule
=
schedule_pk
,
start__gte
=
start
,
end__lte
=
end
).
order_by
(
order
)
#
#
# /shows/1/timeslots/
# /shows/1/timeslots/
...
@@ -549,7 +552,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -549,7 +552,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
# Returns timeslots of the show
# Returns timeslots of the show
#
#
elif
show_pk
and
schedule_pk
is
None
:
elif
show_pk
and
schedule_pk
is
None
:
return
TimeSlot
.
objects
.
filter
(
show
=
show_pk
,
start__gte
=
start
,
end__lte
=
end
).
order_by
(
'
start
'
)
return
TimeSlot
.
objects
.
filter
(
show
=
show_pk
,
start__gte
=
start
,
end__lte
=
end
).
order_by
(
order
)
#
#
# /timeslots/
# /timeslots/
...
@@ -557,7 +560,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
...
@@ -557,7 +560,7 @@ class APITimeSlotViewSet(viewsets.ModelViewSet):
# Returns all timeslots
# Returns all timeslots
#
#
else
:
else
:
return
TimeSlot
.
objects
.
filter
(
start__gte
=
start
,
end__lte
=
end
).
order_by
(
'
start
'
)
return
TimeSlot
.
objects
.
filter
(
start__gte
=
start
,
end__lte
=
end
).
order_by
(
order
)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
pk
=
int_or_none
(
'
pk
'
,
self
.
kwargs
)
pk
=
int_or_none
(
'
pk
'
,
self
.
kwargs
)
...
...
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