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
11482eca
Commit
11482eca
authored
11 months ago
by
Chris Pastl
Browse files
Options
Downloads
Patches
Plain Diff
Refactor: replace json_playout func with APIPlayoutViewSet class
parent
2dfb2d71
No related branches found
No related tags found
1 merge request
!40
Refactor playout endpoint
Pipeline
#7875
passed
11 months ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/views.py
+51
-45
51 additions, 45 deletions
program/views.py
steering/urls.py
+3
-3
3 additions, 3 deletions
steering/urls.py
with
54 additions
and
48 deletions
program/views.py
+
51
−
45
View file @
11482eca
...
@@ -171,68 +171,74 @@ def json_day_schedule(request, year=None, month=None, day=None):
...
@@ -171,68 +171,74 @@ def json_day_schedule(request, year=None, month=None, day=None):
)
)
def
json_playout
(
request
):
class
APIPlayoutViewSet
(
"""
mixins
.
ListModelMixin
,
Return a JSON representation of the scheduled playout.
viewsets
.
GenericViewSet
,
):
queryset
=
TimeSlot
.
objects
.
all
()
Expects GET parameters `start` (date), `end` (date), and `includeVirtual` (boolean).
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Return a JSON representation of the scheduled playout.
- `start` is today by default.
Expects GET parameters `start` (date), `end` (date), and `includeVirtual` (boolean).
- `end` is one week after the start date by default.
- `includeVirtual` is false by default.
The schedule will include virtual timeslots to fill unscheduled gaps if requested.
- `start` is today by default.
- `end` is one week after the start date by default.
- `includeVirtual` is false by default.
Called by
The schedule will include virtual timeslots to fill unscheduled gaps if requested.
- engine (playout) to retrieve timeslots within a given timerange
- internal calendar to retrieve all timeslots for a week
"""
# datetime.now and datetime.combine return timezone naive datetime objects
Called by
if
request
.
GET
.
get
(
"
start
"
)
is
None
:
- engine (playout) to retrieve timeslots within a given timerange
schedule_start
=
timezone
.
make_aware
(
datetime
.
combine
(
datetime
.
now
(),
time
(
0
,
0
)))
- internal calendar to retrieve all timeslots for a week
else
:
"""
schedule_start
=
timezone
.
make_aware
(
datetime
.
combine
(
parse_date
(
request
.
GET
.
get
(
"
start
"
)),
time
(
0
,
0
))
)
if
request
.
GET
.
get
(
"
end
"
)
is
None
:
# datetime.now and datetime.combine return timezone naive datetime objects
schedule_end
=
schedule_start
+
timedelta
(
days
=
7
)
if
request
.
GET
.
get
(
"
start
"
)
is
None
:
else
:
schedule_start
=
timezone
.
make_aware
(
datetime
.
combine
(
datetime
.
now
(),
time
(
0
,
0
)))
schedule_end
=
timezone
.
make_aware
(
else
:
datetime
.
combine
(
parse_date
(
request
.
GET
.
get
(
"
end
"
))
+
timedelta
(
days
=
1
),
time
(
0
,
0
))
schedule_start
=
timezone
.
make_aware
(
)
datetime
.
combine
(
parse_date
(
request
.
GET
.
get
(
"
start
"
)),
time
(
0
,
0
))
)
include_virtual
=
request
.
GET
.
get
(
"
include_virtual
"
)
==
"
true
"
if
request
.
GET
.
get
(
"
end
"
)
is
None
:
schedule_end
=
schedule_start
+
timedelta
(
days
=
7
)
else
:
schedule_end
=
timezone
.
make_aware
(
datetime
.
combine
(
parse_date
(
request
.
GET
.
get
(
"
end
"
))
+
timedelta
(
days
=
1
),
time
(
0
,
0
))
)
timeslots
=
get_timerange_timeslots
(
schedule_start
,
schedule_end
).
select_related
(
"
schedul
e
"
)
include_virtual
=
request
.
GET
.
get
(
"
include_virtual
"
)
==
"
tru
e
"
schedule
=
[]
timeslots
=
get_timerange_timeslots
(
schedule_start
,
schedule_end
).
select_related
(
"
schedule
"
)
first_timeslot
=
timeslots
.
first
()
schedule
=
[]
if
include_virtual
and
first_timeslot
.
start
>
schedule_start
:
first_timeslot
=
timeslots
.
first
()
schedule
.
append
(
gap_entry
(
gap_start
=
schedule_start
,
gap_end
=
first_timeslot
.
start
))
for
current
,
upcoming
in
pairwise
(
timeslots
)
:
if
include_virtual
and
first_timeslot
.
start
>
schedule_start
:
schedule
.
append
(
timeslot_entry
(
timeslot
=
curren
t
))
schedule
.
append
(
gap_entry
(
gap_start
=
schedule_start
,
gap_end
=
first_
timeslot
.
star
t
))
if
include_virtual
and
current
.
end
!=
upcoming
.
start
:
for
current
,
upcoming
in
pairwise
(
timeslots
)
:
schedule
.
append
(
gap_entry
(
gap_start
=
current
.
end
,
gap_end
=
upcoming
.
star
t
))
schedule
.
append
(
timeslot_entry
(
timeslot
=
curren
t
))
last_timeslot
=
timeslots
.
last
()
if
include_virtual
and
current
.
end
!=
upcoming
.
start
:
schedule
.
append
(
gap_entry
(
gap_start
=
current
.
end
,
gap_end
=
upcoming
.
start
))
# we need to append the last timeslot to the schedule to complete it
last_timeslot
=
timeslots
.
last
()
if
last_timeslot
:
schedule
.
append
(
timeslot_entry
(
timeslot
=
last_timeslot
))
if
include_virtual
and
last_timeslot
.
end
<
schedule_end
:
# we need to append the last timeslot to the schedule to complete it
schedule
.
append
(
gap_entry
(
gap_start
=
last_timeslot
.
end
,
gap_end
=
schedule_end
))
if
last_timeslot
:
schedule
.
append
(
timeslot_entry
(
timeslot
=
last_timeslot
))
return
HttpResponse
(
if
include_virtual
and
last_timeslot
.
end
<
schedule_end
:
json
.
dumps
(
schedule
,
ensure_ascii
=
False
).
encode
(
"
utf8
"
),
schedule
.
append
(
gap_entry
(
gap_start
=
last_timeslot
.
end
,
gap_end
=
schedule_end
))
content_type
=
"
application/json; charset=utf-8
"
,
)
return
HttpResponse
(
json
.
dumps
(
schedule
,
ensure_ascii
=
False
).
encode
(
"
utf8
"
),
content_type
=
"
application/json; charset=utf-8
"
,
)
@extend_schema_view
(
@extend_schema_view
(
...
...
This diff is collapsed.
Click to expand it.
steering/urls.py
+
3
−
3
View file @
11482eca
...
@@ -44,7 +44,7 @@ from program.views import (
...
@@ -44,7 +44,7 @@ from program.views import (
APITypeViewSet
,
APITypeViewSet
,
APIUserViewSet
,
APIUserViewSet
,
json_day_schedule
,
json_day_schedule
,
json_playout
,
APIPlayoutViewSet
)
)
admin
.
autodiscover
()
admin
.
autodiscover
()
...
@@ -67,12 +67,12 @@ router.register(r"link-types", APILinkTypeViewSet, basename="link-type")
...
@@ -67,12 +67,12 @@ router.register(r"link-types", APILinkTypeViewSet, basename="link-type")
router
.
register
(
r
"
rrules
"
,
APIRRuleViewSet
,
basename
=
"
rrule
"
)
router
.
register
(
r
"
rrules
"
,
APIRRuleViewSet
,
basename
=
"
rrule
"
)
router
.
register
(
r
"
images
"
,
APIImageViewSet
,
basename
=
"
image
"
)
router
.
register
(
r
"
images
"
,
APIImageViewSet
,
basename
=
"
image
"
)
router
.
register
(
r
"
settings
"
,
APIRadioSettingsViewSet
,
basename
=
"
settings
"
)
router
.
register
(
r
"
settings
"
,
APIRadioSettingsViewSet
,
basename
=
"
settings
"
)
router
.
register
(
r
"
playout
"
,
APIPlayoutViewSet
,
basename
=
"
playout
"
)
router
.
register
(
r
"
program/week
"
,
APIPlayoutViewSet
,
basename
=
"
program/week
"
)
urlpatterns
=
[
urlpatterns
=
[
path
(
"
openid/
"
,
include
(
"
oidc_provider.urls
"
,
namespace
=
"
oidc_provider
"
)),
path
(
"
openid/
"
,
include
(
"
oidc_provider.urls
"
,
namespace
=
"
oidc_provider
"
)),
path
(
"
api/v1/
"
,
include
(
router
.
urls
)),
path
(
"
api/v1/
"
,
include
(
router
.
urls
)),
path
(
"
api/v1/playout
"
,
json_playout
),
path
(
"
api/v1/program/week
"
,
json_playout
),
path
(
"
api/v1/program/<int:year>/<int:month>/<int:day>/
"
,
json_day_schedule
),
path
(
"
api/v1/program/<int:year>/<int:month>/<int:day>/
"
,
json_day_schedule
),
path
(
"
api/v1/schema/
"
,
SpectacularAPIView
.
as_view
(),
name
=
"
schema
"
),
path
(
"
api/v1/schema/
"
,
SpectacularAPIView
.
as_view
(),
name
=
"
schema
"
),
path
(
path
(
...
...
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