Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AKPlanning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Felix Blanke
AKPlanning
Commits
ba15b01d
Commit
ba15b01d
authored
2 years ago
by
Nadja Geisler
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-cv-checking' into 'main'
Fix constraint checking issues Closes
#132
and
#131
See merge request
!118
parents
b00d0427
8b5ffde8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
AKModel/availability/forms.py
+7
-1
7 additions, 1 deletion
AKModel/availability/forms.py
AKScheduling/models.py
+14
-1
14 additions, 1 deletion
AKScheduling/models.py
with
21 additions
and
2 deletions
AKModel/availability/forms.py
+
7
−
1
View file @
ba15b01d
...
...
@@ -7,6 +7,7 @@ import json
from
django
import
forms
from
django.db
import
transaction
from
django.db.models.signals
import
post_save
from
django.utils.dateparse
import
parse_datetime
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -142,11 +143,16 @@ class AvailabilitiesFormMixin(forms.Form):
for
avail
in
availabilities
:
setattr
(
avail
,
reference_name
,
instance
.
id
)
def
_replace_availabilities
(
self
,
instance
,
availabilities
):
def
_replace_availabilities
(
self
,
instance
,
availabilities
:
[
Availability
]
):
with
transaction
.
atomic
():
# TODO: do not recreate objects unnecessarily, give the client the IDs, so we can track modifications and leave unchanged objects alone
instance
.
availabilities
.
all
().
delete
()
Availability
.
objects
.
bulk_create
(
availabilities
)
# Trigger post save signal manually to make sure constraints are updated accordingly
# Doing this one time is sufficient, since this will nevertheless update all availability constraint
# violations of the corresponding AK
if
len
(
availabilities
)
>
0
:
post_save
.
send
(
Availability
,
instance
=
availabilities
[
0
],
created
=
True
)
def
save
(
self
,
*
args
,
**
kwargs
):
instance
=
super
().
save
(
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
AKScheduling/models.py
+
14
−
1
View file @
ba15b01d
from
django.db.models.signals
import
post_save
,
m2m_changed
from
django.db.models.signals
import
post_save
,
m2m_changed
,
pre_delete
from
django.dispatch
import
receiver
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -551,6 +551,19 @@ def akslot_changed_handler(sender, instance: AKSlot, **kwargs):
update_constraint_violations
(
new_violations
,
existing_violations_to_check
)
@receiver
(
pre_delete
,
sender
=
AKSlot
)
def
akslot_deleted_handler
(
sender
,
instance
:
AKSlot
,
**
kwargs
):
# Manually clean up or remove constraint violations that belong to this slot since there is no cascade deletion
# for many2many relationships. Explicitly listening for AK deletion signals is not necessary since they will
# transitively trigger this signal and we always set both AK and AKSlot references in a constraint violation
print
(
f
"
{
instance
}
deleted
"
)
for
cv
in
instance
.
constraintviolation_set
.
all
():
# Make sure not delete CVs that e.g., show three parallel slots in a single room
if
cv
.
ak_slots
.
count
()
<=
2
:
cv
.
delete
()
@receiver
(
post_save
,
sender
=
Room
)
def
room_changed_handler
(
sender
,
instance
:
Room
,
**
kwargs
):
# Changes might affect: Room size
...
...
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