Skip to content

Commit 0675a0c

Browse files
committed
add timeouts to screenshot server requests, show error message in django admin
1 parent 8f04e50 commit 0675a0c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

django/gsmap/admin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from django.utils.translation import gettext as _
44
from django_json_widget.widgets import JSONEditorWidget
55
from django.utils.html import mark_safe
6+
from django.contrib import messages
67
from sortedm2m_filter_horizontal_widget.forms import SortedFilteredSelectMultiple
78
from gsmap.models import Municipality, Snapshot, Workspace
9+
import requests
810

911

1012
class MunicipalityAdmin(admin.OSMGeoAdmin):
@@ -70,6 +72,13 @@ def thumbnail_manual_image(self, obj):
7072
return self._image_display(obj.thumbnail_manual.url, width=200)
7173

7274

75+
def save_model(self, request, obj, form, change):
76+
try:
77+
obj.save()
78+
except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError) as e:
79+
messages.error(request, "Couldn't create the screenshots, screenshot server problem.")
80+
81+
7382
class WorkspaceAdmin(admin.OSMGeoAdmin):
7483
readonly_fields = ('id', 'created', 'modified', 'get_absolute_link')
7584
fieldsets = (

django/gsmap/models.py

Lines changed: 1 addition & 1 deletion
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)
163+
response = requests.get(url, timeout=(5, 30))
164164
date_suffix = timezone.now().strftime("%Y-%m-%d_%H-%M-%SZ")
165165
screenshot_file = SimpleUploadedFile(
166166
f'{path}/{self.pk}_{date_suffix}.png',

0 commit comments

Comments
 (0)