Allow extending GAS media files
This commit is contained in:
parent
ee4218c901
commit
4fa82a63a0
|
@ -18,3 +18,5 @@ MEDIA = getattr(settings, 'GAS_MEDIA', {
|
||||||
'gas/js/gas.js',
|
'gas/js/gas.js',
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
EXTRA_MEDIA = getattr(settings, 'GAS_EXTRA_MEDIA', None)
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
<ul id="main-navigation">
|
<ul id="main-navigation">
|
||||||
<li>{{ user }}</li>
|
<li>{{ user }}</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'gas:change_password' %}"> <i class="fa fa-fw fa-key" title="{% trans "Change password" %}"></i></a>
|
<a href="{% url 'gas:change_password' %}"> <i class="fas fa-key" title="{% trans "Change password" %}"></i></a>
|
||||||
<a href="{% url 'gas:logout' %}"> <i class="fa fa-fw fa-times text-danger" title="{% trans "Logout" %}"></i></a>
|
<a href="{% url 'gas:logout' %}"> <i class="fas fa-times" title="{% trans "Logout" %}"></i></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -243,6 +243,41 @@ class GASMixinTestCase(TestCase):
|
||||||
with self.assertRaises(ImproperlyConfigured):
|
with self.assertRaises(ImproperlyConfigured):
|
||||||
response = view(request)
|
response = view(request)
|
||||||
|
|
||||||
|
def test_extra_css(self):
|
||||||
|
class SampleView(gviews.GASMixin, TemplateView):
|
||||||
|
template_name = 'test.html'
|
||||||
|
|
||||||
|
view = SampleView.as_view()
|
||||||
|
request = self.request_factory.get('some_url')
|
||||||
|
|
||||||
|
request.user = self.admin_user
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
gas_settings.EXTRA_MEDIA = None
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertNotIn('test.css', response.context_data['css'])
|
||||||
|
self.assertNotIn('test.js', response.context_data['js'])
|
||||||
|
|
||||||
|
gas_settings.EXTRA_MEDIA = {'css': ['test.css']}
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn('test.css', response.context_data['css'])
|
||||||
|
self.assertNotIn('test.js', response.context_data['js'])
|
||||||
|
|
||||||
|
gas_settings.EXTRA_MEDIA = {'js': ['test.js']}
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertNotIn('test.css', response.context_data['css'])
|
||||||
|
self.assertIn('test.js', response.context_data['js'])
|
||||||
|
|
||||||
|
gas_settings.EXTRA_MEDIA = {'css': ['test.css'], 'js': ['test.js']}
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn('test.css', response.context_data['css'])
|
||||||
|
self.assertIn('test.js', response.context_data['js'])
|
||||||
|
|
||||||
|
|
||||||
class GASListTestCase(TestCase):
|
class GASListTestCase(TestCase):
|
||||||
def test_filtered(self):
|
def test_filtered(self):
|
||||||
|
|
|
@ -99,6 +99,11 @@ class GASMixin:
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
css = gas_settings.MEDIA['css']
|
||||||
|
js = gas_settings.MEDIA['js']
|
||||||
|
if gas_settings.EXTRA_MEDIA:
|
||||||
|
css = css + gas_settings.EXTRA_MEDIA.get('css', [])
|
||||||
|
js = js + gas_settings.EXTRA_MEDIA.get('js', [])
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'base_template': self.base_template,
|
'base_template': self.base_template,
|
||||||
'header_title': self.get_header_title(),
|
'header_title': self.get_header_title(),
|
||||||
|
@ -108,8 +113,8 @@ class GASMixin:
|
||||||
'actions': self.get_actions(),
|
'actions': self.get_actions(),
|
||||||
'gas_title': gas_settings.TITLE,
|
'gas_title': gas_settings.TITLE,
|
||||||
'logo_static_url': gas_settings.LOGO,
|
'logo_static_url': gas_settings.LOGO,
|
||||||
'css': gas_settings.MEDIA['css'],
|
'css': css,
|
||||||
'js': gas_settings.MEDIA['js'],
|
'js': js,
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@ Project settings can customize the `gas` control panel:
|
||||||
* `GAS_TITLE`: Name of the control panel.
|
* `GAS_TITLE`: Name of the control panel.
|
||||||
* `GAS_LOGO`: Icon for the control panel.
|
* `GAS_LOGO`: Icon for the control panel.
|
||||||
* `GAS_MEDIA`: A django form's Media like dict with css and js files.
|
* `GAS_MEDIA`: A django form's Media like dict with css and js files.
|
||||||
|
Overrides default css and javascript.
|
||||||
|
* `GAS_EXTRA_MEDIA`: A django form's Media like dict with css and js
|
||||||
|
files. Extends current css and javascript instead of overriding.
|
||||||
|
|
||||||
The default values of those settings can be viewed in the
|
The default values of those settings can be viewed in the
|
||||||
`gas/gas_settings.py` file.
|
`gas/gas_settings.py` file.
|
||||||
|
|
Loading…
Reference in New Issue