|
4 | 4 | from django_json_widget.widgets import JSONEditorWidget |
5 | 5 | from django.utils.html import mark_safe |
6 | 6 | from django.contrib import messages |
| 7 | +import requests |
7 | 8 | from sortedm2m_filter_horizontal_widget.forms import SortedFilteredSelectMultiple |
8 | 9 | from gsmap.models import Municipality, Snapshot, Workspace |
9 | | -import requests |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class MunicipalityAdmin(admin.OSMGeoAdmin): |
@@ -48,28 +48,44 @@ class SnapshotAdmin(admin.OSMGeoAdmin): |
48 | 48 | }, |
49 | 49 | } |
50 | 50 |
|
51 | | - list_display = ('id', 'title', 'municipality', 'permission', 'is_showcase', |
52 | | - 'created', 'modified') |
| 51 | + list_display = ('id', 'thumbnail_list_image', 'title', 'municipality', |
| 52 | + 'permission', 'is_showcase', 'created', 'modified') |
53 | 53 | list_filter = ('is_showcase', 'permission') |
54 | 54 | search_fields = ['title', 'municipality__name', 'municipality__canton'] |
55 | 55 |
|
56 | | - def _image_display(self, url, width=None): |
57 | | - return mark_safe( |
58 | | - '<a href="{url}" target="_blank">' |
59 | | - '<img src="{url}" width="{width}" height={height} />' |
60 | | - '</a>'.format(url=url, width=width, height='auto')) |
| 56 | + def _image_display(self, obj, width=None, link=True): |
| 57 | + if hasattr(obj, 'url'): |
| 58 | + html = '<img src="{url}" width="{width}" height={height} />'.format( |
| 59 | + url=obj.url, width=width, height='auto' |
| 60 | + ) |
| 61 | + if link: |
| 62 | + html = '<a href="{url}" target="_blank">{html}</a>'.format(url=obj.url, html=html) |
| 63 | + return mark_safe(html) |
| 64 | + else: |
| 65 | + return '-' |
61 | 66 |
|
62 | 67 | def screenshot_generated_image(self, obj): |
63 | | - return self._image_display(obj.screenshot_generated.url, width=300) |
| 68 | + return self._image_display(obj.screenshot_generated, width=300) |
64 | 69 |
|
65 | 70 | def thumbnail_generated_image(self, obj): |
66 | | - return self._image_display(obj.thumbnail_generated.url, width=200) |
| 71 | + return self._image_display(obj.thumbnail_generated, width=200) |
| 72 | + |
| 73 | + def thumbnail_list_image(self, obj): |
| 74 | + if obj.thumbnail_generated or obj.thumbnail_manual: |
| 75 | + return self._image_display( |
| 76 | + obj.thumbnail_generated or obj.thumbnail_manual, |
| 77 | + width=50, link=False |
| 78 | + ) |
| 79 | + else: |
| 80 | + return '-' |
| 81 | + |
| 82 | + thumbnail_list_image.short_description = 'thumbnail' |
67 | 83 |
|
68 | 84 | def screenshot_manual_image(self, obj): |
69 | | - return self._image_display(obj.screenshot_manual.url, width=300) |
| 85 | + return self._image_display(obj.screenshot_manual, width=300) |
70 | 86 |
|
71 | 87 | def thumbnail_manual_image(self, obj): |
72 | | - return self._image_display(obj.thumbnail_manual.url, width=200) |
| 88 | + return self._image_display(obj.thumbnail_manual, width=200) |
73 | 89 |
|
74 | 90 |
|
75 | 91 | def save_model(self, request, obj, form, change): |
|
0 commit comments