Skip to content

Commit 24ee771

Browse files
authored
Merge pull request #90 from cmu-delphi/OKRS24-117
OKRS24-117
2 parents 110a9a7 + 9e2d952 commit 24ee771

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/base/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.utils.translation import gettext_lazy as _
33
from linkpreview import LinkPreview, link_preview
44
from models_extensions.models import TimeStampedModel
5+
from requests.exceptions import HTTPError
56

67
from base.tools import get_class_by_name, split_class_name
78

@@ -116,4 +117,9 @@ def get_preview(self) -> LinkPreview:
116117
:return: A dictionary containing information about the link preview, including title, description, and image.
117118
:rtype: dict
118119
"""
119-
return link_preview(self)
120+
try:
121+
return link_preview(self)
122+
except HTTPError:
123+
return {
124+
'description': _('No description available'),
125+
}

src/templates/signals/signal_detail.html

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,30 @@ <h5>Related links</h5>
227227
<div class="card">
228228
<div class="card-body padding-top-1rem">
229229
<div class="row">
230-
{% for link in signal.links.all %}
231-
{% if link.link_type != 'example_url' %}
232-
<div class="card col-2 related-link-card">
233-
<div class="card-body">
234-
<h5 class="card-title">{{ link.get_previerw.title }}</h5>
235-
<p class="card-text">{{ link.get_preview.description }}</p>
236-
<a href="{{ link.url }}">{{ link.url|truncatechars:50 }}</a>
237-
</div>
238-
</div>
239-
{% endif %}
240-
{% endfor %}
230+
<table class="table table-responsive">
231+
<thead>
232+
<tr>
233+
<th scope="col">Link Type</th>
234+
<th scope="col">Link Description</th>
235+
<th scope="col">URL</th>
236+
</tr>
237+
</thead>
238+
<tbody>
239+
{% for link in signal.links.all %}
240+
{% if link.link_type != 'example_url' %}
241+
<tr>
242+
<td>
243+
{{ link.get_link_type_display }}
244+
</td>
245+
<td>{{ link.get_preview.description }}</td>
246+
<td>
247+
<a href="{{ link.url }}">{{ link.url|truncatechars:50 }}</a>
248+
</td>
249+
</tr>
250+
{% endif %}
251+
{% endfor %}
252+
</tbody>
253+
</table>
241254
</div>
242255
</div>
243256
</div>

0 commit comments

Comments
 (0)