-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(risk-matrix): use plotly #2
Changes from all commits
76629a0
2a1f013
a5d1d4c
cf07768
3d2a6ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Daverball marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ | |||||||
if TYPE_CHECKING: | ||||||||
from pyramid.interfaces import IRequest | ||||||||
from sqlalchemy.orm.query import Query | ||||||||
from typing import TypeVar | ||||||||
from typing import TypeVar, Iterator | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Always use the
|
||||||||
|
||||||||
from riskmatrix.models import Organization | ||||||||
from riskmatrix.types import MixedDataOrRedirect | ||||||||
|
@@ -130,25 +130,24 @@ def buttons(self, assessment: RiskAssessment | None = None) -> list[Button]: | |||||||
|
||||||||
|
||||||||
class AssessmentOverviewTable(AssessmentBaseTable): | ||||||||
nr = DataColumn(_("Nr.")) | ||||||||
name = DataColumn(_("Name")) | ||||||||
description = DataColumn(_("Description"), class_name="visually-hidden") | ||||||||
category = DataColumn(_("Category")) | ||||||||
asset_name = DataColumn(_("Asset")) | ||||||||
likelihood = DataColumn(_("Likelihood")) | ||||||||
impact = DataColumn(_("Impact")) | ||||||||
|
||||||||
def __init__(self, org: "Organization", request: "IRequest") -> None: | ||||||||
super().__init__(org, request, id="risks-table") | ||||||||
nr = DataColumn(_('Nr.')) | ||||||||
name = DataColumn(_('Name')) | ||||||||
description = DataColumn(_('Description'), class_name='visually-hidden') | ||||||||
category = DataColumn(_('Category')) | ||||||||
asset_name = DataColumn(_('Asset')) | ||||||||
likelihood = DataColumn(_('Likelihood')) | ||||||||
impact = DataColumn(_('Impact')) | ||||||||
|
||||||||
def __init__(self, org: 'Organization', request: 'IRequest') -> None: | ||||||||
super().__init__(org, request, id='risks-table') | ||||||||
xhr_edit_js.need() | ||||||||
|
||||||||
def query(self) -> "Query[RiskMatrixAssessment]": | ||||||||
def query(self) -> 'Iterator[RiskMatrixAssessment]': | ||||||||
query = super().query() | ||||||||
|
||||||||
return map( | ||||||||
lambda entry: setattr(entry[1], "nr", entry[0] + 1) or entry[1], | ||||||||
enumerate(query), | ||||||||
) | ||||||||
for idx, item in enumerate(query, start=1): | ||||||||
item.nr = idx | ||||||||
yield item | ||||||||
|
||||||||
|
||||||||
_RADIO_TEMPLATE = Markup( | ||||||||
|
@@ -287,7 +286,6 @@ def __html__(self) -> str: | |||||||
params=params, | ||||||||
) | ||||||||
|
||||||||
|
||||||||
def generate_risk_matrix_view( | ||||||||
context: "Organization", request: "IRequest" | ||||||||
) -> "RenderData": | ||||||||
|
@@ -382,11 +380,13 @@ def plot_risk_matrix(risks: 'Query[RiskMatrixAssessment]') -> str: | |||||||
font=dict(size=20), | ||||||||
) | ||||||||
|
||||||||
return fig.to_html( | ||||||||
return Markup(fig.to_html( | ||||||||
full_html=False, | ||||||||
include_plotlyjs=False, | ||||||||
config={"modeBarButtonsToRemove": ["zoom", "pan", "select", "lasso2d"]}, | ||||||||
) | ||||||||
include_plotlyjs=True, | ||||||||
config={ | ||||||||
'modeBarButtonsToRemove': ['zoom', 'pan', 'select', 'lasso2d'] | ||||||||
}, | ||||||||
)) | ||||||||
|
||||||||
|
||||||||
def edit_assessment_view( | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to also add a
csp_nonce
attribute totesting.DummyRequest
, this can just be a static string for testing. Some tests currently fail because the attribute doesn't exist.