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
668cf45e
Commit
668cf45e
authored
Sep 18, 2021
by
Jacek Lebioda
Browse files
feat: use absolute uri in reports
parent
ac943c94
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
8 deletions
+33
-8
core/issues.py
core/issues.py
+8
-4
core/templates/report_email.html
core/templates/report_email.html
+1
-1
core/templates/report_email.txt
core/templates/report_email.txt
+1
-1
core/tests/email_reporter/test_reporter.py
core/tests/email_reporter/test_reporter.py
+11
-2
core/utils.py
core/utils.py
+12
-0
No files found.
core/issues.py
View file @
668cf45e
...
...
@@ -5,6 +5,7 @@ from django.urls import reverse
from
core.models.data_declaration
import
DataDeclaration
from
core.models.project
import
Project
from
core.models.dataset
import
Dataset
from
core.utils
import
get_absolute_uri
class
Issue
:
...
...
@@ -21,8 +22,9 @@ class Issue:
def
find_issues_in_dataset
(
dataset
:
Dataset
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'dataset'
,
args
=
[
str
(
dataset
.
id
)])
local_url
=
reverse
(
'dataset'
,
args
=
[
str
(
dataset
.
id
)])
url
=
get_absolute_uri
(
local_url
)
if
dataset
.
legal_basis_definitions
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[D-1]'
,
'Missing legal bases for a dataset'
,
dataset
.
title
))
...
...
@@ -39,7 +41,8 @@ def find_issues_in_dataset(dataset: Dataset) -> List[Issue]:
def
find_issues_in_project
(
project
:
Project
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'project'
,
args
=
[
str
(
project
.
id
)])
local_url
=
reverse
(
'project'
,
args
=
[
str
(
project
.
id
)])
url
=
get_absolute_uri
(
local_url
)
if
project
.
datasets
.
count
()
==
0
:
issues
.
append
(
Issue
(
url
,
'[P-1]'
,
'No dataset in a project'
,
project
.
acronym
))
...
...
@@ -54,7 +57,8 @@ def find_issues_in_project(project: Project) -> List[Issue]:
def
find_issues_in_datadeclaration
(
data_declaration
:
DataDeclaration
)
->
List
[
Issue
]:
issues
=
[]
url
=
reverse
(
'data_declaration'
,
args
=
[
str
(
data_declaration
.
id
)])
local_url
=
reverse
(
'data_declaration'
,
args
=
[
str
(
data_declaration
.
id
)])
url
=
get_absolute_uri
(
local_url
)
# TODO:
...
...
core/templates/report_email.html
View file @
668cf45e
...
...
@@ -108,7 +108,7 @@
</table>
{% endfor %}
{% if issues %}
{% if issues
|length > 0
%}
<table
border=
"0"
cellspacing=
"0"
cellpadding=
"0"
style=
"table-layout: fixed;font-family: 'Roboto','Helvetica','Arial',sans-serif;
font-weight: 300; background-color: rgba(158, 158, 158, 0.2);"
...
...
core/templates/report_email.txt
View file @
668cf45e
...
...
@@ -22,7 +22,7 @@ Detailed overview:
{% endfor %}
{% if issues %}Issues found:
{% if issues
|length > 0
%}Issues found:
{% for issue in issues %}
{{ issue.code }}: {{ issue.description }}
{{ issue.object_title }}
...
...
core/tests/email_reporter/test_reporter.py
View file @
668cf45e
from
core.issues
import
Issue
from
typing
import
cast
from
django.db.models.query
import
QuerySet
from
core.reporting
import
cast_to_queryset
,
ReportParameters
,
ReportParametersCollector
,
ReportRenderer
from
core.reporting
import
cast_to_queryset
,
cast_to_issue_list
from
core.reporting
import
ReportParameters
,
ReportParametersCollector
,
ReportRenderer
from
core.models
import
Project
,
data_declaration
from
test
import
factories
def
test_cast_to_queryset
():
assert
cast_to_queryset
(
None
,
Project
)
==
None
assert
cast_to_queryset
(
None
,
Project
)
is
None
project
=
factories
.
ProjectFactory
.
create
(
acronym
=
'test1'
,
title
=
'test1'
)
assert
type
(
cast_to_queryset
(
project
,
Project
))
==
QuerySet
...
...
@@ -18,6 +20,13 @@ def test_cast_to_queryset():
assert
type
(
cast_to_queryset
(
Project
.
objects
.
all
(),
Project
))
==
QuerySet
assert
type
(
cast_to_queryset
(
Project
.
objects
,
Project
))
==
QuerySet
assert
type
(
cast_to_queryset
(
Project
.
objects
.
get
(
acronym
=
'test2'
),
Project
))
==
QuerySet
def
test_cast_to_issue_list
():
issue
=
Issue
(
'https://a.com'
,
'1'
,
'desc'
,
'title'
)
assert
cast_to_issue_list
(
None
)
is
None
assert
type
(
cast_to_issue_list
(
issue
))
==
list
assert
issue
in
cast_to_issue_list
(
issue
)
def
test_report_parameters
():
...
...
core/utils.py
View file @
668cf45e
...
...
@@ -2,6 +2,10 @@
Module that regroup some utilities.
"""
import
logging
from
os.path
import
join
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
class
DaisyLogger
:
...
...
@@ -22,3 +26,11 @@ class DaisyLogger:
message
+=
' '
.
join
((
'%s=%s'
%
(
str
(
k
),
str
(
v
))
for
k
,
v
in
kwargs
.
items
()))
return
fn
(
message
)
return
wrap
def
get_absolute_uri
(
uri
):
if
len
(
getattr
(
settings
,
'SERVER_SCHEME'
,
''
))
==
0
:
raise
ImproperlyConfigured
(
'You must specify "HTTP_SCHEME" in settings.py'
)
if
len
(
getattr
(
settings
,
'SERVER_URL'
,
''
))
==
0
:
raise
ImproperlyConfigured
(
'You must specify "SERVER_URL" in settings.py'
)
return
join
(
f
'
{
settings
.
SERVER_SCHEME
}
://
{
settings
.
SERVER_URL
}
'
,
uri
)
\ No newline at end of file
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