Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
SMASCH
scheduling-system
Commits
4fc607ce
Commit
4fc607ce
authored
4 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
visit order should be computed on ids if the begin_date is the same
parent
b58513a8
No related branches found
No related tags found
1 merge request
!304
Resolve "two visits with the same dates"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG
+7
-0
7 additions, 0 deletions
CHANGELOG
smash/web/models/visit.py
+5
-4
5 additions, 4 deletions
smash/web/models/visit.py
smash/web/tests/models/test_visit.py
+29
-0
29 additions, 0 deletions
smash/web/tests/models/test_visit.py
with
41 additions
and
4 deletions
CHANGELOG
+
7
−
0
View file @
4fc607ce
smasch (1.0.0~beta.6-1) unstable; urgency=low
* bug fix: when two visits with the same start date are created compute visit
number on the visit creation order basis (#369)
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 24 Feb 2021 12:00:00 +0200
smasch (1.0.0~beta.5-1) unstable; urgency=low
* bug fix: login page did not contain valid link to help with account
...
...
This diff is collapsed.
Click to expand it.
smash/web/models/visit.py
+
5
−
4
View file @
4fc607ce
...
...
@@ -126,16 +126,17 @@ class Visit(models.Model):
self
.
save
()
return
@receiver
(
post_save
,
sender
=
Visit
)
def
check_visit_number
(
sender
,
instance
,
created
,
**
kwargs
):
# no other solution to ensure the visit_number is in cronological order than to sort the whole list if there are future visits
# no other solution to ensure the visit_number is in c
h
ronological order than to sort the whole list if there are future visits
visit
=
instance
if
visit
.
subject
is
not
None
:
#not sure if select_for_update has an effect, the tests work as well without it
#new visit, sort only future visit respect to the new one
if
created
:
visits_before
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
filter
(
datetime_begin__lt
=
visit
.
datetime_begin
).
count
()
# we need to sort the future visits respect to the new one, if any
visits
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
filter
(
datetime_begin__gte
=
visit
.
datetime_begin
).
order_by
(
'
datetime_begin
'
,
'
datetime_en
d
'
)
visits
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
filter
(
datetime_begin__gte
=
visit
.
datetime_begin
).
order_by
(
'
datetime_begin
'
,
'
i
d
'
)
with
transaction
.
atomic
():
#not sure if it has an effect, the tests work as well without it
for
i
,
v
in
enumerate
(
visits
):
expected_visit_number
=
(
visits_before
+
i
+
1
)
...
...
@@ -143,10 +144,10 @@ def check_visit_number(sender, instance, created, **kwargs):
Visit
.
objects
.
filter
(
id
=
v
.
id
).
update
(
visit_number
=
expected_visit_number
)
# does not rise post_save, we avoid recursion
if
v
.
id
==
visit
.
id
:
#if the iteration visit is the same that the instance that produced the signal call
#this ensures that the upper saved object is also updated, otherwise, refresh_from_db should be called
visit
.
visit_number
=
v
.
visit_number
visit
.
visit_number
=
v
.
visit_number
else
:
#if visits are modified, then, check everything
visits
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
order_by
(
'
datetime_begin
'
,
'
datetime_en
d
'
)
visits
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
order_by
(
'
datetime_begin
'
,
'
i
d
'
)
with
transaction
.
atomic
():
for
i
,
v
in
enumerate
(
visits
):
expected_visit_number
=
(
i
+
1
)
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/models/test_visit.py
+
29
−
0
View file @
4fc607ce
...
...
@@ -229,3 +229,32 @@ class VisitModelTests(TestCase):
def
test_visit_to_unicode
(
self
):
visit
=
create_visit
(
create_study_subject
())
self
.
assertIsNotNone
(
str
(
visit
))
def
test_visit_numbers_with_the_same_dates
(
self
):
subject
=
create_study_subject
()
visit1
=
create_visit
(
subject
=
subject
,
datetime_begin
=
get_today_midnight_date
()
-
datetime
.
timedelta
(
days
=
1
),
datetime_end
=
get_today_midnight_date
()
+
datetime
.
timedelta
(
days
=
4
))
visit2
=
create_visit
(
subject
=
subject
,
datetime_begin
=
get_today_midnight_date
()
-
datetime
.
timedelta
(
days
=
1
),
datetime_end
=
get_today_midnight_date
()
+
datetime
.
timedelta
(
days
=
3
))
visit3
=
create_visit
(
subject
=
subject
,
datetime_begin
=
get_today_midnight_date
()
+
datetime
.
timedelta
(
days
=
1
),
datetime_end
=
get_today_midnight_date
()
+
datetime
.
timedelta
(
days
=
2
))
visit3
.
is_finished
=
True
visit3
.
save
()
visit2
.
mark_as_finished
()
visit1
.
is_finished
=
True
visit1
.
save
()
self
.
assertEqual
(
4
,
Visit
.
objects
.
filter
(
subject
=
subject
).
count
())
# order should be [V1, V2, V3]
visit1
.
refresh_from_db
()
visit2
.
refresh_from_db
()
visit3
.
refresh_from_db
()
self
.
assertEqual
(
1
,
visit1
.
visit_number
)
self
.
assertEqual
(
2
,
visit2
.
visit_number
)
self
.
assertEqual
(
3
,
visit3
.
visit_number
)
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