Strip querystring from report cover image url (#1635)

This commit is contained in:
Greg Kaleka
2025-02-14 13:50:09 -05:00
committed by GitHub
parent 77b3253678
commit ffc545be0d
2 changed files with 14 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
from urllib.parse import urlparse, urlunparse
from django import template
from django.template.defaultfilters import stringfilter
import re
@@ -73,3 +75,13 @@ def url_target_blank(value, arg):
Use after urlize to add target="_blank" and add classes.
"""
return value.replace("<a ", f'<a target="_blank" class="{arg}" ')
@register.filter
def strip_query_string(url):
"""Remove query string from URL while preserving the path and other components."""
if not url:
return url
parsed = urlparse(url)
clean = parsed._replace(query="", fragment="")
return urlunparse(clean)

View File

@@ -1,5 +1,5 @@
{% extends "admin/library_report_base.html" %}
{% load humanize avatar_tags %}
{% load humanize avatar_tags text_helpers %}
{% load static %}
{% block css %}
{{ block.super }}
@@ -93,7 +93,7 @@ body {
{% if version.release_report_cover_image and version.release_report_cover_image.url %}
<img
class="max-h-[60%]"
src="{{ version.release_report_cover_image.url }}"
src="{{ version.release_report_cover_image.url|strip_query_string }}"
alt="release report cover image"
>
{% endif %}