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
51a66173
Commit
51a66173
authored
3 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
indentation
parent
1ffa87f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!336
Pylint checks
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/api_views/worker.py
+13
-10
13 additions, 10 deletions
smash/web/api_views/worker.py
with
13 additions
and
10 deletions
smash/web/api_views/worker.py
+
13
−
10
View file @
51a66173
...
...
@@ -122,10 +122,10 @@ def serialize_worker(worker):
return
result
def
add_worker_availability
(
request
,
worker_id
,
weekday
,
start_hour
,
end_hour
):
if
worker_id
is
None
or
weekday
is
None
or
start_hour
is
None
or
end_hour
is
None
:
context
=
{
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either worker_id, weekday, start_hour, end_hour or all of them are invalid.
'
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either worker_id, weekday, start_hour, end_hour or all of them are invalid.
'
}
response
=
HttpResponse
(
json
.
dumps
(
context
),
content_type
=
'
application/json
'
)
response
.
status_code
=
400
...
...
@@ -133,17 +133,17 @@ def add_worker_availability(request, worker_id, weekday, start_hour, end_hour):
worker
=
get_object_or_404
(
Worker
,
id
=
int
(
worker_id
))
availability
,
_
=
Availability
.
objects
.
update_or_create
(
person
=
worker
,
day_number
=
weekday
,
availability
,
_
=
Availability
.
objects
.
update_or_create
(
person
=
worker
,
day_number
=
weekday
,
defaults
=
{
'
available_from
'
:
start_hour
,
'
available_till
'
:
end_hour
})
availability
.
save
()
return
JsonResponse
({},
status
=
200
)
return
JsonResponse
({},
status
=
200
)
def
add_worker_extra_availability
(
request
,
worker_id
,
start_str_date
,
end_str_date
):
if
start_str_date
is
None
or
end_str_date
is
None
or
worker_id
is
None
:
context
=
{
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either start_date, end_str_date, worker_id or all of them are invalid.
'
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either start_date, end_str_date, worker_id or all of them are invalid.
'
}
response
=
HttpResponse
(
json
.
dumps
(
context
),
content_type
=
'
application/json
'
)
response
.
status_code
=
400
...
...
@@ -153,7 +153,10 @@ def add_worker_extra_availability(request, worker_id, start_str_date, end_str_da
end_date
=
datetime
.
datetime
.
strptime
(
end_str_date
,
"
%Y-%m-%d-%H-%M
"
).
replace
(
tzinfo
=
timezone
.
now
().
tzinfo
)
worker
=
get_object_or_404
(
Worker
,
id
=
int
(
worker_id
))
extra_availability
,
_
=
Holiday
.
objects
.
update_or_create
(
person
=
worker
,
datetime_start
=
start_date
,
datetime_end
=
end_date
,
kind
=
AVAILABILITY_EXTRA
)
extra_availability
,
_
=
Holiday
.
objects
.
update_or_create
(
person
=
worker
,
datetime_start
=
start_date
,
datetime_end
=
end_date
,
kind
=
AVAILABILITY_EXTRA
)
extra_availability
.
save
()
return
JsonResponse
({},
status
=
200
)
...
...
@@ -162,10 +165,10 @@ def get_worker_availability(request):
start_str_date
=
request
.
GET
.
get
(
"
start_date
"
)
end_str_date
=
request
.
GET
.
get
(
"
end_date
"
)
worker_id
=
request
.
GET
.
get
(
"
worker_id
"
)
if
start_str_date
is
None
or
worker_id
is
None
:
context
=
{
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either start_date, worker_id or both are invalid.
'
'
status
'
:
'
400
'
,
'
reason
'
:
'
Either start_date, worker_id or both are invalid.
'
}
response
=
HttpResponse
(
json
.
dumps
(
context
),
content_type
=
'
application/json
'
)
response
.
status_code
=
400
...
...
@@ -181,7 +184,7 @@ def get_worker_availability(request):
result
=
{
'
start_date
'
:
start_date
,
'
end_date
'
:
end_date
,
'
end_date
'
:
end_date
,
'
availability
'
:
round
(
worker
.
availability_percentage
(
start_date
=
start_date
,
end_date
=
end_date
),
0
)
}
return
JsonResponse
(
result
)
\ No newline at end of file
return
JsonResponse
(
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