Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
geant-swd
compendium-v2
Commits
34163d9a
Commit
34163d9a
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
add /api/staff endpoint for NREN staff data
parent
9b003ce9
No related branches found
No related tags found
1 merge request
!6
Feature/comp 125 staffing graph
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/routes/api.py
+3
-1
3 additions, 1 deletion
compendium_v2/routes/api.py
compendium_v2/routes/staff.py
+73
-0
73 additions, 0 deletions
compendium_v2/routes/staff.py
with
76 additions
and
1 deletion
compendium_v2/routes/api.py
+
3
−
1
View file @
34163d9a
...
@@ -4,7 +4,7 @@ API Endpoints
...
@@ -4,7 +4,7 @@ API Endpoints
.. contents:: :local:
.. contents:: :local:
/api/
data-entries/
/api/
---------------------
---------------------
...
@@ -18,11 +18,13 @@ from compendium_v2.routes import common
...
@@ -18,11 +18,13 @@ from compendium_v2.routes import common
from
compendium_v2.routes.budget
import
routes
as
budget_routes
from
compendium_v2.routes.budget
import
routes
as
budget_routes
from
compendium_v2.routes.funding
import
routes
as
funding_routes
from
compendium_v2.routes.funding
import
routes
as
funding_routes
from
compendium_v2.routes.charging
import
routes
as
charging_routes
from
compendium_v2.routes.charging
import
routes
as
charging_routes
from
compendium_v2.routes.staff
import
routes
as
staff_routes
routes
=
Blueprint
(
'
compendium-v2-api
'
,
__name__
)
routes
=
Blueprint
(
'
compendium-v2-api
'
,
__name__
)
routes
.
register_blueprint
(
budget_routes
,
url_prefix
=
'
/budget
'
)
routes
.
register_blueprint
(
budget_routes
,
url_prefix
=
'
/budget
'
)
routes
.
register_blueprint
(
funding_routes
,
url_prefix
=
'
/funding
'
)
routes
.
register_blueprint
(
funding_routes
,
url_prefix
=
'
/funding
'
)
routes
.
register_blueprint
(
charging_routes
,
url_prefix
=
'
/charging
'
)
routes
.
register_blueprint
(
charging_routes
,
url_prefix
=
'
/charging
'
)
routes
.
register_blueprint
(
staff_routes
,
url_prefix
=
'
/staff
'
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/routes/staff.py
0 → 100644
+
73
−
0
View file @
34163d9a
import
logging
from
flask
import
Blueprint
,
jsonify
,
current_app
from
compendium_v2
import
db
from
compendium_v2.routes
import
common
from
compendium_v2.db
import
model
from
typing
import
Any
routes
=
Blueprint
(
'
staff
'
,
__name__
)
@routes.before_request
def
before_request
():
config
=
current_app
.
config
[
'
CONFIG_PARAMS
'
]
dsn_prn
=
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
db
.
init_db_model
(
dsn_prn
)
logger
=
logging
.
getLogger
(
__name__
)
STAFF_RESPONSE_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
definitions
'
:
{
'
staff
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
nren
'
:
{
'
type
'
:
'
string
'
},
'
year
'
:
{
'
type
'
:
'
integer
'
},
'
permanent_fte
'
:
{
'
type
'
:
'
number
'
},
'
subcontracted_fte
'
:
{
'
type
'
:
'
number
'
},
'
technical_fte
'
:
{
'
type
'
:
'
number
'
},
'
non_technical_fte
'
:
{
'
type
'
:
'
number
'
}
},
'
required
'
:
[
'
nren
'
,
'
year
'
,
'
permanent_fte
'
,
'
subcontracted_fte
'
,
'
technical_fte
'
,
'
non_technical_fte
'
],
'
additionalProperties
'
:
False
}
},
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/staff
'
}
}
@routes.route
(
'
/
'
,
methods
=
[
'
GET
'
])
@common.require_accepts_json
def
staff_view
()
->
Any
:
"""
handler for /api/staff/ requests
response will be formatted as:
.. asjson::
compendium_v2.routes.staff.STAFF_RESPONSE_SCHEMA
:return:
"""
def
_extract_data
(
entry
:
model
.
NrenStaff
):
return
{
'
nren
'
:
entry
.
nren
.
name
,
'
year
'
:
entry
.
year
,
'
permanent_fte
'
:
entry
.
permanent_fte
,
'
subcontracted_fte
'
:
entry
.
subcontracted_fte
,
'
technical_fte
'
:
entry
.
technical_fte
,
'
non_technical_fte
'
:
entry
.
non_technical_fte
}
with
db
.
session_scope
()
as
session
:
entries
=
[
_extract_data
(
entry
)
for
entry
in
session
.
query
(
model
.
NrenStaff
).
join
(
model
.
NREN
).
order_by
(
model
.
NREN
.
name
.
asc
(),
model
.
NrenStaff
.
year
.
desc
())]
return
jsonify
(
entries
)
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