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
dff9a1fd
Commit
dff9a1fd
authored
8 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
refactor on notifications (count of events execute common code with
getting events)
parent
489aebbb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Appointments dev
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/tests/test_view_notifications.py
+43
-0
43 additions, 0 deletions
smash/web/tests/test_view_notifications.py
smash/web/views.py
+42
-52
42 additions, 52 deletions
smash/web/views.py
with
85 additions
and
52 deletions
smash/web/tests/test_view_notifications.py
+
43
−
0
View file @
dff9a1fd
...
@@ -106,3 +106,46 @@ class NotificationViewTests(TestCase):
...
@@ -106,3 +106,46 @@ class NotificationViewTests(TestCase):
notification
=
get_approaching_visits_without_appointments_count
()
notification
=
get_approaching_visits_without_appointments_count
()
self
.
assertEquals
(
original_notification
.
count
+
1
,
notification
.
count
)
self
.
assertEquals
(
original_notification
.
count
+
1
,
notification
.
count
)
def
test_get_subject_with_no_visit_notifications_count
(
self
):
original_notification
=
get_subject_with_no_visit_notifications_count
()
subject
=
create_subject
()
notification
=
get_subject_with_no_visit_notifications_count
()
self
.
assertEquals
(
original_notification
.
count
+
1
,
notification
.
count
)
def
test_get_subject_with_no_visit_notifications_count_2
(
self
):
original_notification
=
get_subject_with_no_visit_notifications_count
()
subject
=
create_subject
()
visit
=
create_visit
(
subject
)
visit
.
is_finished
=
True
visit
.
save
()
notification
=
get_subject_with_no_visit_notifications_count
()
self
.
assertEquals
(
original_notification
.
count
+
1
,
notification
.
count
)
def
test_get_subject_with_no_visit_notifications_count_3
(
self
):
original_notification
=
get_subject_with_no_visit_notifications_count
()
subject
=
create_subject
()
visit
=
create_visit
(
subject
)
notification
=
get_subject_with_no_visit_notifications_count
()
self
.
assertEquals
(
original_notification
.
count
,
notification
.
count
)
def
test_get_subject_with_no_visit_notifications_count_4
(
self
):
original_notification
=
get_subject_with_no_visit_notifications_count
()
subject
=
create_subject
()
subject
.
dead
=
True
subject
.
save
()
notification
=
get_subject_with_no_visit_notifications_count
()
self
.
assertEquals
(
original_notification
.
count
,
notification
.
count
)
def
test_get_subject_with_no_visit_notifications_count_5
(
self
):
original_notification
=
get_subject_with_no_visit_notifications_count
()
subject
=
create_subject
()
subject
.
resigned
=
True
subject
.
save
()
notification
=
get_subject_with_no_visit_notifications_count
()
self
.
assertEquals
(
original_notification
.
count
,
notification
.
count
)
This diff is collapsed.
Click to expand it.
smash/web/views.py
+
42
−
52
View file @
dff9a1fd
...
@@ -12,6 +12,9 @@ from django.shortcuts import render
...
@@ -12,6 +12,9 @@ from django.shortcuts import render
from
django.db.models
import
Q
from
django.db.models
import
Q
import
collections
import
collections
import
datetime
import
datetime
from
django.db.models
import
Count
from
django.db.models
import
Case
from
django.db.models
import
When
# See https://docs.djangoproject.com/en/1.10/topics/http/views/#customizing-error-views
# See https://docs.djangoproject.com/en/1.10/topics/http/views/#customizing-error-views
# They should work ONLY in production! (DEBUG=False)
# They should work ONLY in production! (DEBUG=False)
...
@@ -68,77 +71,63 @@ class NotificationCount(object):
...
@@ -68,77 +71,63 @@ class NotificationCount(object):
self
.
style
=
style
self
.
style
=
style
self
.
type
=
type
self
.
type
=
type
def
get_exceeded_visits
():
return
Visit
.
objects
.
filter
(
datetime_end__lt
=
get_today_midnight_date
(),
is_finished
=
False
).
order_by
(
'
datetime_begin
'
)
def
get_exceeded_visit_notifications_count
():
def
get_exceeded_visit_notifications_count
():
notification
=
NotificationCount
(
"
exceeded visit time
"
,
0
,
"
fa fa-thermometer-4 text-red
"
,
'
web.views.exceeded_visits
'
)
notification
=
NotificationCount
(
today
=
get_today_midnight_date
()
title
=
"
exceeded visit time
"
,
count
=
Visit
.
objects
.
filter
(
datetime_end__lt
=
today
,
is_finished
=
False
).
count
()
count
=
get_exceeded_visits
().
count
(),
notification
.
count
=
count
style
=
"
fa fa-thermometer-4 text-red
"
,
type
=
'
web.views.exceeded_visits
'
)
return
notification
def
get_subjects_with_no_visit
():
return
Subject
.
objects
.
annotate
(
my_count
=
Count
(
Case
(
When
(
visit__is_finished
=
False
,
then
=
1
)))).
filter
(
dead
=
False
,
resigned
=
False
,
my_count
=
0
)
def
get_subject_with_no_visit_notifications_count
():
notification
=
NotificationCount
(
title
=
"
subject without visit
"
,
count
=
get_subjects_with_no_visit
().
count
(),
style
=
"
fa fa-users text-aqua
"
,
type
=
'
web.views.subject_no_visits
'
)
return
notification
return
notification
def
get_exceeded_visits
():
return
Visit
.
objects
.
filter
(
datetime_end__lt
=
get_today_midnight_date
(),
is_finished
=
False
).
order_by
(
'
datetime_begin
'
)
def
get_visits_without_appointments_count
():
def
get_visits_without_appointments_count
():
notification
=
NotificationCount
(
"
unfinished visits
"
,
0
,
"
fa fa-user-times text-yellow
"
,
'
web.views.unfinished_visits
'
)
notification
=
NotificationCount
(
today
=
get_today_midnight_date
()
title
=
"
unfinished visits
"
,
count
=
0
count
=
get_unfinished_visits
().
count
(),
#visits in progress
style
=
"
fa fa-user-times text-yellow
"
,
visits
=
Visit
.
objects
.
filter
(
datetime_begin__lt
=
today
,
datetime_end__gt
=
today
,
is_finished
=
False
)
type
=
'
web.views.unfinished_visits
'
)
for
visit
in
visits
:
app_count
=
Appointment
.
objects
.
filter
(
visit
=
visit
,
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
count
()
if
app_count
==
0
:
count
+=
1
notification
.
count
=
count
return
notification
return
notification
def
get_unfinished_visits
():
def
get_unfinished_visits
():
today
=
get_today_midnight_date
()
today
=
get_today_midnight_date
()
result
=
[];
#list visits that have no scheduled appointments and taking place now
#visits in progress
return
Visit
.
objects
.
annotate
(
my_count
=
Count
(
Case
(
When
(
appointment__status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
,
then
=
1
)))).
filter
(
datetime_begin__lt
=
today
,
datetime_end__gt
=
today
,
is_finished
=
False
,
my_count
=
0
)
visits
=
Visit
.
objects
.
filter
(
datetime_begin__lt
=
today
,
datetime_end__gt
=
today
,
is_finished
=
False
)
for
visit
in
visits
:
app_count
=
Appointment
.
objects
.
filter
(
visit
=
visit
,
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
count
()
if
app_count
==
0
:
result
.
append
(
visit
)
return
result
def
get_approaching_visits_without_appointments_count
():
def
get_approaching_visits_without_appointments_count
():
notification
=
NotificationCount
(
"
approaching visits
"
,
0
,
"
fa fa-users text-aqua
"
,
'
web.views.approaching_visits_without_appointments
'
)
notification
=
NotificationCount
(
today
=
get_today_midnight_date
()
title
=
"
approaching visits
"
,
today_plus_two_months
=
today
+
datetime
.
timedelta
(
days
=
62
)
count
=
get_approaching_visits_without_appointments
().
count
(),
count
=
0
style
=
"
fa fa-users text-aqua
"
,
#visits in near future (2 months)
type
=
'
web.views.approaching_visits_without_appointments
'
)
visits
=
Visit
.
objects
.
filter
(
datetime_begin__gt
=
today
,
datetime_begin__lt
=
today_plus_two_months
,
is_finished
=
False
)
for
visit
in
visits
:
app_count
=
Appointment
.
objects
.
filter
(
visit
=
visit
,
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
count
()
if
app_count
==
0
:
count
+=
1
notification
.
count
=
count
return
notification
return
notification
def
get_approaching_visits_without_appointments
():
def
get_approaching_visits_without_appointments
():
today
=
get_today_midnight_date
()
today
=
get_today_midnight_date
()
today_plus_two_months
=
today
+
datetime
.
timedelta
(
days
=
62
)
today_plus_two_months
=
today
+
datetime
.
timedelta
(
days
=
62
)
result
=
[];
return
Visit
.
objects
.
annotate
(
my_count
=
Count
(
Case
(
When
(
appointment__status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
,
then
=
1
)))).
filter
(
datetime_begin__gt
=
today
,
datetime_begin__lt
=
today_plus_two_months
,
is_finished
=
False
,
my_count
=
0
)
#visits in progress
visits
=
Visit
.
objects
.
filter
(
datetime_begin__gt
=
today
,
datetime_begin__lt
=
today_plus_two_months
,
is_finished
=
False
)
for
visit
in
visits
:
app_count
=
Appointment
.
objects
.
filter
(
visit
=
visit
,
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
count
()
if
app_count
==
0
:
result
.
append
(
visit
)
return
result
def
get_unfinished_appointments_count
():
def
get_unfinished_appointments_count
():
notification
=
NotificationCount
(
"
unfinished appointments
"
,
0
,
"
fa fa-history text-yellow
"
,
'
web.views.unfinished_appointments
'
)
return
NotificationCount
(
today
=
get_today_midnight_date
()
title
=
"
unfinished appointments
"
,
count
=
get_unfinished_appointments
(),
count
=
Appointment
.
objects
.
filter
(
datetime_when__lt
=
today
,
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
).
count
()
style
=
"
fa fa-history text-yellow
"
,
type
=
'
web.views.unfinished_appointments
'
)
notification
.
count
=
count
return
notification
def
get_unfinished_appointments
():
def
get_unfinished_appointments
():
return
Appointment
.
objects
.
filter
(
datetime_when__lt
=
get_today_midnight_date
(),
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
)
return
Appointment
.
objects
.
filter
(
datetime_when__lt
=
get_today_midnight_date
(),
status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
)
...
@@ -154,6 +143,7 @@ def get_notifications(the_user):
...
@@ -154,6 +143,7 @@ def get_notifications(the_user):
notifications
.
append
(
get_visits_without_appointments_count
())
notifications
.
append
(
get_visits_without_appointments_count
())
notifications
.
append
(
get_approaching_visits_without_appointments_count
())
notifications
.
append
(
get_approaching_visits_without_appointments_count
())
notifications
.
append
(
get_unfinished_appointments_count
())
notifications
.
append
(
get_unfinished_appointments_count
())
notifications
.
append
(
get_subject_with_no_visit_notifications_count
())
for
notification
in
notifications
:
for
notification
in
notifications
:
count
+=
notification
.
count
count
+=
notification
.
count
return
(
count
,
notifications
)
return
(
count
,
notifications
)
...
...
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