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
c2c3a9cc
Verified
Commit
c2c3a9cc
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
fix: added missing _id suffixes and fixed use of model_to_dict
Closes:
#155
parent
c296877c
No related branches found
No related tags found
No related merge requests found
Pipeline
#3416
passed
1 year ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/serializers.py
+14
-10
14 additions, 10 deletions
program/serializers.py
program/services.py
+9
-7
9 additions, 7 deletions
program/services.py
with
23 additions
and
17 deletions
program/serializers.py
+
14
−
10
View file @
c2c3a9cc
...
@@ -83,16 +83,18 @@ class ErrorSerializer(serializers.Serializer):
...
@@ -83,16 +83,18 @@ class ErrorSerializer(serializers.Serializer):
class
ProfileSerializer
(
serializers
.
ModelSerializer
):
class
ProfileSerializer
(
serializers
.
ModelSerializer
):
user_id
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
User
.
objects
.
all
(),
source
=
"
user
"
)
class
Meta
:
class
Meta
:
model
=
UserProfile
model
=
UserProfile
fields
=
(
fields
=
(
"
user
"
,
"
cba_username
"
,
"
cba_username
"
,
"
cba_user_token
"
,
"
cba_user_token
"
,
"
created_at
"
,
"
created_at
"
,
"
created_by
"
,
"
created_by
"
,
"
updated_at
"
,
"
updated_at
"
,
"
updated_by
"
,
"
updated_by
"
,
"
user_id
"
,
)
)
read_only_fields
=
(
read_only_fields
=
(
"
created_at
"
,
"
created_at
"
,
...
@@ -281,10 +283,8 @@ class ImageSerializer(serializers.ModelSerializer):
...
@@ -281,10 +283,8 @@ class ImageSerializer(serializers.ModelSerializer):
class
HostSerializer
(
serializers
.
ModelSerializer
):
class
HostSerializer
(
serializers
.
ModelSerializer
):
image
=
serializers
.
PrimaryKeyRelatedField
(
image_id
=
serializers
.
PrimaryKeyRelatedField
(
allow_null
=
True
,
allow_null
=
True
,
queryset
=
Image
.
objects
.
all
(),
required
=
False
,
source
=
"
image
"
queryset
=
Image
.
objects
.
all
(),
required
=
False
,
)
)
links
=
HostLinkSerializer
(
many
=
True
,
required
=
False
)
links
=
HostLinkSerializer
(
many
=
True
,
required
=
False
)
...
@@ -300,7 +300,7 @@ class HostSerializer(serializers.ModelSerializer):
...
@@ -300,7 +300,7 @@ class HostSerializer(serializers.ModelSerializer):
"
biography
"
,
"
biography
"
,
"
email
"
,
"
email
"
,
"
id
"
,
"
id
"
,
"
image
"
,
"
image
_id
"
,
"
is_active
"
,
"
is_active
"
,
"
links
"
,
"
links
"
,
"
name
"
,
"
name
"
,
...
@@ -313,6 +313,8 @@ class HostSerializer(serializers.ModelSerializer):
...
@@ -313,6 +313,8 @@ class HostSerializer(serializers.ModelSerializer):
links_data
=
validated_data
.
pop
(
"
links
"
,
[])
links_data
=
validated_data
.
pop
(
"
links
"
,
[])
validated_data
[
"
image
"
]
=
validated_data
.
pop
(
"
image_id
"
,
None
)
host
=
Host
.
objects
.
create
(
host
=
Host
.
objects
.
create
(
created_by
=
self
.
context
.
get
(
"
request
"
).
user
.
username
,
**
validated_data
created_by
=
self
.
context
.
get
(
"
request
"
).
user
.
username
,
**
validated_data
)
)
...
@@ -331,7 +333,7 @@ class HostSerializer(serializers.ModelSerializer):
...
@@ -331,7 +333,7 @@ class HostSerializer(serializers.ModelSerializer):
instance
.
biography
=
validated_data
.
get
(
"
biography
"
,
instance
.
biography
)
instance
.
biography
=
validated_data
.
get
(
"
biography
"
,
instance
.
biography
)
instance
.
email
=
validated_data
.
get
(
"
email
"
,
instance
.
email
)
instance
.
email
=
validated_data
.
get
(
"
email
"
,
instance
.
email
)
instance
.
image
=
validated_data
.
get
(
"
image
"
,
instance
.
image
)
instance
.
image
=
validated_data
.
get
(
"
image
_id
"
,
instance
.
image
)
instance
.
is_active
=
validated_data
.
get
(
"
is_active
"
,
instance
.
is_active
)
instance
.
is_active
=
validated_data
.
get
(
"
is_active
"
,
instance
.
is_active
)
instance
.
name
=
validated_data
.
get
(
"
name
"
,
instance
.
name
)
instance
.
name
=
validated_data
.
get
(
"
name
"
,
instance
.
name
)
...
@@ -643,7 +645,7 @@ class CollisionSerializer(serializers.Serializer):
...
@@ -643,7 +645,7 @@ class CollisionSerializer(serializers.Serializer):
playlist_id
=
serializers
.
IntegerField
(
allow_null
=
True
)
playlist_id
=
serializers
.
IntegerField
(
allow_null
=
True
)
show_id
=
serializers
.
IntegerField
()
show_id
=
serializers
.
IntegerField
()
show_name
=
serializers
.
CharField
()
show_name
=
serializers
.
CharField
()
repetition_of
=
serializers
.
IntegerField
(
allow_null
=
True
)
repetition_of
_id
=
serializers
.
IntegerField
(
allow_null
=
True
)
schedule_id
=
serializers
.
IntegerField
()
schedule_id
=
serializers
.
IntegerField
()
memo
=
serializers
.
CharField
()
memo
=
serializers
.
CharField
()
note_id
=
serializers
.
IntegerField
(
allow_null
=
True
)
note_id
=
serializers
.
IntegerField
(
allow_null
=
True
)
...
@@ -741,7 +743,9 @@ class NoteLinkSerializer(serializers.ModelSerializer):
...
@@ -741,7 +743,9 @@ class NoteLinkSerializer(serializers.ModelSerializer):
class
NoteSerializer
(
serializers
.
ModelSerializer
):
class
NoteSerializer
(
serializers
.
ModelSerializer
):
contributors
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
Host
.
objects
.
all
(),
many
=
True
)
contributor_ids
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
Host
.
objects
.
all
(),
source
=
"
contributors
"
)
image_id
=
serializers
.
PrimaryKeyRelatedField
(
image_id
=
serializers
.
PrimaryKeyRelatedField
(
queryset
=
Image
.
objects
.
all
(),
required
=
False
,
allow_null
=
True
queryset
=
Image
.
objects
.
all
(),
required
=
False
,
allow_null
=
True
)
)
...
@@ -763,7 +767,7 @@ class NoteSerializer(serializers.ModelSerializer):
...
@@ -763,7 +767,7 @@ class NoteSerializer(serializers.ModelSerializer):
fields
=
(
fields
=
(
"
cba_id
"
,
"
cba_id
"
,
"
content
"
,
"
content
"
,
"
contributors
"
,
"
contributor
_id
s
"
,
"
id
"
,
"
id
"
,
"
image_id
"
,
"
image_id
"
,
"
links
"
,
"
links
"
,
...
...
This diff is collapsed.
Click to expand it.
program/services.py
+
9
−
7
View file @
c2c3a9cc
...
@@ -25,10 +25,10 @@ from dateutil.rrule import rrule
...
@@ -25,10 +25,10 @@ from dateutil.rrule import rrule
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.exceptions
import
ValidationError
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.forms.models
import
model_to_dict
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
program.models
import
Note
,
RRule
,
Schedule
,
ScheduleConflictError
,
Show
,
TimeSlot
from
program.models
import
Note
,
RRule
,
Schedule
,
ScheduleConflictError
,
Show
,
TimeSlot
from
program.serializers
import
ScheduleSerializer
,
TimeSlotSerializer
from
program.utils
import
parse_date
,
parse_datetime
,
parse_time
from
program.utils
import
parse_date
,
parse_datetime
,
parse_time
from
steering.settings
import
(
from
steering.settings
import
(
AUTO_SET_LAST_DATE_TO_DAYS_IN_FUTURE
,
AUTO_SET_LAST_DATE_TO_DAYS_IN_FUTURE
,
...
@@ -271,7 +271,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -271,7 +271,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
# 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
if
len
(
errors
)
>
0
:
if
len
(
errors
)
>
0
:
conflicts
=
make_conflicts
(
model_to_dict
(
new_schedule
),
new_schedule
.
pk
,
show
.
pk
)
conflicts
=
make_conflicts
(
ScheduleSerializer
().
to_representation
(
new_schedule
),
new_schedule
.
pk
,
show
.
pk
)
partly_resolved
=
conflicts
[
"
projected
"
]
partly_resolved
=
conflicts
[
"
projected
"
]
saved_solutions
=
{}
saved_solutions
=
{}
...
@@ -313,9 +315,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -313,9 +315,9 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
# If 'dryrun' is true, just return the projected changes instead of executing them
# If 'dryrun' is true, just return the projected changes instead of executing them
if
"
dryrun
"
in
schedule
and
schedule
[
"
dryrun
"
]:
if
"
dryrun
"
in
schedule
and
schedule
[
"
dryrun
"
]:
return
{
return
{
"
create
"
:
[
model_to_dict
(
timeslot
)
for
timeslot
in
to_create
],
"
create
"
:
[
TimeSlotSerializer
().
to_representation
(
timeslot
)
for
timeslot
in
to_create
],
"
update
"
:
[
model_to_dict
(
timeslot
)
for
timeslot
in
to_update
],
"
update
"
:
[
TimeSlotSerializer
().
to_representation
(
timeslot
)
for
timeslot
in
to_update
],
"
delete
"
:
[
model_to_dict
(
timeslot
)
for
timeslot
in
to_delete
],
"
delete
"
:
[
TimeSlotSerializer
().
to_representation
(
timeslot
)
for
timeslot
in
to_delete
],
}
}
# Database changes if no errors found
# Database changes if no errors found
...
@@ -354,7 +356,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
...
@@ -354,7 +356,7 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s
for
timeslot
in
to_delete
:
for
timeslot
in
to_delete
:
timeslot
.
delete
()
timeslot
.
delete
()
return
model_to_dict
(
new_schedule
)
return
ScheduleSerializer
().
to_representation
(
new_schedule
)
def
instantiate_upcoming_schedule
(
def
instantiate_upcoming_schedule
(
...
@@ -440,7 +442,7 @@ def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int) ->
...
@@ -440,7 +442,7 @@ def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int) ->
conflicts
=
generate_conflicts
(
timeslots
)
conflicts
=
generate_conflicts
(
timeslots
)
# create a new dictionary by adding "schedule" to conflicts
# create a new dictionary by adding "schedule" to conflicts
return
dict
(
conflicts
,
schedule
=
model_to_dict
(
new_schedule
))
return
dict
(
conflicts
,
schedule
=
ScheduleSerializer
().
to_representation
(
new_schedule
))
def
generate_timeslots
(
schedule
:
Schedule
)
->
list
[
TimeSlot
]:
def
generate_timeslots
(
schedule
:
Schedule
)
->
list
[
TimeSlot
]:
...
...
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