Skip to content

OKRS24-117 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.utils.translation import gettext_lazy as _
from linkpreview import LinkPreview, link_preview
from models_extensions.models import TimeStampedModel
from requests.exceptions import HTTPError

from base.tools import get_class_by_name, split_class_name

Expand Down Expand Up @@ -116,4 +117,9 @@ def get_preview(self) -> LinkPreview:
:return: A dictionary containing information about the link preview, including title, description, and image.
:rtype: dict
"""
return link_preview(self)
try:
return link_preview(self)
except HTTPError:
return {
'description': _('No description available'),
}
35 changes: 24 additions & 11 deletions src/templates/signals/signal_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,30 @@ <h5>Related links</h5>
<div class="card">
<div class="card-body padding-top-1rem">
<div class="row">
{% for link in signal.links.all %}
{% if link.link_type != 'example_url' %}
<div class="card col-2 related-link-card">
<div class="card-body">
<h5 class="card-title">{{ link.get_previerw.title }}</h5>
<p class="card-text">{{ link.get_preview.description }}</p>
<a href="{{ link.url }}">{{ link.url|truncatechars:50 }}</a>
</div>
</div>
{% endif %}
{% endfor %}
<table class="table table-responsive">
<thead>
<tr>
<th scope="col">Link Type</th>
<th scope="col">Link Description</th>
<th scope="col">URL</th>
</tr>
</thead>
<tbody>
{% for link in signal.links.all %}
{% if link.link_type != 'example_url' %}
<tr>
<td>
{{ link.get_link_type_display }}
</td>
<td>{{ link.get_preview.description }}</td>
<td>
<a href="{{ link.url }}">{{ link.url|truncatechars:50 }}</a>
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
Expand Down
Loading