diff --git a/home/apps.py b/home/apps.py
new file mode 100644
index 000000000..1bfa33661
--- /dev/null
+++ b/home/apps.py
@@ -0,0 +1,8 @@
+from django.apps import AppConfig
+
+class HomeConfig(AppConfig):
+ name = "home"
+
+ def ready(self):
+ import home.signals
+
diff --git a/home/signals.py b/home/signals.py
new file mode 100644
index 000000000..c09823513
--- /dev/null
+++ b/home/signals.py
@@ -0,0 +1,15 @@
+from django.dispatch import receiver
+from wagtail.core.models import Site
+from django.db.models.signals import pre_save, pre_delete
+from wagtail.admin import messages
+
+
+@receiver(pre_save, sender=Site)
+def save_site(instance, **kwargs):
+ if Site.objects.exclude(pk=instance.pk).count() == 0:
+ instance.is_default_site = True
+
+@receiver(pre_delete, sender=Site)
+def delete_site(sender, instance, using, **kwargs):
+ if Site.objects.exclude(pk=instance.pk).count() == 1:
+ Site.objects.exclude(pk=instance.pk).update(is_default_site=True)
diff --git a/home/tests/tests.py b/home/tests/tests.py
index 41303c695..8a2405b71 100644
--- a/home/tests/tests.py
+++ b/home/tests/tests.py
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.http import HttpRequest
+from django.urls import reverse
from translation_manager.models import TranslationEntry
from wagtail.core.models import Site
from wagtail_localize.operations import TranslationCreator
@@ -9,6 +10,8 @@
from wagtail_factories import SiteFactory, PageFactory
from bs4 import BeautifulSoup
+from iogt_users.factories import AdminUserFactory
+
class LimitPageChooserHookTests(TestCase):
def setUp(self):
@@ -98,3 +101,23 @@ def test_media_block_translation_of_bengali_language(self):
self.assertEqual(response.status_code, 200)
self.assertContains(response, f"উপরের ভিডিও দেখা না গেলে এর পরিবর্তে এটা ডাউনলোড করুন", count=1)
self.assertContains(response, f"উপরের অডিও শুনতে না পেলে এর পরিবর্তে এটা ডাউনলোড করুন", count=1)
+
+
+class SiteTest(TestCase):
+ def setUp(self):
+ self.site01 = SiteFactory(hostname='localhost', port=8000, is_default_site=True)
+ self.site02 = SiteFactory(hostname='testserver', port=80)
+ admin_user = AdminUserFactory()
+ self.client.force_login(admin_user)
+
+ def test_hide_delete_button_on_default_site(self):
+ response = self.client.get(reverse('wagtailsites:edit', args=(self.site01.pk,)))
+
+ self.assertEqual(response.status_code, 200)
+ self.assertNotContains(response, 'Delete site')
+
+ def test_display_delete_button_on_non_default_site(self):
+ response = self.client.get(reverse('wagtailsites:edit', args=(self.site02.pk,)))
+
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, 'Delete site')
diff --git a/iogt/settings/base.py b/iogt/settings/base.py
index 840de6f25..0a4839df4 100644
--- a/iogt/settings/base.py
+++ b/iogt/settings/base.py
@@ -31,7 +31,7 @@
# Application definition
INSTALLED_APPS = [
- 'home',
+ 'home.apps.HomeConfig',
'search',
'iogt_users',
'comments',
diff --git a/iogt/templates/wagtailadmin/generic/edit.html b/iogt/templates/wagtailadmin/generic/edit.html
new file mode 100644
index 000000000..3809a59ff
--- /dev/null
+++ b/iogt/templates/wagtailadmin/generic/edit.html
@@ -0,0 +1,13 @@
+{% extends "wagtailadmin/generic/form.html" %}
+{% load i18n %}
+
+{% block actions %}
+
+
+ {# TO DO: Update this file on wagtail upgrade #}
+ {% if can_delete and site is None %}
+ {{ view.delete_item_label }}
+ {% elif can_delete and site is not None and not site.is_default_site %}
+ {{ view.delete_item_label }}
+ {% endif %}
+{% endblock %}