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

zostera / django-bootstrap4 / 5399170771

pending completion
5399170771

push

github

dyve
Remove support for Python 3.7 (EOL)

272 of 344 branches covered (79.07%)

Branch coverage included in aggregate %.

704 of 793 relevant lines covered (88.78%)

3.55 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
4✔
2

3
from django.conf import settings
4✔
4

5
BOOTSTRAP4_DEFAULTS = {
4✔
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):
4✔
46
    """Read a setting."""
47
    # Start with a copy of default settings
48
    BOOTSTRAP4 = BOOTSTRAP4_DEFAULTS.copy()
4✔
49

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

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

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

58

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

63

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

68

69
def include_jquery():
4✔
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")
4✔
76

77

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

82

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

87

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

92

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

97

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

104

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

109

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

114

115
def get_field_renderer(**kwargs):
4✔
116
    renderers = get_bootstrap_setting("field_renderers")
4✔
117
    return get_renderer(renderers, **kwargs)
4✔
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