M dlrepo/templates/product_version.html => dlrepo/templates/product_version.html +14 -0
@@ 37,4 37,18 @@
{{macros.install_procedure(version.name, version.artifact_formats)}}
</section>
+
+{% if version.branch_links %}
+<section class="product-link">
+ <h2>Branch Link{{'s' if version.branch_links|length > 1}}</h2>
+ <hr/>
+ {% for link in version.branch_links|sort %}
+ <a href="/{{'~' + user + '/' if user}}branches/{{link}}/"
+ title="Branch link" class="product">
+ <span>{{link.split('/')[-1]}}</span>
+ </a>
+ {% endfor %}
+</section>
+{% endif %}
+
{% endblock %}
M dlrepo/views/product.py => dlrepo/views/product.py +10 -0
@@ 183,6 183,7 @@ class VersionView(BaseView):
html = "html" in self.request.headers.get("Accept", "json")
formats = []
+ branch_links = []
for fmt in version.get_formats():
fmt_url = fmt.url()
if self.access_granted(fmt_url):
@@ 202,12 203,21 @@ class VersionView(BaseView):
"url": fmt_url,
}
)
+ job = fmt.path().resolve().parent
+ link = f"{job.parent.parent.name}/{job.parent.name}/{job.name}"
+ if link not in branch_links and self.access_granted(
+ fmt.root().url() + link
+ ):
+ branch_links.append(link)
else:
formats.append(fmt.name)
data = {"version": {"name": version.name, "artifact_formats": formats}}
if html:
+ if branch_links:
+ data["version"]["branch_links"] = branch_links
+
return aiohttp_jinja2.render_template(
"product_version.html", self.request, data
)