Skip to content

Commit

Permalink
[#2302] basic css overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 3, 2012
1 parent 3123bc4 commit 0ffe609
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ckan/controllers/admin.py
Expand Up @@ -51,6 +51,9 @@ def config(self):
intro_text = data.get('intro_text')
app_globals.set_global('ckan.site_intro_text', intro_text)

custom_css = data.get('custom_css')
app_globals.set_global('ckan.site_custom_css', custom_css)

if 'reset' in data:
# remove sys info items
for key in app_globals.auto_update:
Expand All @@ -72,6 +75,7 @@ def config(self):
data['tagline'] = g.site_description
data['about'] = g.site_about
data['intro_text'] = g.site_intro_text
data['custom_css'] = g.site_custom_css

vars = {'data': data, 'errors': {}, 'styles': styles}
return base.render('admin/config.html',
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/app_globals.py
Expand Up @@ -24,6 +24,7 @@
'ckan.site_description',
'ckan.site_about',
'ckan.site_intro_text',
'ckan.site_custom_css',
]

# A place to store the origional config options of we override them
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/admin/config.html
Expand Up @@ -20,6 +20,8 @@ <h1 class="page-heading">{{ _('Configuration Settings') }}</h1>

{{ form.markdown('intro_text', id='field-intro', label=_('Intro Text'), placeholder=_('Intro contents'), value=data.intro_text, error=errors.intro_text) }}

{{ form.plain_textarea('custom_css', id='field-intro', label=_('Custom CSS'), placeholder=_('Custom css'), value=data.custom_css, error=errors.custom_css) }}

<div class="form-actions">
{# Update needs to come first so form submits when return is pressed #}
<button type="submit" class="btn btn-primary" name="save">Update</button>
Expand Down
5 changes: 5 additions & 0 deletions ckan/templates/base.html
Expand Up @@ -89,6 +89,11 @@
{% block head_extras %}
{{ config.get('ckan.template_head_end', '') | safe }}
{% endblock %}
{%- if g.site_custom_css -%}
<style>
{{ g.site_custom_css | safe }}
</style>
{%- endif %}
</head>

{# Allows custom attributes to be added to the <body> tag #}
Expand Down
27 changes: 27 additions & 0 deletions ckan/templates/macros/form.html
Expand Up @@ -118,6 +118,33 @@
{% endcall %}
{% endmacro %}

{#
Creates all the markup required for a plain textarea element. Handles
matching labels to inputs, selected item and error messages.

name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
value - The value of the input.
placeholder - Some placeholder text.
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the control-group.

Examples:

{% import 'macros/form.html' as form %}
{{ form.plain_textarea('desc', id='field-description', label=_('Description'), value=data.desc, error=errors.desc) }}

#}
{% macro plain_textarea(name, id='', label='', value='', placeholder='', error="", classes=[], attrs={}) %}
{% set classes = (classes|list) %}
{% do classes.append('control-full') %}

{% call input_block(id or name, label or name, error, classes, control_classes=["editor"]) %}
<textarea id="{{ id or name }}" name="{{ name }}" cols="20" rows="5" placeholder="{{ placeholder }}" {{ attributes(attrs) }}>{{ value | empty_and_escape }}</textarea>
{% endcall %}
{% endmacro %}

{#
Creates all the markup required for an input element with a prefixed segment.
These are useful for showing url slugs and other fields where the input
Expand Down

0 comments on commit 0ffe609

Please sign in to comment.