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
5c8c5992
Commit
5c8c5992
authored
8 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
list of appointments (ith calendar) uses dynamic loading of data
parent
f5413b19
No related branches found
No related tags found
1 merge request
!35
performance on appointment list
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/api_views/appointment.py
+27
-10
27 additions, 10 deletions
smash/web/api_views/appointment.py
smash/web/templates/appointments/index.html
+68
-66
68 additions, 66 deletions
smash/web/templates/appointments/index.html
smash/web/views/appointment.py
+2
-10
2 additions, 10 deletions
smash/web/views/appointment.py
with
97 additions
and
86 deletions
smash/web/api_views/appointment.py
+
27
−
10
View file @
5c8c5992
import
traceback
import
traceback
import
pytz
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
JsonResponse
from
django.http
import
JsonResponse
from
django.urls
import
reverse
from
web.models
import
Appointment
from
web.models
import
Appointment
from
web.views
import
e500_error
from
web.views
import
e500_error
...
@@ -13,13 +13,14 @@ from web.views.notifications import get_filter_locations, \
...
@@ -13,13 +13,14 @@ from web.views.notifications import get_filter_locations, \
@login_required
@login_required
def
get_appointments
(
request
,
type
):
def
get_appointments
(
request
,
type
,
min_date
,
max_date
):
if
type
==
APPOINTMENT_LIST_GENERIC
:
if
type
==
APPOINTMENT_LIST_GENERIC
:
return
Appointment
.
objects
.
filter
(
location__in
=
get_filter_locations
(
request
.
user
)).
order_by
(
"
datetime_when
"
)
result
=
Appointment
.
objects
.
filter
(
location__in
=
get_filter_locations
(
request
.
user
),
)
elif
type
==
APPOINTMENT_LIST_UNFINISHED
:
elif
type
==
APPOINTMENT_LIST_UNFINISHED
:
re
turn
get_unfinished_appointments
(
request
.
user
)
.
order_by
(
"
datetime_when
"
)
re
sult
=
get_unfinished_appointments
(
request
.
user
)
elif
type
==
APPOINTMENT_LIST_APPROACHING
:
elif
type
==
APPOINTMENT_LIST_APPROACHING
:
re
turn
Appointment
.
objects
.
filter
(
re
sult
=
Appointment
.
objects
.
filter
(
datetime_when__gt
=
get_today_midnight_date
(),
datetime_when__gt
=
get_today_midnight_date
(),
location__in
=
get_filter_locations
(
request
.
user
),
location__in
=
get_filter_locations
(
request
.
user
),
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
...
@@ -27,6 +28,13 @@ def get_appointments(request, type):
...
@@ -27,6 +28,13 @@ def get_appointments(request, type):
else
:
else
:
raise
TypeError
(
"
Unknown query type:
"
+
type
)
raise
TypeError
(
"
Unknown query type:
"
+
type
)
if
min_date
is
not
None
:
result
=
result
.
filter
(
datetime_when__gt
=
min_date
)
if
max_date
is
not
None
:
result
=
result
.
filter
(
datetime_when__lt
=
max_date
)
return
result
.
order_by
(
"
datetime_when
"
)
@login_required
@login_required
def
appointments
(
request
,
type
):
def
appointments
(
request
,
type
):
...
@@ -36,7 +44,12 @@ def appointments(request, type):
...
@@ -36,7 +44,12 @@ def appointments(request, type):
start
=
int
(
request
.
GET
.
get
(
"
start
"
,
"
0
"
))
start
=
int
(
request
.
GET
.
get
(
"
start
"
,
"
0
"
))
length
=
int
(
request
.
GET
.
get
(
"
length
"
,
"
10
"
))
length
=
int
(
request
.
GET
.
get
(
"
length
"
,
"
10
"
))
order
=
int
(
request
.
GET
.
get
(
"
order[0][column]
"
,
"
0
"
))
min_date
=
request
.
GET
.
get
(
"
start_date
"
,
None
)
max_date
=
request
.
GET
.
get
(
"
end_date
"
,
None
)
if
min_date
is
not
None
:
length
=
1000000000
filters
=
[]
filters
=
[]
column_id
=
0
column_id
=
0
...
@@ -46,7 +59,7 @@ def appointments(request, type):
...
@@ -46,7 +59,7 @@ def appointments(request, type):
filters
.
append
([
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][data]
"
),
val
])
filters
.
append
([
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][data]
"
),
val
])
column_id
+=
1
column_id
+=
1
all_appointments
=
get_appointments
(
request
,
type
)
all_appointments
=
get_appointments
(
request
,
type
,
min_date
,
max_date
)
count
=
all_appointments
.
count
()
count
=
all_appointments
.
count
()
...
@@ -54,7 +67,7 @@ def appointments(request, type):
...
@@ -54,7 +67,7 @@ def appointments(request, type):
appointments
=
sliced_subjects
appointments
=
sliced_subjects
count_filtered
=
all_appointmen
ts
.
count
()
count_filtered
=
sliced_subjec
ts
.
count
()
data
=
[]
data
=
[]
for
appointment
in
appointments
:
for
appointment
in
appointments
:
...
@@ -72,8 +85,6 @@ def appointments(request, type):
...
@@ -72,8 +85,6 @@ def appointments(request, type):
def
serialize_appointment
(
appointment
):
def
serialize_appointment
(
appointment
):
local_tz
=
pytz
.
timezone
(
'
UTC
'
)
subject
=
""
subject
=
""
if
appointment
.
visit
is
not
None
:
if
appointment
.
visit
is
not
None
:
title
=
appointment
.
visit
.
follow_up_title
()
title
=
appointment
.
visit
.
follow_up_title
()
...
@@ -88,13 +99,19 @@ def serialize_appointment(appointment):
...
@@ -88,13 +99,19 @@ def serialize_appointment(appointment):
if
appointment
.
datetime_when
is
not
None
:
if
appointment
.
datetime_when
is
not
None
:
time
=
appointment
.
datetime_when
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
time
=
appointment
.
datetime_when
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
# time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M:%S.%f %Z%z')
# time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M:%S.%f %Z%z')
until
=
""
if
appointment
.
datetime_when
is
not
None
:
until
=
appointment
.
datetime_until
().
strftime
(
'
%Y-%m-%d %H:%M
'
)
result
=
{
result
=
{
"
subject
"
:
subject
,
"
subject
"
:
subject
,
"
title
"
:
title
,
"
title
"
:
title
,
"
type
"
:
type
,
"
type
"
:
type
,
"
datetime_when
"
:
time
,
"
datetime_when
"
:
time
,
"
datetime_until
"
:
until
,
"
comment
"
:
appointment
.
comment
,
"
comment
"
:
appointment
.
comment
,
"
color
"
:
appointment
.
color
(),
"
id
"
:
appointment
.
id
,
"
id
"
:
appointment
.
id
,
"
url
"
:
reverse
(
'
web.views.appointment_edit
'
,
kwargs
=
{
'
id
'
:
str
(
appointment
.
id
)})
}
}
return
result
return
result
This diff is collapsed.
Click to expand it.
smash/web/templates/appointments/index.html
+
68
−
66
View file @
5c8c5992
...
@@ -24,53 +24,20 @@
...
@@ -24,53 +24,20 @@
{% block maincontent %}
{% block maincontent %}
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-5"
>
<div
class=
"col-md-5"
>
{% if approaching_list %}
<table
id=
"approaching_table"
class=
"table table-bordered table-striped"
>
<table
id=
"approaching_table"
class=
"table table-bordered table-striped"
>
<thead>
<thead>
<tr>
<tr>
<th>
Subject
</th>
<th>
Subject
</th>
<th>
Visit
</th>
<th>
Visit
</th>
<th>
Type
</th>
<th>
Type
</th>
<th>
Date
</th>
<th>
Date
</th>
<th>
Details
</th>
<th>
Details
</th>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody>
</tbody>
</table>
{% for approach in approaching_list %}
<tr>
{% if approach.visit == None %}
<td>
</td>
<td>
</td>
{% else %}
<td>
{{ approach.visit.subject.first_name }} {{ approach.visit.subject.last_name }}
({{ approach.visit.subject.nd_number }})
</td>
<td>
{{ approach.visit.follow_up_title }}
</td>
{% endif %}
<td>
{% for type in approach.appointment_types.all %}
{{ type.code }},
{% endfor %}
</td>
<td>
{{ approach.datetime_when | date:"Y-m-d H:i" }}
</td>
<td>
<a
href=
"{% url 'web.views.appointment_edit' approach.id %}"
type=
"button"
class=
"btn btn-block btn-default"
>
Details
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>
No visits approaching in close future.
</p>
{% endif %}
</div>
</div>
<div
class=
"col-md-7"
>
<div
class=
"col-md-7"
>
...
@@ -101,16 +68,32 @@
...
@@ -101,16 +68,32 @@
<script>
<script>
$
(
function
()
{
$
(
function
()
{
$
(
'
#planning_table, #approaching_table
'
).
DataTable
({
var
table
=
$
(
'
#approaching_table
'
).
DataTable
({
"
paging
"
:
true
,
serverSide
:
true
,
"
lengthChange
"
:
false
,
processing
:
true
,
"
searching
"
:
true
,
ordering
:
false
,
"
ordering
"
:
true
,
ajax
:
"
{% url 'web.api.appointments' approaching_list %}
"
,
"
order
"
:
[[
3
,
"
asc
"
]],
columns
:
[
"
info
"
:
true
,
{
"
data
"
:
"
subject
"
},
"
autoWidth
"
:
false
{
"
data
"
:
"
title
"
},
{
"
data
"
:
"
type
"
},
{
"
data
"
:
"
datetime_when
"
},
{
"
data
"
:
null
},
],
columnDefs
:
[{
"
targets
"
:
4
,
"
data
"
:
"
id
"
,
"
defaultContent
"
:
'
<a href="#" type="button" class="btn btn-block btn-default">Edit</a>
'
}]
})
$
(
'
#approaching_table tbody
'
).
on
(
'
click
'
,
'
a
'
,
function
()
{
var
data
=
table
.
row
(
$
(
this
).
parents
(
'
tr
'
)).
data
();
var
url
=
"
{% url 'web.views.appointment_edit' 12345 %}
"
.
replace
(
/12345/
,
data
.
id
.
toString
());
window
.
location
.
href
=
url
;
});
});
$
(
'
#approaching_table_filter
'
).
css
(
"
display
"
,
"
none
"
);
$
(
'
#calendar
'
).
fullCalendar
({
$
(
'
#calendar
'
).
fullCalendar
({
header
:
{
header
:
{
left
:
'
prev,next today
'
,
left
:
'
prev,next today
'
,
...
@@ -119,19 +102,38 @@
...
@@ -119,19 +102,38 @@
},
},
editable
:
false
,
editable
:
false
,
weekNumbers
:
true
,
weekNumbers
:
true
,
events
:
[
startParam
:
"
start_date
"
,
{
%
for
appointment
in
full_list
%
}
endParam
:
"
end_date
"
,
{
events
:
function
(
start
,
end
,
timezone
,
callback
)
{
title
:
'
{{ appointment.title }}
'
,
$
.
ajax
({
start
:
'
{{ appointment.datetime_when | date:"c" }}
'
,
data
:
{
end
:
'
{{ appointment.datetime_until | date:"c" }}
'
,
// our hypothetical feed requires UNIX timestamps
color
:
'
{{ appointment.color }}
'
,
start_date
:
start
.
format
(),
subject_id
:
'
{{ appointment.visit.subject.id }}
'
,
end_date
:
end
.
format
()
id
:
'
{{ appointment.id }}
'
,
url
:
'
{% url
'
web
.
views
.
appointment_edit
'
appointment.id %}
'
,
},
},
{
%
endfor
%
}
url
:
"
{% url 'web.api.appointments' full_list %}
"
,
],
success
:
function
(
doc
)
{
var
events
=
[];
for
(
var
i
=
0
;
i
<
doc
.
data
.
length
;
i
++
)
{
var
title
=
doc
.
data
[
i
].
subject
;
if
(
title
!=
""
)
{
title
+=
"
; type:
"
+
doc
.
data
[
i
].
type
;
}
else
{
title
=
doc
.
data
[
i
].
title
}
events
.
push
({
title
:
title
,
start
:
doc
.
data
[
i
].
datetime_when
,
end
:
doc
.
data
[
i
].
datetime_until
,
id
:
doc
.
data
[
i
].
id
,
color
:
doc
.
data
[
i
].
color
,
url
:
doc
.
data
[
i
].
url
,
})
}
callback
(
events
);
}
});
}
});
});
});
});
</script>
</script>
...
...
This diff is collapsed.
Click to expand it.
smash/web/views/appointment.py
+
2
−
10
View file @
5c8c5992
...
@@ -13,17 +13,9 @@ APPOINTMENT_LIST_APPROACHING = "APPROACHING"
...
@@ -13,17 +13,9 @@ APPOINTMENT_LIST_APPROACHING = "APPROACHING"
def
appointments
(
request
):
def
appointments
(
request
):
approaching_list
=
Appointment
.
objects
.
filter
(
datetime_when__gt
=
get_today_midnight_date
(),
location__in
=
get_filter_locations
(
request
.
user
),
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
order_by
(
'
datetime_when
'
)
full_list
=
get_calendar_full_appointments
(
request
.
user
)
context
=
{
context
=
{
'
approaching_list
'
:
approaching_list
,
'
approaching_list
'
:
APPOINTMENT_LIST_APPROACHING
,
'
full_list
'
:
full_list
'
full_list
'
:
APPOINTMENT_LIST_GENERIC
}
}
return
wrap_response
(
request
,
"
appointments/index.html
"
,
context
)
return
wrap_response
(
request
,
"
appointments/index.html
"
,
context
)
...
...
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