Skip to content

Commit 2e3d7e3

Browse files
committed
Merge branch 'screenshot' into stage
2 parents 0f1c668 + 8eb348c commit 2e3d7e3

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

django/gsmap/admin.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from django_json_widget.widgets import JSONEditorWidget
55
from django.utils.html import mark_safe
66
from django.contrib import messages
7+
import requests
78
from sortedm2m_filter_horizontal_widget.forms import SortedFilteredSelectMultiple
89
from gsmap.models import Municipality, Snapshot, Workspace
9-
import requests
1010

1111

1212
class MunicipalityAdmin(admin.OSMGeoAdmin):
@@ -48,28 +48,44 @@ class SnapshotAdmin(admin.OSMGeoAdmin):
4848
},
4949
}
5050

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')
5353
list_filter = ('is_showcase', 'permission')
5454
search_fields = ['title', 'municipality__name', 'municipality__canton']
5555

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 '-'
6166

6267
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)
6469

6570
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'
6783

6884
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)
7086

7187
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)
7389

7490

7591
def save_model(self, request, obj, form, change):

django/gsmap/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def create_screenshot_file(self, is_thumbnail=False):
160160
if is_thumbnail:
161161
url += '&thumbnail'
162162
path = 'snapshot-thumbnails'
163-
response = requests.get(url, timeout=(5, 30))
163+
response = requests.get(url, timeout=(10, 50))
164164
date_suffix = timezone.now().strftime("%Y-%m-%d_%H-%M-%SZ")
165165
screenshot_file = SimpleUploadedFile(
166166
f'{path}/{self.pk}_{date_suffix}.png',
@@ -196,7 +196,9 @@ def save_screenshot():
196196
post_save.disconnect(save_screenshot_handler, sender=Snapshot)
197197
instance = kwargs.get('instance')
198198
# only create snapshot if data changed
199-
if instance.data_changed(['data', 'screenshot_generated', 'thumbnail_generated']):
199+
if instance.data_changed([
200+
'data', 'screenshot_generated', 'thumbnail_generated'
201+
]) or not bool(instance.thumbnail_generated):
200202
if not 'resources' in instance.data:
201203
return
202204
try:

django/main/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from django.conf import settings
22
from django.contrib import admin
33
from django.urls import path
4-
from graphene_django.views import GraphQLView
54
from django.views.decorators.csrf import csrf_exempt
5+
from graphene_django.views import GraphQLView
66

77
urlpatterns = [
88
path('gmanage/', admin.site.urls),

0 commit comments

Comments
 (0)