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
d9fe318b
Verified
Commit
d9fe318b
authored
10 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
fix: create a timeslot with a cloned schedule for "ours-both"
parent
fb845f32
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/services.py
+15
-6
15 additions, 6 deletions
program/services.py
with
15 additions
and
6 deletions
program/services.py
+
15
−
6
View file @
d9fe318b
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
import
copy
from
datetime
import
datetime
,
time
,
timedelta
from
datetime
import
datetime
,
time
,
timedelta
from
typing
import
TypedDict
from
typing
import
TypedDict
...
@@ -148,6 +149,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -148,6 +149,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
to_create
:
list
[
TimeSlot
]
=
[]
to_create
:
list
[
TimeSlot
]
=
[]
to_update
:
list
[
TimeSlot
]
=
[]
to_update
:
list
[
TimeSlot
]
=
[]
to_delete
:
list
[
TimeSlot
]
=
[]
to_delete
:
list
[
TimeSlot
]
=
[]
to_instantiate
:
list
[
Schedule
]
=
[]
# only needed for the "ours-both" solution
errors
=
{}
errors
=
{}
...
@@ -249,7 +251,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -249,7 +251,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
# - Create projected
# - Create projected
# - Split existing into two
# - Split existing into two
# - Set existing end time to projected start
# - Set existing end time to projected start
# - C
reate another one
with start = projected end and end = existing end
# - C
lone the existing
with start = projected end and end = existing end
to_create
.
append
(
to_create
.
append
(
create_timeslot
(
timeslot
[
"
start
"
],
timeslot
[
"
end
"
],
new_schedule
),
create_timeslot
(
timeslot
[
"
start
"
],
timeslot
[
"
end
"
],
new_schedule
),
)
)
...
@@ -258,9 +260,15 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -258,9 +260,15 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
existing_ts
.
end
=
parse_datetime
(
timeslot
[
"
start
"
])
existing_ts
.
end
=
parse_datetime
(
timeslot
[
"
start
"
])
to_update
.
append
(
existing_ts
)
to_update
.
append
(
existing_ts
)
to_create
.
append
(
cloned_schedule
=
copy
.
copy
(
existing_ts
.
schedule
)
create_timeslot
(
timeslot
[
"
end
"
],
existing
[
"
end
"
],
new_schedule
),
)
cloned_schedule
.
pk
=
None
cloned_schedule
.
start_time
=
parse_datetime
(
timeslot
[
"
end
"
])
cloned_schedule
.
end_time
=
parse_datetime
(
existing
[
"
end
"
])
# keep track of the schedule to instantiate it before creating a timeslot if needed
to_instantiate
.
append
(
cloned_schedule
)
to_create
.
append
(
create_timeslot
(
timeslot
[
"
end
"
],
existing
[
"
end
"
],
cloned_schedule
))
# If there were any errors, don't make any db changes yet
# If there were any errors, don't make any db changes yet
# but add error messages and return already chosen solutions
# but add error messages and return already chosen solutions
...
@@ -319,6 +327,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -319,6 +327,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
if
last_date_is_unknown
:
if
last_date_is_unknown
:
new_schedule
.
last_date
=
None
new_schedule
.
last_date
=
None
for
cloned_schedule
in
to_instantiate
:
cloned_schedule
.
save
()
if
to_create
:
if
to_create
:
new_schedule
.
save
()
new_schedule
.
save
()
...
@@ -326,8 +337,6 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -326,8 +337,6 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
timeslot
.
save
(
update_fields
=
[
"
start
"
,
"
end
"
])
timeslot
.
save
(
update_fields
=
[
"
start
"
,
"
end
"
])
for
timeslot
in
to_create
:
for
timeslot
in
to_create
:
timeslot
.
schedule
=
new_schedule
# Reassign playlists
# Reassign playlists
if
"
playlists
"
in
data
and
timeslot
.
hash
in
data
[
"
playlists
"
]:
if
"
playlists
"
in
data
and
timeslot
.
hash
in
data
[
"
playlists
"
]:
timeslot
.
playlist_id
=
int
(
data
[
"
playlists
"
][
timeslot
.
hash
])
timeslot
.
playlist_id
=
int
(
data
[
"
playlists
"
][
timeslot
.
hash
])
...
...
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