Skip to content

Commit

Permalink
Allow overriding suit config by request for demos. Layout switch for …
Browse files Browse the repository at this point in the history
…demo
  • Loading branch information
darklow committed Feb 11, 2017
1 parent 4b2afa4 commit 30e77bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
41 changes: 40 additions & 1 deletion demo/demo/templates/admin/base_site.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
{% extends 'admin/base_site.html' %}
{# This is how you can extend admin by custom CSS or JS files #}
{% load suit_tags %}

{# Following is an example how to extend admin by custom CSS or JS files #}
{# Add extra CSS for admin #}
{#{% block extrastyle %}#}
{# {{ block.super }}#}
{# <link rel="stylesheet" href="{% static 'css/admin.css' %}">#}
{#{% endblock %}#}

{#{% block foot %}#}
{# {{ block.super }}#}
{# <script type="text/javascript"></script>#}
{#{% endblock %}#}



{# Switch for demonstration purposes, not indended for production use #}
{% block usertools %}
{% with suit_layout='layout'|suit_conf:request %}
{% if suit_layout == 'horizontal' %}
<a href="{% url 'admin:index' %}?__suit_layout=vertical" class="demo-layout-switch">
Switch to vertical
</a>
{% else %}
<a href="{% url 'admin:index' %}?__suit_layout=horizontal" class="demo-layout-switch">
Switch to horizontal
</a>
{% endif %}

{{ block.super }}

{% endwith %}

<style type="text/css">
body #header a.demo-layout-switch {
color: #687086;
}

body.suit_layout_vertical .demo-layout-switch {
background-color: #383D4B;
order: 10;
text-align: center;
padding: .5rem 0;
}
</style>
{% endblock %}
10 changes: 10 additions & 0 deletions suit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def get_config_instance(app_name=None):

def get_config(param=None, request=None):
suit_config = get_config_instance(get_current_app(request) if request else None)

# Allow overriding suit config by request
# Used only for demo purposes
req_key = '__suit_config_by_request'
if request and not hasattr(req_key, req_key):
setattr(request, req_key, True)
for k, v in request.GET.items():
if k.startswith('__suit_'):
setattr(suit_config, k[7:], v)

if param:
value = getattr(suit_config, param, None)
if value is None:
Expand Down

0 comments on commit 30e77bf

Please sign in to comment.