From a2d467172486042432ae102e7ebe3df738d82d6c Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Mon, 24 Feb 2020 12:28:58 +0100 Subject: [PATCH 1/3] Sometimes redirs are hard to test :-/ --- ivatar/ivataraccount/test_views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index 057db68..ddb3906 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -1225,10 +1225,12 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods ) ) url = '%s?%s' % (urlobj.path, urlobj.query) - response = self.client.get(url, follow=True) + response = self.client.get(url, follow=False) self.assertRedirects( response=response, expected_url='/gravatarproxy/1b1d0b654430c012e47e350db07c83c5?s=80&default=mm', + status_code=302, + target_status_code=200, msg_prefix='Why does this not redirect to the gravatarproxy and defaulting to mm?') # Eventually one should check if the data is the same From d01cd083d8d5db617e37468b5ac0e6c0c6cb5997 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Mon, 24 Feb 2020 14:50:44 +0100 Subject: [PATCH 2/3] Add option to easily set maintenance page --- ivatar/urls.py | 17 +++++++++++++++-- templates/maintenance.html | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 templates/maintenance.html diff --git a/ivatar/urls.py b/ivatar/urls.py index 618890a..39d44db 100644 --- a/ivatar/urls.py +++ b/ivatar/urls.py @@ -13,7 +13,6 @@ urlpatterns = [ # pylint: disable=invalid-name path('admin/', admin.site.urls), path('i18n/', include('django.conf.urls.i18n')), url('openid/', include('django_openid_auth.urls')), - url('accounts/', include('ivatar.ivataraccount.urls')), url('tools/', include('ivatar.tools.urls')), url( r'avatar/(?P\w{64})', @@ -36,7 +35,21 @@ urlpatterns = [ # pylint: disable=invalid-name url('privacy/', TemplateView.as_view(template_name='privacy.html'), name='privacy'), url('contact/', TemplateView.as_view(template_name='contact.html'), name='contact'), path('talk_to_us/', RedirectView.as_view(url='/contact'), name='talk_to_us'), - url('', TemplateView.as_view(template_name='home.html'), name='home'), ] +MAINTENANCE = False +try: + if settings.MAINTENANCE: + MAINTENANCE = True +except: + pass + +if MAINTENANCE: + urlpatterns.append(url('', TemplateView.as_view(template_name='maintenance.html'), name='home')) + urlpatterns.insert(3, url('accounts/', RedirectView.as_view(url='/'))) +else: + urlpatterns.append(url('', TemplateView.as_view(template_name='home.html'), name='home')) + urlpatterns.insert(3, url('accounts/', include('ivatar.ivataraccount.urls'))) + + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/templates/maintenance.html b/templates/maintenance.html new file mode 100644 index 0000000..47e3dfa --- /dev/null +++ b/templates/maintenance.html @@ -0,0 +1,30 @@ +{% extends 'base_home.html' %} +{% load i18n %} +{% load static %} + +{% block title %}{% trans 'federated avatar hosting service' %}{% endblock %} + +{% block content %} + +
+
+
+

{{ site_name }}

+

{% trans 'freeing the web one face at a time' %}

+
+
+
+
+
+
+

{% trans 'Maintenance mode' %}

+ Libravatar is currently in maintenance mode.
+ Avatars are still served, but all write operations may result + in loss of these changes. +

+
+
+
+
+ +{% endblock %} From c5c4b7320884ff8f3bd0af4d88777a2f9e474fa8 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Mon, 24 Feb 2020 15:47:27 +0100 Subject: [PATCH 3/3] Further debugging --- ivatar/ivataraccount/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivatar/ivataraccount/models.py b/ivatar/ivataraccount/models.py index e4fc338..64a2265 100644 --- a/ivatar/ivataraccount/models.py +++ b/ivatar/ivataraccount/models.py @@ -180,7 +180,7 @@ class Photo(BaseAccountModel): # Testing? Ideas anyone? except Exception as exc: # pylint: disable=broad-except # For debugging only - print('Exception caught: %s' % exc) + print('Exception caught in Photo.save(): %s' % exc) return False self.format = file_format(img.format) if not self.format: