Allow overriding home url

This commit is contained in:
Ales (Shagi) Zabala Alava 2022-09-01 11:24:01 +02:00
parent 40946be0e6
commit 3a89537a0c
4 changed files with 13 additions and 3 deletions

View File

@ -15,7 +15,7 @@
{% if not is_popup %}
<nav id="navbar-main" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="{% url "gas:index" %}"><img id="logo" src="{% static logo_static_url %}"></a>
<a class="navbar-brand" href="{{ home_url }}"><img id="logo" src="{% static logo_static_url %}"></a>
</div>
<ul id="main-navigation">
<li>{{ user }}</li>
@ -41,7 +41,7 @@
{% if not is_popup %}
<nav class="breadcrumb">
<ol>
<li><a href="{% url "gas:index" %}" title="{% trans "Home" %}"><i class="fas fa-home fa-fw"></i></a></li>
<li><a href="{{ home_url }}" title="{% trans "Home" %}"><i class="fas fa-home fa-fw"></i></a></li>
{% for bc_url, bc_label in breadcrumbs %}
{% if bc_url %}
<li><a href="{{ bc_url }}">{{ bc_label }}</a></li>

View File

@ -228,10 +228,14 @@ class GASMixinTestCase(TestCase):
]
template_name = 'gas/base.html'
def get_home_url(self):
return 'home_url'
view = SampleView.as_view()
request = self.request_factory.get('some_url')
request.user = self.admin_user
response = view(request)
self.assertEqual(response.context_data['home_url'], 'home_url')
self.assertEqual(response.context_data['title'], SampleView.title)
self.assertEqual(response.context_data['header_title'], SampleView.header_title)
self.assertEqual(response.context_data['help_text'], SampleView.help_text)
@ -428,7 +432,7 @@ class GASDeleteTestCase(TestCase):
success_url = 'success'
confirmation_text = 'delete {object.username}'
deleted_text = '{object.username} deleted'
view = SampleDeleteView.as_view()
request = request_factory.get('some_url')

View File

@ -110,6 +110,10 @@ class GASMixin:
def get_success_message(self):
return self.success_message
def get_home_url(self):
""" Url for the home of the control panel """
return reverse('gas:index')
def get_cancel_url(self):
if self.cancel_url:
# Forcing possible reverse_lazy evaluation
@ -154,6 +158,7 @@ class GASMixin:
js = js + gas_settings.EXTRA_MEDIA.get('js', [])
ctx.update({
'base_template': self.base_template,
'home_url': self.get_home_url(),
'header_title': self.get_header_title(),
'title': self.get_title(),
'help_text': self.get_help_text(),

View File

@ -10,6 +10,7 @@ def runtests():
if not settings.configured:
# Configure test environment
settings.configure(
SECRET_KEY="test-secret",
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',