mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
* made results table responsive for Django 2 admin * make fieldsets collapsable * updated version via feature * fixed codestyle according to requested changes * made results table responsive for Django 2 admin Co-authored-by: Camilo Nova <camilo.nova@axiacore.com>
This commit is contained in:
parent
5e91a92431
commit
4de4114bbd
5 changed files with 56 additions and 5 deletions
1
AUTHORS
1
AUTHORS
|
|
@ -8,6 +8,7 @@ Dan Poirier <dpoirier@caktusgroup.com>
|
|||
David Burke <dmbst32@gmail.com>
|
||||
Florian Apolloner <florian@apolloner.eu>
|
||||
Igor Támara <igor@axiacore.com>
|
||||
Ilya Chichak <ilyachch@gmail.com>
|
||||
Jake Merdich <jmerdich@users.noreply.github.com>
|
||||
Jannis Leidel <jannis@leidel.info>
|
||||
Janusz Harkot <janusz.harkot@gmail.com>
|
||||
|
|
|
|||
|
|
@ -250,7 +250,14 @@ class ConstanceAdmin(admin.ModelAdmin):
|
|||
|
||||
if settings.CONFIG_FIELDSETS:
|
||||
context['fieldsets'] = []
|
||||
for fieldset_title, fields_list in settings.CONFIG_FIELDSETS.items():
|
||||
for fieldset_title, fieldset_data in settings.CONFIG_FIELDSETS.items():
|
||||
if type(fieldset_data) == dict:
|
||||
fields_list = fieldset_data['fields']
|
||||
collapse = fieldset_data.get('collapse', False)
|
||||
else:
|
||||
fields_list = fieldset_data
|
||||
collapse = False
|
||||
|
||||
absent_fields = [field for field in fields_list
|
||||
if field not in settings.CONFIG]
|
||||
assert not any(absent_fields), (
|
||||
|
|
@ -265,11 +272,14 @@ class ConstanceAdmin(admin.ModelAdmin):
|
|||
config_values.append(
|
||||
self.get_config_value(name, options, form, initial)
|
||||
)
|
||||
|
||||
context['fieldsets'].append({
|
||||
fieldset_context = {
|
||||
'title': fieldset_title,
|
||||
'config_values': config_values
|
||||
})
|
||||
}
|
||||
|
||||
if collapse:
|
||||
fieldset_context['collapse'] = True
|
||||
context['fieldsets'].append(fieldset_context)
|
||||
if not isinstance(settings.CONFIG_FIELDSETS, OrderedDict):
|
||||
context['fieldsets'].sort(key=itemgetter('title'))
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
{{ block.super }}
|
||||
{{ media.js }}
|
||||
<script type="text/javascript" src="{% static 'admin/js/constance.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'admin/js/collapse.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block bodyclass %}change-list{% endblock %}
|
||||
|
|
@ -45,7 +46,7 @@
|
|||
|
||||
{% if fieldsets %}
|
||||
{% for fieldset in fieldsets %}
|
||||
<fieldset class="module">
|
||||
<fieldset class="module{% if fieldset.collapse %} collapse{% endif %}">
|
||||
<h2>{{ fieldset.title }}</h2>
|
||||
{% with config_values=fieldset.config_values %}
|
||||
{% include "admin/constance/includes/results_list.html" %}
|
||||
|
|
|
|||
|
|
@ -192,6 +192,28 @@ You can define fieldsets to group settings together:
|
|||
|
||||
.. image:: screenshot3.png
|
||||
|
||||
|
||||
Fieldsets collapsing
|
||||
--------------------
|
||||
|
||||
To make some fieldsets collapsing you can use new format if CONSTANCE_CONFIG_FIELDSETS. Here's an example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
CONSTANCE_CONFIG = {
|
||||
'SITE_NAME': ('My Title', 'Website title'),
|
||||
'SITE_DESCRIPTION': ('', 'Website description'),
|
||||
'THEME': ('light-blue', 'Website theme'),
|
||||
}
|
||||
|
||||
CONSTANCE_CONFIG_FIELDSETS = {
|
||||
'General Options': {
|
||||
'fields': ('SITE_NAME', 'SITE_DESCRIPTION'),
|
||||
'collapse': True
|
||||
},
|
||||
'Theme Options': ('THEME',),
|
||||
}
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,23 @@ class TestAdmin(TestCase):
|
|||
self.assertContains(response, '<h2>Numbers</h2>')
|
||||
self.assertContains(response, '<h2>Text</h2>')
|
||||
|
||||
@mock.patch('constance.settings.CONFIG_FIELDSETS', {
|
||||
'Numbers': {
|
||||
'fields': ('INT_VALUE', 'DECIMAL_VALUE',),
|
||||
'collapse': True,
|
||||
},
|
||||
'Text': {
|
||||
'fields': ('STRING_VALUE', 'LINEBREAK_VALUE',),
|
||||
'collapse': True,
|
||||
},
|
||||
})
|
||||
def test_collapsed_fieldsets(self):
|
||||
self.client.login(username='admin', password='nimda')
|
||||
request = self.rf.get('/admin/constance/config/')
|
||||
request.user = self.superuser
|
||||
response = self.options.changelist_view(request, {})
|
||||
self.assertContains(response, 'module collapse')
|
||||
|
||||
@mock.patch('constance.settings.CONFIG_FIELDSETS', {
|
||||
'FieldSetOne': ('INT_VALUE',)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue