Skip to content

Commit

Permalink
Add a new AboutCode tab in Package details view #42
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed May 14, 2024
1 parent f7d990a commit f1a8b2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="alert alert-primary m-0 mb-3" role="alert">
<p class="m-0">
This tab renders a preview of the AboutCode files: .ABOUT and .NOTICE,
exactly as it will appear in the generated .yml files.<br>
<a href="{{ object.get_about_files_url }}" class="fw-bold">Click here to download</a>
those files as a zip archive.
</p>
</div>

<dl class="row mb-0">
<dt class="col-sm-1 text-end pt-2 pe-0">.ABOUT</dt>
<dd class="col-sm-11">
<pre class="pre-bg-body-tertiary mb-1">{{ values.about_content }}</pre>
</dd>
{% if values.notice_content %}
<dt class="col-sm-1 text-end pt-2 pe-0">.NOTICE</dt>
<dd class="col-sm-11">
<pre class="pre-bg-body-tertiary mb-1">{{ values.notice_content }}</pre>
</dd>
{% endif %}
</dl>
13 changes: 13 additions & 0 deletions component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from django.utils.formats import date_format
from django.utils.html import escape
from django.utils.html import format_html
from django.utils.text import normalize_newlines
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
Expand Down Expand Up @@ -1247,6 +1248,9 @@ class PackageDetailsView(
"vulnerabilities": {
"verbose_name": "Vulnerabilities",
},
"aboutcode": {
"verbose_name": "AboutCode",
},
"history": {
"fields": [
"created_date",
Expand Down Expand Up @@ -1447,6 +1451,15 @@ def tab_purldb(self):
}
return {"fields": [(None, tab_context, None, template)]}

def tab_aboutcode(self):
template = "component_catalog/tabs/tab_aboutcode.html"
context = {
"about_content": self.object.as_about_yaml(),
"notice_content": normalize_newlines(self.object.notice_text),
}

return {"fields": [(None, context, None, template)]}

def get_vulnerabilities_tab_fields(self, vulnerabilities):
dataspace = self.object.dataspace
fields = []
Expand Down

0 comments on commit f1a8b2f

Please sign in to comment.