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
02fa66a7
Commit
02fa66a7
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
cleaned a bit the code
parent
e98ed3d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!194
Issue #195 added tests and changed the post_save function for visit. I didn't…
Pipeline
#7571
passed
6 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/models/visit.py
+3
-17
3 additions, 17 deletions
smash/web/models/visit.py
with
3 additions
and
17 deletions
smash/web/models/visit.py
+
3
−
17
View file @
02fa66a7
...
@@ -85,30 +85,16 @@ class Visit(models.Model):
...
@@ -85,30 +85,16 @@ class Visit(models.Model):
@receiver
(
post_save
,
sender
=
Visit
)
@receiver
(
post_save
,
sender
=
Visit
)
def
check_visit_number
(
sender
,
instance
,
**
kwargs
):
def
check_visit_number
(
sender
,
instance
,
**
kwargs
):
# no other solution to ensure the visit_number is in cronological order than to sort the whole list
# no other solution to ensure the visit_number is in cronological order than to sort the whole list
if there are future visits
visit
=
instance
visit
=
instance
if
visit
.
subject
is
not
None
:
#not sure if select_for_update has an effect
if
visit
.
subject
is
not
None
:
#not sure if select_for_update has an effect
, the tests work as well without it
visits_before
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
filter
(
datetime_begin__lt
=
visit
.
datetime_begin
).
count
()
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 this one, if any
# we need to sort the future visits respect to this 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_end
'
)
visits
=
Visit
.
objects
.
select_for_update
().
filter
(
subject
=
visit
.
subject
).
filter
(
datetime_begin__gte
=
visit
.
datetime_begin
).
order_by
(
'
datetime_begin
'
,
'
datetime_end
'
)
with
transaction
.
atomic
():
#not sure if has an effect
with
transaction
.
atomic
():
#not sure if
it
has an effect
, the tests work as well without it
for
i
,
v
in
enumerate
(
visits
):
for
i
,
v
in
enumerate
(
visits
):
if
v
.
visit_number
!=
(
visits_before
+
i
+
1
):
if
v
.
visit_number
!=
(
visits_before
+
i
+
1
):
visit_number
=
(
visits_before
+
i
+
1
)
visit_number
=
(
visits_before
+
i
+
1
)
Visit
.
objects
.
filter
(
id
=
v
.
id
).
update
(
visit_number
=
visit_number
)
# does not rise post_save, we avoid recursion
Visit
.
objects
.
filter
(
id
=
v
.
id
).
update
(
visit_number
=
visit_number
)
# does not rise post_save, we avoid recursion
if
v
.
id
==
visit
.
id
:
if
v
.
id
==
visit
.
id
:
visit
.
visit_number
=
v
.
visit_number
visit
.
visit_number
=
v
.
visit_number
# @receiver(post_save, sender=Visit)
# def update_visit_number(sender, instance, **kwargs):
# n = kwargs.get('n', 1)
# visit = instance
# if visit.subject is not None:
# count = Visit.objects.filter(subject=visit.subject).filter(datetime_begin__lte=visit.datetime_begin).count()
# if count != visit.visit_number:
# visit.visit_number = count
# visit.save()
# subject_visits = Visit.objects.filter(subject=visit.subject).all()
# for subject_visit in subject_visits:
# update_visit_number(sender, subject_visit, n=(n+1))
\ No newline at end of file
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