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
c37bb783
There was a problem fetching the pipeline metadata.
Commit
c37bb783
authored
7 years ago
by
Valentin Groues
Browse files
Options
Downloads
Patches
Plain Diff
reset appointment types links when appointment date changes
parent
6a53c12b
No related branches found
No related tags found
1 merge request
!97
Resolve "appointment date change"
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/api_views/daily_planning.py
+2
-2
2 additions, 2 deletions
smash/web/api_views/daily_planning.py
smash/web/forms.py
+9
-3
9 additions, 3 deletions
smash/web/forms.py
smash/web/tests/forms/test_AppointmentEditForm.py
+65
-5
65 additions, 5 deletions
smash/web/tests/forms/test_AppointmentEditForm.py
with
76 additions
and
10 deletions
smash/web/api_views/daily_planning.py
+
2
−
2
View file @
c37bb783
...
...
@@ -7,8 +7,8 @@ from django.contrib.auth.decorators import login_required
from
django.http
import
JsonResponse
from
django.shortcuts
import
get_object_or_404
from
web.views
import
e500_error
from
web.models
import
Appointment
,
AppointmentTypeLink
,
Worker
,
Availability
,
Holiday
from
web.views
import
e500_error
from
web.views.notifications
import
get_filter_locations
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -202,7 +202,7 @@ def get_generic_appointment_events(request, date):
appointment_data
=
{
'
name
'
:
"
GENERAL
"
,
'
id
'
:
appointment
.
id
,
'
color
'
:
RANDOM_COLORS
[
len
(
RANDOM_COLORS
)
-
1
],
'
color
'
:
RANDOM_COLORS
[
len
(
RANDOM_COLORS
)
-
1
],
'
start
'
:
""
,
'
location
'
:
str
(
appointment
.
location
),
'
events
'
:
[]
...
...
This diff is collapsed.
Click to expand it.
smash/web/forms.py
+
9
−
3
View file @
c37bb783
...
...
@@ -6,7 +6,7 @@ from django.forms import ModelForm, Form
from
django.utils.dates
import
MONTHS
from
web.models
import
Subject
,
Worker
,
Appointment
,
Visit
,
AppointmentType
,
ContactAttempt
,
AppointmentTypeLink
,
\
Availability
,
Holiday
,
Country
Availability
,
Holiday
from
web.models.constants
import
SUBJECT_TYPE_CHOICES
,
SCREENING_NUMBER_PREFIXES_FOR_TYPE
,
COUNTRY_OTHER_ID
from
web.views.notifications
import
get_filter_locations
...
...
@@ -254,7 +254,12 @@ class AppointmentEditForm(ModelForm):
def
save
(
self
,
commit
=
True
):
appointment
=
super
(
AppointmentEditForm
,
self
).
save
(
commit
)
appointment_type_links
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
appointment
).
all
()
# if appointment date change, remove appointment_type links
if
'
datetime_when
'
in
self
.
changed_data
:
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
appointment
).
delete
()
appointment_type_links
=
[]
else
:
appointment_type_links
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
appointment
).
all
()
appointment_types_from_links
=
[]
appointment_types
=
self
.
cleaned_data
[
'
appointment_types
'
]
for
appointment_type_link
in
appointment_type_links
:
...
...
@@ -266,7 +271,8 @@ class AppointmentEditForm(ModelForm):
for
appointment_type
in
appointment_types
:
if
appointment_type
not
in
appointment_types_from_links
:
# we create new appointment links for appointments types that have been added
appointment_type_link
=
AppointmentTypeLink
(
appointment
=
appointment
,
appointment_type
=
appointment_type
)
appointment_type_link
=
AppointmentTypeLink
(
appointment
=
appointment
,
appointment_type
=
appointment_type
)
appointment_type_link
.
save
()
return
appointment
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/forms/test_AppointmentEditForm.py
+
65
−
5
View file @
c37bb783
...
...
@@ -2,8 +2,8 @@ from django.test import TestCase
from
web.forms
import
AppointmentAddForm
from
web.forms
import
AppointmentEditForm
from
web.models
import
Appointment
,
Worker
from
web.tests.functions
import
get_test_location
,
create_user
,
create_visit
,
create_location
from
web.models
import
Appointment
,
Worker
,
AppointmentTypeLink
from
web.tests.functions
import
get_test_location
,
create_user
,
create_visit
,
create_location
,
create_appointment_type
class
AppointmentEditFormTests
(
TestCase
):
...
...
@@ -11,9 +11,9 @@ class AppointmentEditFormTests(TestCase):
location
=
get_test_location
()
self
.
user
=
create_user
()
worker
=
Worker
.
get_by_user
(
self
.
user
)
worker
.
locations
=
[
get_test_location
()]
worker
.
save
()
self
.
worker
=
Worker
.
get_by_user
(
self
.
user
)
self
.
worker
.
locations
=
[
get_test_location
()]
self
.
worker
.
save
()
self
.
visit
=
create_visit
()
...
...
@@ -27,6 +27,66 @@ class AppointmentEditFormTests(TestCase):
add_form
=
AppointmentAddForm
(
user
=
self
.
user
,
data
=
self
.
sample_data
)
add_form
.
instance
.
visit_id
=
self
.
visit
.
id
self
.
appointment
=
add_form
.
save
()
self
.
appointment_type
=
create_appointment_type
()
def
test_appointment_types_links_add_type
(
self
):
self
.
assertFalse
(
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
all
())
sample_data
=
self
.
sample_data
.
copy
()
sample_data
[
'
appointment_types
'
]
=
[
self
.
appointment_type
.
id
]
form
=
AppointmentEditForm
(
user
=
self
.
user
,
instance
=
self
.
appointment
,
data
=
sample_data
)
self
.
assertTrue
(
form
.
is_valid
())
form
.
save
()
self
.
assertEqual
(
1
,
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
count
(),
"
one appointment link should have been created
"
)
def
test_appointment_types_links_removed_after_date_changed
(
self
):
# create first link
self
.
test_appointment_types_links_add_type
()
# modify link
link
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
first
()
self
.
assertIsNone
(
link
.
worker
)
link
.
worker
=
self
.
worker
link
.
save
()
self
.
assertEqual
(
self
.
worker
,
link
.
worker
)
# change date
sample_data
=
self
.
sample_data
.
copy
()
sample_data
[
'
appointment_types
'
]
=
[
self
.
appointment_type
.
id
]
sample_data
[
'
datetime_when
'
]
=
'
2021-01-01
'
form
=
AppointmentEditForm
(
user
=
self
.
user
,
instance
=
self
.
appointment
,
data
=
sample_data
)
self
.
assertTrue
(
form
.
is_valid
())
form
.
save
()
# check that the appointment links have been deleted and recreated
links_count
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
count
()
self
.
assertEqual
(
1
,
links_count
,
"
only one appointment link should exist, {} found
"
.
format
(
links_count
))
new_link
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
first
()
self
.
assertNotEqual
(
link
,
new_link
)
self
.
assertIsNone
(
new_link
.
worker
)
def
test_appointment_types_links_kept_if_no_date_changed
(
self
):
# create first link
self
.
test_appointment_types_links_add_type
()
# modify link
link
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
first
()
self
.
assertIsNone
(
link
.
worker
)
link
.
worker
=
self
.
worker
link
.
save
()
self
.
assertEqual
(
self
.
worker
,
link
.
worker
)
# change length
sample_data
=
self
.
sample_data
.
copy
()
sample_data
[
'
length
'
]
=
'
100
'
sample_data
[
'
appointment_types
'
]
=
[
self
.
appointment_type
.
id
]
form
=
AppointmentEditForm
(
user
=
self
.
user
,
instance
=
self
.
appointment
,
data
=
sample_data
)
self
.
assertTrue
(
form
.
is_valid
())
self
.
appointment
=
form
.
save
()
self
.
assertEqual
(
100
,
self
.
appointment
.
length
)
# check that the appointment links have been kept
links_count
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
count
()
self
.
assertEqual
(
1
,
links_count
,
"
only one appointment link should exist, {} found
"
.
format
(
links_count
))
new_link
=
AppointmentTypeLink
.
objects
.
filter
(
appointment
=
self
.
appointment
).
first
()
self
.
assertEqual
(
link
.
id
,
new_link
.
id
)
self
.
assertEqual
(
self
.
worker
,
new_link
.
worker
)
def
test_validation
(
self
):
form
=
AppointmentEditForm
(
user
=
self
.
user
,
data
=
self
.
sample_data_with_status
)
...
...
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