Page MenuHomeSoftware Heritage

D3096.diff
No OneTemporary

D3096.diff

diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py
--- a/swh/web/browse/snapshot_context.py
+++ b/swh/web/browse/snapshot_context.py
@@ -1006,6 +1006,8 @@
"content": content_data.get("content_data"),
"content_size": content_data.get("length"),
"max_content_size": content_display_max_size,
+ "filename": filename,
+ "encoding": content_data.get("encoding"),
"mimetype": content_data.get("mimetype"),
"language": content_data.get("language"),
"available_languages": available_languages,
diff --git a/swh/web/browse/views/content.py b/swh/web/browse/views/content.py
--- a/swh/web/browse/views/content.py
+++ b/swh/web/browse/views/content.py
@@ -348,6 +348,8 @@
"content": content,
"content_size": content_data["length"],
"max_content_size": content_display_max_size,
+ "filename": filename,
+ "encoding": content_data["encoding"],
"mimetype": mimetype,
"language": language,
"available_languages": available_languages,
diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py
--- a/swh/web/browse/views/revision.py
+++ b/swh/web/browse/views/revision.py
@@ -10,10 +10,9 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.template.defaultfilters import filesizeformat
-from django.utils.html import escape
from django.utils.safestring import mark_safe
-from swh.model.identifiers import persistent_identifier
+from swh.model.identifiers import persistent_identifier, REVISION
from swh.web.browse.browseurls import browse_route
from swh.web.browse.snapshot_context import get_snapshot_context
from swh.web.browse.utils import (
@@ -34,6 +33,7 @@
)
from swh.web.common import service
from swh.web.common.exc import NotFoundExc, handle_view_exception
+from swh.web.common.typing import RevisionMetadata
from swh.web.common.utils import (
reverse,
format_utc_iso_date,
@@ -311,7 +311,7 @@
path = request.GET.get("path", None)
dir_id = None
dirs, files = None, None
- content_data = None
+ content_data = {}
if origin_url:
try:
snapshot_context = get_snapshot_context(
@@ -351,50 +351,36 @@
except Exception as exc:
return handle_view_exception(request, exc)
- revision_data = {}
-
- revision_data["author"] = "None"
- if revision["author"]:
- author_link = gen_person_mail_link(revision["author"])
- revision_data["author"] = author_link
- revision_data["committer"] = "None"
- if revision["committer"]:
- committer_link = gen_person_mail_link(revision["committer"])
- revision_data["committer"] = committer_link
- revision_data["committer date"] = format_utc_iso_date(revision["committer_date"])
- revision_data["date"] = format_utc_iso_date(revision["date"])
- revision_data["directory"] = revision["directory"]
- if snapshot_context:
- revision_data["snapshot"] = snapshot_id
- browse_snapshot_link = gen_snapshot_link(snapshot_id)
- revision_data["context-independent snapshot"] = browse_snapshot_link
-
- revision_data["context-independent directory"] = gen_directory_link(
- revision["directory"]
- )
- revision_data["revision"] = sha1_git
- revision_data["merge"] = revision["merge"]
- revision_data["metadata"] = escape(
- json.dumps(
+ revision_metadata = RevisionMetadata(
+ object_type=REVISION,
+ revision=sha1_git,
+ revision_url=gen_revision_link(sha1_git),
+ author=revision["author"]["fullname"] if revision["author"] else "None",
+ author_url=gen_person_mail_link(revision["author"])
+ if revision["author"]
+ else "None",
+ committer=revision["committer"]["fullname"]
+ if revision["committer"]
+ else "None",
+ committer_url=gen_person_mail_link(revision["committer"])
+ if revision["committer"]
+ else "None",
+ committer_date=format_utc_iso_date(revision["committer_date"]),
+ date=format_utc_iso_date(revision["date"]),
+ directory=revision["directory"],
+ directory_url=gen_directory_link(revision["directory"]),
+ merge=revision["merge"],
+ metadata=json.dumps(
revision["metadata"], sort_keys=True, indent=4, separators=(",", ": ")
- )
+ ),
+ parents=revision["parents"],
+ synthetic=revision["synthetic"],
+ type=revision["type"],
+ snapshot=snapshot_id,
+ snapshot_url=gen_snapshot_link(snapshot_id) if snapshot_id else None,
+ origin_url=origin_url,
)
- if origin_info:
- revision_data["origin url"] = gen_link(origin_info["url"], origin_info["url"])
- revision_data["context-independent revision"] = gen_revision_link(sha1_git)
-
- parents = ""
- for p in revision["parents"]:
- parent_link = gen_revision_link(
- p, link_text=None, link_attrs=None, snapshot_context=snapshot_context
- )
- parents += parent_link + "<br/>"
-
- revision_data["parents"] = mark_safe(parents)
- revision_data["synthetic"] = revision["synthetic"]
- revision_data["type"] = revision["type"]
-
message_lines = ["None"]
if revision["message"]:
message_lines = revision["message"].split("\n")
@@ -448,6 +434,7 @@
content = None
content_size = None
+ filename = None
mimetype = None
language = None
readme_name = None
@@ -472,8 +459,7 @@
query_params = {}
if path:
filename = path_info[-1]["name"]
- query_params["filename"] = path_info[-1]["name"]
- revision_data["filename"] = filename
+ query_params["filename"] = filename
top_right_link = {
"url": reverse(
@@ -560,7 +546,7 @@
"heading": heading,
"swh_object_id": swh_ids[0]["swh_id"],
"swh_object_name": "Revision",
- "swh_object_metadata": revision_data,
+ "swh_object_metadata": revision_metadata,
"message_header": message_lines[0],
"message_body": "\n".join(message_lines[1:]),
"parents": parents,
@@ -570,6 +556,8 @@
"content": content,
"content_size": content_size,
"max_content_size": content_display_max_size,
+ "filename": filename,
+ "encoding": content_data.get("encoding"),
"mimetype": mimetype,
"language": language,
"readme_name": readme_name,
diff --git a/swh/web/common/typing.py b/swh/web/common/typing.py
--- a/swh/web/common/typing.py
+++ b/swh/web/common/typing.py
@@ -165,3 +165,20 @@
target_type: str
target_url: str
snapshot: Optional[str]
+
+
+class RevisionMetadata(SWHObjectMetadata):
+ revision: str
+ author: str
+ author_url: str
+ committer: str
+ committer_url: str
+ date: str
+ committer_date: str
+ directory: str
+ merge: bool
+ metadata: str
+ parents: List[str]
+ synthetic: bool
+ type: str
+ snapshot: Optional[str]
diff --git a/swh/web/templates/browse/revision.html b/swh/web/templates/browse/revision.html
--- a/swh/web/templates/browse/revision.html
+++ b/swh/web/templates/browse/revision.html
@@ -19,8 +19,8 @@
{% block swh-browse-content %}
<div>
<i class="{{ swh_object_icons|key_value:'revision' }} fa-fw"></i>Revision <b>{{ swh_object_metadata.revision }}</b>
- authored by {{ swh_object_metadata.author }} on <b>{{ swh_object_metadata.date }}</b>,
- committed by {{ swh_object_metadata.committer }} on <b>{{ swh_object_metadata|key_value:'committer date' }}</b>
+ authored by {{ swh_object_metadata.author_url }} on <b>{{ swh_object_metadata.date }}</b>,
+ committed by {{ swh_object_metadata.committer_url }} on <b>{{ swh_object_metadata.committer_date }}</b>
</div>
<div class="card">
diff --git a/swh/web/templates/includes/content-display.html b/swh/web/templates/includes/content-display.html
--- a/swh/web/templates/includes/content-display.html
+++ b/swh/web/templates/includes/content-display.html
@@ -11,9 +11,9 @@
{% include "includes/empty-snapshot.html" %}
{% else %}
<div class="card">
- {% if swh_object_metadata.filename %}
+ {% if filename %}
<div class="swh-content-filename card-header bg-gray-light swh-heading-color">
- {{ swh_object_metadata.filename }}
+ {{ filename }}
</div>
{% endif %}
<div class="swh-content">
@@ -21,10 +21,10 @@
Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}).
{% elif "inode/x-empty" == mimetype %}
<i>File is empty</i>
- {% elif swh_object_metadata.filename and swh_object_metadata.filename|default:""|slice:"-5:" == "ipynb" %}
+ {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
<div class="swh-ipynb">
</div>
- {% elif "text/" in mimetype and swh_object_metadata.encoding != "binary" %}
+ {% elif "text/" in mimetype and encoding != "binary" %}
<div class="highlightjs">
<pre><code class="{{ language }}">{{ content }}</code></pre>
</div>
@@ -40,8 +40,8 @@
<canvas id="pdf-canvas"></canvas>
</div>
{% elif content %}
- Content with mime type {{ swh_object_metadata.mimetype }} and encoding
- {{ swh_object_metadata.encoding }} cannot be displayed.
+ Content with mime type {{ mimetype }} and encoding
+ {{ encoding }} cannot be displayed.
{% else %}
{% include "includes/http-error.html" %}
{% endif %}
@@ -51,7 +51,7 @@
<script>
{% if "application/pdf" == mimetype %}
swh.webapp.renderPdf({{ top_right_link.url|jsonify }});
- {% elif swh_object_metadata.filename and swh_object_metadata.filename|default:""|slice:"-5:" == "ipynb" %}
+ {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb');
{% elif content %}
let codeContainer = $('code');
diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py
--- a/swh/web/tests/browse/views/test_revision.py
+++ b/swh/web/tests/browse/views/test_revision.py
@@ -39,7 +39,7 @@
for parent in revision_data["parents"]:
parent_url = reverse("browse-revision", url_args={"sha1_git": parent})
- assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent))
+ assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent[:7]))
author_date = revision_data["date"]
committer_date = revision_data["committer_date"]
@@ -96,7 +96,7 @@
url_args={"sha1_git": parent},
query_params={"origin_url": origin["url"]},
)
- assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent))
+ assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent[:7]))
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 17, 8:45 PM (2 d, 10 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221762

Event Timeline