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
c25748b7
Commit
c25748b7
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
counting of notification is done via django model query
parent
57d5b3ab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!107
Resolve "exceeded visits list & unfinished visits list"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/tests/view/test_notifications.py
+1
-1
1 addition, 1 deletion
smash/web/tests/view/test_notifications.py
smash/web/views/notifications.py
+17
-14
17 additions, 14 deletions
smash/web/views/notifications.py
with
18 additions
and
15 deletions
smash/web/tests/view/test_notifications.py
+
1
−
1
View file @
c25748b7
...
@@ -144,7 +144,7 @@ class NotificationViewTests(LoggedInTestCase):
...
@@ -144,7 +144,7 @@ class NotificationViewTests(LoggedInTestCase):
visit
.
save
()
visit
.
save
()
visits
=
get_unfinished_visits
(
self
.
user
)
visits
=
get_unfinished_visits
(
self
.
user
)
self
.
assertEquals
(
3
,
len
(
visits
))
self
.
assertEquals
(
3
,
visits
.
count
(
))
# check sort order
# check sort order
self
.
assertTrue
(
visits
[
0
].
datetime_begin
<
visits
[
1
].
datetime_begin
)
self
.
assertTrue
(
visits
[
0
].
datetime_begin
<
visits
[
1
].
datetime_begin
)
...
...
This diff is collapsed.
Click to expand it.
smash/web/views/notifications.py
+
17
−
14
View file @
c25748b7
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
datetime
import
datetime
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.db.models
import
Count
,
Case
,
When
from
django.db.models
import
Count
,
Case
,
When
,
Q
,
F
from
django.utils
import
timezone
from
django.utils
import
timezone
from
web.models
import
Study
from
web.models
import
Study
...
@@ -71,7 +71,7 @@ def get_subject_with_no_visit_notifications_count(user):
...
@@ -71,7 +71,7 @@ def get_subject_with_no_visit_notifications_count(user):
def
get_visits_without_appointments_count
(
user
):
def
get_visits_without_appointments_count
(
user
):
notification
=
NotificationCount
(
notification
=
NotificationCount
(
title
=
"
unfinished visits
"
,
title
=
"
unfinished visits
"
,
count
=
len
(
get_unfinished_visits
(
user
)),
count
=
get_unfinished_visits
(
user
)
.
count
(
),
style
=
"
fa fa-user-times text-yellow
"
,
style
=
"
fa fa-user-times text-yellow
"
,
type
=
'
web.views.unfinished_visits
'
)
type
=
'
web.views.unfinished_visits
'
)
return
notification
return
notification
...
@@ -80,7 +80,7 @@ def get_visits_without_appointments_count(user):
...
@@ -80,7 +80,7 @@ def get_visits_without_appointments_count(user):
def
get_visits_with_missing_appointments_count
(
user
):
def
get_visits_with_missing_appointments_count
(
user
):
notification
=
NotificationCount
(
notification
=
NotificationCount
(
title
=
"
visits with missing appointments
"
,
title
=
"
visits with missing appointments
"
,
count
=
len
(
get_active_visits_with_missing_appointments
(
user
)),
count
=
get_active_visits_with_missing_appointments
(
user
)
.
count
(
),
style
=
"
fa fa-user-times text-yellow
"
,
style
=
"
fa fa-user-times text-yellow
"
,
type
=
'
web.views.visits_with_missing_appointments
'
)
type
=
'
web.views.visits_with_missing_appointments
'
)
return
notification
return
notification
...
@@ -169,19 +169,13 @@ def get_subjects_with_reminder(user):
...
@@ -169,19 +169,13 @@ def get_subjects_with_reminder(user):
def
get_active_visits_with_missing_appointments
(
user
):
def
get_active_visits_with_missing_appointments
(
user
):
result
=
[]
visits_without_appointments
=
get_active_visits_without_appointments
(
user
)
for
visit
in
get_active_visits_without_appointments
(
user
):
return
visits_without_appointments
.
filter
(
types_in_system_count__lt
=
F
(
"
types_expected_in_system_count
"
))
if
waiting_for_appointment
(
visit
):
result
.
append
(
visit
)
return
result
def
get_unfinished_visits
(
user
):
def
get_unfinished_visits
(
user
):
result
=
[]
visits_without_appointments
=
get_active_visits_without_appointments
(
user
)
for
visit
in
get_active_visits_without_appointments
(
user
):
return
visits_without_appointments
.
filter
(
types_in_system_count__gte
=
F
(
"
types_expected_in_system_count
"
))
if
not
waiting_for_appointment
(
visit
):
result
.
append
(
visit
)
return
result
def
get_approaching_visits_without_appointments
(
user
):
def
get_approaching_visits_without_appointments
(
user
):
...
@@ -259,7 +253,16 @@ def get_active_visits_without_appointments(user):
...
@@ -259,7 +253,16 @@ def get_active_visits_without_appointments(user):
datetime_end__gt
=
today
,
datetime_end__gt
=
today
,
is_finished
=
False
,
is_finished
=
False
,
subject__default_location__in
=
get_filter_locations
(
user
),
subject__default_location__in
=
get_filter_locations
(
user
),
my_count
=
0
).
order_by
(
'
datetime_begin
'
)
my_count
=
0
).
order_by
(
'
datetime_begin
'
).
annotate
(
# types_in_system_count annotation counts how many different appointment types were scheduled or already
# performed
types_in_system_count
=
Count
(
Case
(
When
(
Q
(
appointment__status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
)
|
Q
(
appointment__status
=
Appointment
.
APPOINTMENT_STATUS_FINISHED
)
,
then
=
"
appointment__appointment_types
"
)),
distinct
=
True
)).
annotate
(
# types_expected_in_system_count annotation counts how many different appointment types should be performed in
# the visit
types_expected_in_system_count
=
Count
(
'
appointment_types
'
,
distinct
=
True
))
def
get_filter_locations
(
user
):
def
get_filter_locations
(
user
):
...
...
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