Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/utils.py
Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | if link_attrs: | ||||
attrs += '%s="%s" ' % (k, v) | attrs += '%s="%s" ' % (k, v) | ||||
if not link_text: | if not link_text: | ||||
link_text = url | link_text = url | ||||
link = '<a%shref="%s">%s</a>' % (attrs, escape(url), escape(link_text)) | link = '<a%shref="%s">%s</a>' % (attrs, escape(url), escape(link_text)) | ||||
return mark_safe(link) | return mark_safe(link) | ||||
def _snapshot_context_query_params(snapshot_context): | def _snapshot_context_query_params(snapshot_context): | ||||
query_params = None | query_params = {} | ||||
if not snapshot_context: | |||||
return query_params | |||||
if snapshot_context and snapshot_context["origin_info"]: | if snapshot_context and snapshot_context["origin_info"]: | ||||
origin_info = snapshot_context["origin_info"] | origin_info = snapshot_context["origin_info"] | ||||
snp_query_params = snapshot_context["query_params"] | |||||
query_params = {"origin_url": origin_info["url"]} | query_params = {"origin_url": origin_info["url"]} | ||||
if "timestamp" in snapshot_context["query_params"]: | if "timestamp" in snp_query_params: | ||||
query_params["timestamp"] = snapshot_context["query_params"]["timestamp"] | query_params["timestamp"] = snp_query_params["timestamp"] | ||||
if "visit_id" in snapshot_context["query_params"]: | if "visit_id" in snp_query_params: | ||||
query_params["visit_id"] = snapshot_context["query_params"]["visit_id"] | query_params["visit_id"] = snp_query_params["visit_id"] | ||||
if "snapshot" in snp_query_params and "visit_id" not in query_params: | |||||
query_params["snapshot"] = snp_query_params["snapshot"] | |||||
elif snapshot_context: | elif snapshot_context: | ||||
query_params = {"snapshot_id": snapshot_context["snapshot_id"]} | query_params = {"snapshot": snapshot_context["snapshot_id"]} | ||||
if snapshot_context["release"]: | |||||
query_params["release"] = snapshot_context["release"] | |||||
elif snapshot_context["branch"] and snapshot_context["branch"] != "HEAD": | |||||
query_params["branch"] = snapshot_context["branch"] | |||||
elif snapshot_context["revision_id"]: | |||||
query_params["revision"] = snapshot_context["revision_id"] | |||||
return query_params | return query_params | ||||
vlorentz: jenkins reports this is missing some coverage | |||||
def gen_revision_url(revision_id, snapshot_context=None): | def gen_revision_url(revision_id, snapshot_context=None): | ||||
""" | """ | ||||
Utility function for generating an url to a revision. | Utility function for generating an url to a revision. | ||||
Args: | Args: | ||||
revision_id (str): a revision id | revision_id (str): a revision id | ||||
snapshot_context (dict): if provided, generate snapshot-dependent | snapshot_context (dict): if provided, generate snapshot-dependent | ||||
browsing url | browsing url | ||||
Returns: | Returns: | ||||
str: The url to browse the revision | str: The url to browse the revision | ||||
""" | """ | ||||
query_params = _snapshot_context_query_params(snapshot_context) | query_params = _snapshot_context_query_params(snapshot_context) | ||||
query_params.pop("revision", None) | |||||
return reverse( | return reverse( | ||||
"browse-revision", url_args={"sha1_git": revision_id}, query_params=query_params | "browse-revision", url_args={"sha1_git": revision_id}, query_params=query_params | ||||
) | ) | ||||
def gen_revision_link( | def gen_revision_link( | ||||
revision_id, | revision_id, | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | def get_revision_log_url(revision_id, snapshot_context=None): | ||||
Args: | Args: | ||||
revision_id (str): revision identifier the history heads to | revision_id (str): revision identifier the history heads to | ||||
snapshot_context (dict): if provided, generate snapshot-dependent | snapshot_context (dict): if provided, generate snapshot-dependent | ||||
browsing link | browsing link | ||||
Returns: | Returns: | ||||
The revision log view URL | The revision log view URL | ||||
""" | """ | ||||
query_params = {"revision": revision_id} | query_params = {} | ||||
if snapshot_context: | |||||
query_params = _snapshot_context_query_params(snapshot_context) | |||||
query_params["revision"] = revision_id | |||||
if snapshot_context and snapshot_context["origin_info"]: | if snapshot_context and snapshot_context["origin_info"]: | ||||
origin_info = snapshot_context["origin_info"] | |||||
query_params["origin_url"] = origin_info["url"] | |||||
if "timestamp" in snapshot_context["query_params"]: | |||||
query_params["timestamp"] = snapshot_context["query_params"]["timestamp"] | |||||
if "visit_id" in snapshot_context["query_params"]: | |||||
query_params["visit_id"] = snapshot_context["query_params"]["visit_id"] | |||||
revision_log_url = reverse("browse-origin-log", query_params=query_params) | revision_log_url = reverse("browse-origin-log", query_params=query_params) | ||||
elif snapshot_context: | elif snapshot_context: | ||||
url_args = {"snapshot_id": snapshot_context["snapshot_id"]} | url_args = {"snapshot_id": snapshot_context["snapshot_id"]} | ||||
del query_params["snapshot"] | |||||
revision_log_url = reverse( | revision_log_url = reverse( | ||||
"browse-snapshot-log", url_args=url_args, query_params=query_params | "browse-snapshot-log", url_args=url_args, query_params=query_params | ||||
) | ) | ||||
else: | else: | ||||
revision_log_url = reverse( | revision_log_url = reverse( | ||||
"browse-revision-log", url_args={"sha1_git": revision_id} | "browse-revision-log", url_args={"sha1_git": revision_id} | ||||
) | ) | ||||
return revision_log_url | return revision_log_url | ||||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |
jenkins reports this is missing some coverage