Skip to content

Commit

Permalink
Apply black and adjust flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jul 6, 2018
1 parent e80c739 commit 100737d
Show file tree
Hide file tree
Showing 18 changed files with 960 additions and 877 deletions.
2 changes: 1 addition & 1 deletion bootstrap3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '10.0.1'
__version__ = "10.0.1"
72 changes: 32 additions & 40 deletions bootstrap3/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,35 @@

# Default settings
BOOTSTRAP3_DEFAULTS = {
'jquery_url': '//code.jquery.com/jquery.min.js',
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/',
'css_url': None,
'theme_url': None,
'javascript_url': None,
'javascript_in_head': False,
'include_jquery': False,
'horizontal_label_class': 'col-md-3',
'horizontal_field_class': 'col-md-9',

'set_placeholder': True,
'required_css_class': '',
'error_css_class': 'has-error',
'success_css_class': 'has-success',
'formset_renderers': {
'default': 'bootstrap3.renderers.FormsetRenderer',
},
'form_renderers': {
'default': 'bootstrap3.renderers.FormRenderer',
},
'field_renderers': {
'default': 'bootstrap3.renderers.FieldRenderer',
'inline': 'bootstrap3.renderers.InlineFieldRenderer',
"jquery_url": "//code.jquery.com/jquery.min.js",
"base_url": "//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/",
"css_url": None,
"theme_url": None,
"javascript_url": None,
"javascript_in_head": False,
"include_jquery": False,
"horizontal_label_class": "col-md-3",
"horizontal_field_class": "col-md-9",
"set_placeholder": True,
"required_css_class": "",
"error_css_class": "has-error",
"success_css_class": "has-success",
"formset_renderers": {"default": "bootstrap3.renderers.FormsetRenderer"},
"form_renderers": {"default": "bootstrap3.renderers.FormRenderer"},
"field_renderers": {
"default": "bootstrap3.renderers.FieldRenderer",
"inline": "bootstrap3.renderers.InlineFieldRenderer",
},
}

if DBS3_SET_REQUIRED_SET_DISABLED:
BOOTSTRAP3_DEFAULTS.update({
'set_required': True,
'set_disabled': False,
})
BOOTSTRAP3_DEFAULTS.update({"set_required": True, "set_disabled": False})

# Start with a copy of default settings
BOOTSTRAP3 = BOOTSTRAP3_DEFAULTS.copy()

# Override with user settings from settings.py
BOOTSTRAP3.update(getattr(settings, 'BOOTSTRAP3', {}))
BOOTSTRAP3.update(getattr(settings, "BOOTSTRAP3", {}))


def get_bootstrap_setting(setting, default=None):
Expand All @@ -63,56 +55,56 @@ def bootstrap_url(postfix):
"""
Prefix a relative url with the bootstrap base url
"""
return get_bootstrap_setting('base_url') + postfix
return get_bootstrap_setting("base_url") + postfix


def jquery_url():
"""
Return the full url to jQuery file to use
"""
return get_bootstrap_setting('jquery_url')
return get_bootstrap_setting("jquery_url")


def javascript_url():
"""
Return the full url to the Bootstrap JavaScript file
"""
url = get_bootstrap_setting('javascript_url')
return url if url else bootstrap_url('js/bootstrap.min.js')
url = get_bootstrap_setting("javascript_url")
return url if url else bootstrap_url("js/bootstrap.min.js")


def css_url():
"""
Return the full url to the Bootstrap CSS file
"""
url = get_bootstrap_setting('css_url')
return url if url else bootstrap_url('css/bootstrap.min.css')
url = get_bootstrap_setting("css_url")
return url if url else bootstrap_url("css/bootstrap.min.css")


def theme_url():
"""
Return the full url to the theme CSS file
"""
return get_bootstrap_setting('theme_url')
return get_bootstrap_setting("theme_url")


def get_renderer(renderers, **kwargs):
layout = kwargs.get('layout', '')
path = renderers.get(layout, renderers['default'])
layout = kwargs.get("layout", "")
path = renderers.get(layout, renderers["default"])
mod, cls = path.rsplit(".", 1)
return getattr(import_module(mod), cls)


def get_formset_renderer(**kwargs):
renderers = get_bootstrap_setting('formset_renderers')
renderers = get_bootstrap_setting("formset_renderers")
return get_renderer(renderers, **kwargs)


def get_form_renderer(**kwargs):
renderers = get_bootstrap_setting('form_renderers')
renderers = get_bootstrap_setting("form_renderers")
return get_renderer(renderers, **kwargs)


def get_field_renderer(**kwargs):
renderers = get_bootstrap_setting('field_renderers')
renderers = get_bootstrap_setting("field_renderers")
return get_renderer(renderers, **kwargs)
40 changes: 22 additions & 18 deletions bootstrap3/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,36 @@ def render_icon(icon, **kwargs):
Render a Bootstrap glyphicon icon
"""
attrs = {
'class': add_css_class(
'glyphicon glyphicon-{icon}'.format(icon=icon),
kwargs.get('extra_classes', ''),
"class": add_css_class(
"glyphicon glyphicon-{icon}".format(icon=icon),
kwargs.get("extra_classes", ""),
)
}
title = kwargs.get('title')
title = kwargs.get("title")
if title:
attrs['title'] = title
return render_tag('span', attrs=attrs)
attrs["title"] = title
return render_tag("span", attrs=attrs)


def render_alert(content, alert_type=None, dismissable=True):
"""
Render a Bootstrap alert
"""
button = ''
button = ""
if not alert_type:
alert_type = 'info'
css_classes = ['alert', 'alert-' + text_value(alert_type)]
alert_type = "info"
css_classes = ["alert", "alert-" + text_value(alert_type)]
if dismissable:
css_classes.append('alert-dismissable')
button = '<button type="button" class="close" ' + \
'data-dismiss="alert" aria-hidden="true">&times;</button>'
button_placeholder = '__BUTTON__'
return mark_safe(render_tag(
'div',
attrs={'class': ' '.join(css_classes)},
content=button_placeholder + text_value(content),
).replace(button_placeholder, button))
css_classes.append("alert-dismissable")
button = (
'<button type="button" class="close" '
+ 'data-dismiss="alert" aria-hidden="true">&times;</button>'
)
button_placeholder = "__BUTTON__"
return mark_safe(
render_tag(
"div",
attrs={"class": " ".join(css_classes)},
content=button_placeholder + text_value(content),
).replace(button_placeholder, button)
)
2 changes: 2 additions & 0 deletions bootstrap3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class BootstrapException(Exception):
"""
Any exception from this package
"""

pass


class BootstrapError(BootstrapException):
"""
Any exception that is an error
"""

pass

0 comments on commit 100737d

Please sign in to comment.