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
487f1e8f
Commit
487f1e8f
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
common serialize date methods extracted
parent
fda6f41e
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
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/api_views/serialization_utils.py
+16
-0
16 additions, 0 deletions
smash/web/api_views/serialization_utils.py
smash/web/api_views/subject.py
+7
-8
7 additions, 8 deletions
smash/web/api_views/subject.py
smash/web/api_views/visit.py
+4
-14
4 additions, 14 deletions
smash/web/api_views/visit.py
with
27 additions
and
22 deletions
smash/web/api_views/serialization_utils.py
+
16
−
0
View file @
487f1e8f
...
...
@@ -24,6 +24,22 @@ def location_to_str(location):
return
result
def
serialize_date
(
date
):
if
date
is
not
None
:
result
=
date
.
strftime
(
'
%Y-%m-%d
'
)
else
:
result
=
""
return
result
def
serialize_datetime
(
date
):
if
date
is
not
None
:
result
=
date
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
else
:
result
=
""
return
result
def
add_column
(
result
,
name
,
field_name
,
column_list
,
param
,
columns_used_in_study
=
None
,
visible_param
=
None
,
sortable
=
True
):
add
=
True
...
...
This diff is collapsed.
Click to expand it.
smash/web/api_views/subject.py
+
7
−
8
View file @
487f1e8f
...
...
@@ -5,7 +5,8 @@ from django.db.models import Count, Case, When, Min, Max
from
django.db.models
import
Q
from
django.http
import
JsonResponse
from
web.api_views.serialization_utils
import
bool_to_yes_no
,
flying_team_to_str
,
location_to_str
,
add_column
from
web.api_views.serialization_utils
import
bool_to_yes_no
,
flying_team_to_str
,
location_to_str
,
add_column
,
\
serialize_date
,
serialize_datetime
from
web.models
import
StudySubject
,
Visit
,
Appointment
,
Subject
,
SubjectColumns
,
StudyColumns
,
Study
,
ContactAttempt
from
web.models.constants
import
SUBJECT_TYPE_CHOICES
,
GLOBAL_STUDY_ID
from
web.models.study_subject_list
import
SUBJECT_LIST_GENERIC
,
SUBJECT_LIST_NO_VISIT
,
SUBJECT_LIST_REQUIRE_CONTACT
,
\
...
...
@@ -330,17 +331,15 @@ def serialize_subject(study_subject):
status
=
"
UPCOMING
"
serialized_visits
.
append
({
"
status
"
:
status
,
"
datetime_start
"
:
visit
.
datetime_begin
.
strftime
(
'
%Y-%m-%d
'
),
"
datetime_end
"
:
visit
.
datetime_end
.
strftime
(
'
%Y-%m-%d
'
),
"
datetime_start
"
:
serialize_date
(
visit
.
datetime_begin
),
"
datetime_end
"
:
serialize_date
(
visit
.
datetime_end
),
})
contact_reminder
=
study_subject
.
datetime_contact_reminder
if
contact_reminder
is
not
None
:
contact_reminder
=
contact_reminder
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
contact_reminder
=
serialize_datetime
(
study_subject
.
datetime_contact_reminder
)
contact_attempts
=
ContactAttempt
.
objects
.
filter
(
subject
=
study_subject
).
order_by
(
"
-datetime_when
"
)
if
len
(
contact_attempts
)
>
0
:
last_contact_attempt
=
contact_attempts
[
0
]
last_contact_attempt_string
=
last_contact_attempt
.
datetime_when
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
+
"
<br/>
"
+
str
(
last_contact_attempt
.
worker
)
+
"
<br/> Success:
"
+
bool_to_yes_no
(
last_contact_attempt_string
=
serialize_datetime
(
last_contact_attempt
.
datetime_when
)
+
"
<br/>
"
+
str
(
last_contact_attempt
.
worker
)
+
"
<br/> Success:
"
+
bool_to_yes_no
(
last_contact_attempt
.
success
)
+
"
<br/>
"
+
last_contact_attempt
.
comment
else
:
...
...
This diff is collapsed.
Click to expand it.
smash/web/api_views/visit.py
+
4
−
14
View file @
487f1e8f
...
...
@@ -4,7 +4,8 @@ from django.contrib.auth.decorators import login_required
from
django.db.models
import
Q
from
django.http
import
JsonResponse
from
web.api_views.serialization_utils
import
bool_to_yes_no
,
flying_team_to_str
,
location_to_str
,
add_column
from
web.api_views.serialization_utils
import
bool_to_yes_no
,
flying_team_to_str
,
location_to_str
,
add_column
,
\
serialize_date
from
web.models
import
AppointmentType
,
Appointment
from
web.models
import
SubjectColumns
from
web.models
import
Visit
,
Study
,
VisitColumns
,
StudyVisitList
,
StudyColumns
...
...
@@ -221,9 +222,6 @@ def appointment_types_to_str(appointment_types):
def
serialize_visit
(
visit
):
datetime_begin
=
serialize_date
(
visit
.
datetime_begin
)
datetime_end
=
serialize_date
(
visit
.
datetime_end
)
appointment_types
=
visit
.
appointment_types
.
all
()
appointment_types_in_progress
=
AppointmentType
.
objects
.
filter
(
Q
(
appointmenttypelink__appointment__visit
=
visit
)
&
Q
(
appointmenttypelink__appointment__status
=
Appointment
.
APPOINTMENT_STATUS_SCHEDULED
)).
distinct
().
all
()
...
...
@@ -239,8 +237,8 @@ def serialize_visit(visit):
result
=
{
"
first_name
"
:
visit
.
subject
.
subject
.
first_name
,
"
last_name
"
:
visit
.
subject
.
subject
.
last_name
,
"
datetime_begin
"
:
datetime_begin
,
"
datetime_end
"
:
datetime_end
,
"
datetime_begin
"
:
serialize_date
(
visit
.
datetime_begin
)
,
"
datetime_end
"
:
serialize_date
(
visit
.
datetime_end
)
,
"
flying_team
"
:
flying_team_to_str
(
visit
.
subject
.
flying_team
),
"
default_location
"
:
location_to_str
(
visit
.
subject
.
default_location
),
"
is_finished
"
:
bool_to_yes_no
(
visit
.
is_finished
),
...
...
@@ -254,11 +252,3 @@ def serialize_visit(visit):
}
return
result
def
serialize_date
(
date
):
if
date
is
not
None
:
result
=
date
.
strftime
(
'
%Y-%m-%d
'
)
else
:
result
=
""
return
result
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