• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zostera / django-bootstrap4 / 5398229605

pending completion
5398229605

push

github

dyve
Remove Django 2 support

277 of 344 branches covered (80.52%)

Branch coverage included in aggregate %.

689 of 773 relevant lines covered (89.13%)

4.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/bootstrap4/bootstrap.py
1
from importlib import import_module
5✔
2

3
from django.conf import settings
5✔
4

5
BOOTSTRAP4_DEFAULTS = {
5✔
6
    "css_url": {
7
        "href": "https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css",
8
        "integrity": "sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N",
9
        "crossorigin": "anonymous",
10
    },
11
    "javascript_url": {
12
        "url": "https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js",
13
        "integrity": "sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct",
14
        "crossorigin": "anonymous",
15
    },
16
    "theme_url": None,
17
    "jquery_url": {
18
        "url": "https://code.jquery.com/jquery-3.5.1.min.js",
19
        "integrity": "sha384-ZvpUoO/+PpLXR1lu4jmpXWu80pZlYUAfxl5NsBMWOEPSjUn/6Z/hRTt8+pR6L4N2",
20
        "crossorigin": "anonymous",
21
    },
22
    "jquery_slim_url": {
23
        "url": "https://code.jquery.com/jquery-3.5.1.slim.min.js",
24
        "integrity": "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj",
25
        "crossorigin": "anonymous",
26
    },
27
    "javascript_in_head": False,
28
    "include_jquery": False,
29
    "use_i18n": False,
30
    "horizontal_label_class": "col-md-3",
31
    "horizontal_field_class": "col-md-9",
32
    "set_placeholder": True,
33
    "required_css_class": "",
34
    "error_css_class": "is-invalid",
35
    "success_css_class": "is-valid",
36
    "formset_renderers": {"default": "bootstrap4.renderers.FormsetRenderer"},
37
    "form_renderers": {"default": "bootstrap4.renderers.FormRenderer"},
38
    "field_renderers": {
39
        "default": "bootstrap4.renderers.FieldRenderer",
40
        "inline": "bootstrap4.renderers.InlineFieldRenderer",
41
    },
42
}
43

44

45
def get_bootstrap_setting(name, default=None):
5✔
46
    """Read a setting."""
47
    # Start with a copy of default settings
48
    BOOTSTRAP4 = BOOTSTRAP4_DEFAULTS.copy()
5✔
49

50
    # Override with user settings from settings.py
51
    BOOTSTRAP4.update(getattr(settings, "BOOTSTRAP4", {}))
5✔
52

53
    # Update use_i18n
54
    BOOTSTRAP4["use_i18n"] = i18n_enabled()
5✔
55

56
    return BOOTSTRAP4.get(name, default)
5✔
57

58

59
def jquery_url():
5✔
60
    """Return the full url to jQuery library file to use."""
61
    return get_bootstrap_setting("jquery_url")
5✔
62

63

64
def jquery_slim_url():
5✔
65
    """Return the full url to slim jQuery library file to use."""
66
    return get_bootstrap_setting("jquery_slim_url")
5✔
67

68

69
def include_jquery():
5✔
70
    """
71
    Return whether to include jquery.
72

73
    Setting could be False, True|'full', or 'slim'
74
    """
75
    return get_bootstrap_setting("include_jquery")
5✔
76

77

78
def javascript_url():
5✔
79
    """Return the full url to the Bootstrap JavaScript file."""
80
    return get_bootstrap_setting("javascript_url")
5✔
81

82

83
def css_url():
5✔
84
    """Return the full url to the Bootstrap CSS file."""
85
    return get_bootstrap_setting("css_url")
5✔
86

87

88
def theme_url():
5✔
89
    """Return the full url to the theme CSS file."""
90
    return get_bootstrap_setting("theme_url")
5✔
91

92

93
def i18n_enabled():
5✔
94
    """Return the projects i18n setting."""
95
    return getattr(settings, "USE_I18N", False)
5✔
96

97

98
def get_renderer(renderers, **kwargs):
5✔
99
    layout = kwargs.get("layout", "")
5✔
100
    path = renderers.get(layout, renderers["default"])
5✔
101
    mod, cls = path.rsplit(".", 1)
5✔
102
    return getattr(import_module(mod), cls)
5✔
103

104

105
def get_formset_renderer(**kwargs):
5✔
106
    renderers = get_bootstrap_setting("formset_renderers")
5✔
107
    return get_renderer(renderers, **kwargs)
5✔
108

109

110
def get_form_renderer(**kwargs):
5✔
111
    renderers = get_bootstrap_setting("form_renderers")
5✔
112
    return get_renderer(renderers, **kwargs)
5✔
113

114

115
def get_field_renderer(**kwargs):
5✔
116
    renderers = get_bootstrap_setting("field_renderers")
5✔
117
    return get_renderer(renderers, **kwargs)
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc