Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
elixir
daisy
Commits
8a4d284c
Commit
8a4d284c
authored
Sep 16, 2021
by
Jacek Lebioda
Browse files
feat: finding issues
parent
9c8c6c3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
17 deletions
+91
-17
core/issues.py
core/issues.py
+76
-0
core/reporting.py
core/reporting.py
+15
-17
No files found.
core/issues.py
0 → 100644
View file @
8a4d284c
from
typing
import
List
from
django.urls
import
reverse
from
core.models.data_declaration
import
DataDeclaration
from
core.models.project
import
Project
from
core.models.dataset
import
Dataset
class
Issue
:
def
__init__
(
self
,
url
:
str
,
code
:
str
,
description
:
str
,
object_title
:
str
)
->
None
:
self
.
url
=
url
self
.
object_title
=
object_title
self
.
description
=
description
self
.
code
=
code
def
find_issues_in_dataset
(
dataset
:
Dataset
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'dataset'
,
args
=
[
str
(
dataset
.
id
)])
if
dataset
.
legal_basis_definitions
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[D-1]'
,
'Missing legal bases for a dataset'
,
dataset
.
title
))
if
dataset
.
data_declarations
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[D-2]'
,
'No data declarations for a dataset'
,
dataset
.
title
))
if
dataset
.
data_locations
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[D-3]'
,
'No storage locations for a dataset'
,
dataset
.
title
))
if
dataset
.
accesses
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[D-4]'
,
'No accesses specified for a dataset'
,
dataset
.
title
))
return
issues
def
find_issues_in_project
(
project
:
Project
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'project'
,
args
=
[
str
(
project
.
id
)])
if
project
.
datasets
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[P-1]'
,
'No dataset in a project'
,
project
.
acronym
))
if
project
.
has_erp
==
False
:
issues
.
append
(
Issue
(
url
,
'[P-2]'
,
'No ERP in project'
,
project
.
acronym
))
if
project
.
has_erp
and
len
(
project
.
erp_notes
)
==
0
:
issues
.
append
(
Issue
(
url
,
'[P-3]'
,
'Empty ERP notes'
,
project
.
acronym
))
return
issues
def
find_issues_in_datadeclaration
(
data_declaration
:
DataDeclaration
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'data_declaration'
,
args
=
[
str
(
data_declaration
.
id
)])
# TODO:
return
issues
def
_accumulate_results
(
objects
,
func
):
results
=
[]
for
obj
in
objects
:
results
=
results
+
func
(
obj
)
return
results
def
find_issues_in_datasets
(
datasets
:
List
[
Dataset
])
->
List
[
Issue
]:
return
_accumulate_results
(
datasets
,
find_issues_in_dataset
)
def
find_issues_in_projects
(
projects
:
List
[
Project
])
->
List
[
Issue
]:
return
_accumulate_results
(
projects
,
find_issues_in_project
)
def
find_issues_in_datadeclarations
(
data_declarations
:
List
[
DataDeclaration
])
->
List
[
Issue
]:
return
_accumulate_results
(
data_declarations
,
find_issues_in_datadeclaration
)
core/reporting.py
View file @
8a4d284c
...
...
@@ -8,6 +8,7 @@ from django.db.models.query import QuerySet
from
django.db.models.manager
import
Manager
from
django.template.loader
import
render_to_string
from
core.issues
import
Issue
,
find_issues_in_datadeclarations
,
find_issues_in_datasets
,
find_issues_in_projects
from
core.models.dataset
import
Dataset
from
core.models.data_declaration
import
DataDeclaration
from
core.models.project
import
Project
...
...
@@ -39,19 +40,17 @@ def cast_to_queryset(object: Union[Model, List[Model], QuerySet], klass: Type =
return
object
.
all
()
class_name
=
object
.
__class__
.
__name__
raise
TypeError
(
f
'Unrecognised class:
{
class_name
}
!'
)
class
Issue
:
def
__init__
(
self
,
url
:
str
,
code
:
str
,
description
:
str
,
object_title
:
str
)
->
None
:
self
.
url
=
url
self
.
object_title
=
object_title
self
.
description
=
description
self
.
code
=
code
def
cast_to_issue_list
(
object
:
Union
[
Issue
,
List
[
Issue
]])
->
List
[
Issue
]:
if
object
is
None
:
return
None
if
type
(
object
)
==
Issue
:
return
[
object
]
if
type
(
object
)
==
list
:
return
object
class_name
=
object
.
__class__
.
__name__
raise
TypeError
(
f
'Unrecognised class:
{
class_name
}
!'
)
class
ReportParameters
:
"""
...
...
@@ -62,8 +61,8 @@ class ReportParameters:
projects
:
Union
[
Project
,
List
[
Project
],
QuerySet
]
=
None
,
datasets
:
Union
[
Dataset
,
List
[
Dataset
],
QuerySet
]
=
None
,
data_declarations
:
Union
[
DataDeclaration
,
List
[
DataDeclaration
],
QuerySet
]
=
None
,
issues
:
Union
[
Issue
,
List
[
Issue
]
,
QuerySet
]
=
None
)
->
None
:
self
.
issues
=
cast_to_
queryse
t
(
issues
,
Issue
)
issues
:
Union
[
Issue
,
List
[
Issue
]]
=
None
)
->
None
:
self
.
issues
=
cast_to_
issue_lis
t
(
issues
)
self
.
datasets
=
cast_to_queryset
(
datasets
,
Dataset
)
self
.
data_declarations
=
cast_to_queryset
(
data_declarations
,
DataDeclaration
)
self
.
projects
=
cast_to_queryset
(
projects
,
Project
)
...
...
@@ -91,9 +90,8 @@ class ReportParametersCollector:
data_declarations_with_repetitions
=
reduce
(
concat
,
data_declarations_list
)
data_declarations
=
list
(
set
(
data_declarations_with_repetitions
))
# TODO: Generate Issues
issues
=
None
issues
=
find_issues_in_projects
(
projects
)
+
find_issues_in_datasets
(
datasets
)
+
find_issues_in_datadeclarations
(
data_declarations
)
return
ReportParameters
(
projects
,
datasets
,
data_declarations
,
issues
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment