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

monim67 / django-bootstrap-datepicker-plus / 7165058428

11 Dec 2023 08:56AM UTC coverage: 97.887%. First build
7165058428

Pull #108

github

web-flow
Merge e06945f0d into 93ec63025
Pull Request #108: PEP8: Avoid bare exceptions

0 of 1 new or added line in 1 file covered. (0.0%)

139 of 142 relevant lines covered (97.89%)

4.89 hits per line

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

92.11
/src/bootstrap_datepicker_plus/settings.py
1
"""Package settings."""
5✔
2
import functools
5✔
3
from typing import Any, Dict, Optional, Tuple
5✔
4

5
from django.conf import settings as django_settings
5✔
6

7
try:
5✔
8
    from pydantic import Field, validator
5✔
9
    from pydantic.env_settings import BaseSettings, SettingsSourceCallable
5✔
NEW
10
except ImportError:
×
11
    from pydantic.v1.env_settings import BaseSettings, SettingsSourceCallable  # type: ignore
×
12
    from pydantic.v1 import Field, validator  # type: ignore
×
13

14
from .schemas import WidgetOptions, WidgetVariant
5✔
15

16

17
def _django_settings_source(settings: BaseSettings) -> Dict[str, Any]:
5✔
18
    return getattr(django_settings, "BOOTSTRAP_DATEPICKER_PLUS", {})
5✔
19

20

21
class WidgetSettings(BaseSettings):
5✔
22
    """Settings to customize input widgets."""
5✔
23

24
    template_name: Optional[str]
5✔
25
    attrs: Dict[str, str] = {}
5✔
26
    options: WidgetOptions = {}
5✔
27
    variant_options: Dict[WidgetVariant, WidgetOptions] = {}
5✔
28
    addon_icon_classes: Dict[WidgetVariant, str] = {
5✔
29
        WidgetVariant.date: "bi-calendar",
30
        WidgetVariant.time: "bi-clock",
31
        WidgetVariant.datetime: "bi-calendar",
32
        WidgetVariant.month: "bi-calendar",
33
        WidgetVariant.year: "bi-calendar",
34
    }
35
    momentjs_url: Optional[
5✔
36
        str
37
    ] = "https://cdn.jsdelivr.net/npm/moment@2.29.4/min/moment-with-locales.min.js"
38
    datetimepicker_js_url: Optional[
5✔
39
        str
40
    ] = "https://cdn.jsdelivr.net/npm/eonasdan-bootstrap-datetimepicker@4.17.49/build/js/bootstrap-datetimepicker.min.js"
41
    datetimepicker_css_url: Optional[
5✔
42
        str
43
    ] = "https://cdn.jsdelivr.net/npm/eonasdan-bootstrap-datetimepicker@4.17.49/build/css/bootstrap-datetimepicker.min.css"
44
    bootstrap_icon_css_url: Optional[
5✔
45
        str
46
    ] = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css"
47
    app_static_url = "https://cdn.jsdelivr.net/gh/monim67/django-bootstrap-datepicker-plus@5.0.2/src/bootstrap_datepicker_plus/static/bootstrap_datepicker_plus/"
5✔
48
    debug: bool = Field(default_factory=lambda: getattr(django_settings, "DEBUG", True))
5✔
49

50
    @validator("addon_icon_classes")
5✔
51
    def _merge_with_default_dict_value(cls, v, field):  # type: ignore
5✔
52
        return {**field.default, **v}
5✔
53

54
    class Config:
5✔
55
        """Customize pydantic config."""
5✔
56

57
        env_prefix = "BOOTSTRAP_DATEPICKER_PLUS_"
5✔
58

59
        @classmethod
5✔
60
        def customise_sources(
5✔
61
            cls,
62
            init_settings: SettingsSourceCallable,
63
            env_settings: SettingsSourceCallable,
64
            file_secret_settings: SettingsSourceCallable,
65
        ) -> Tuple[SettingsSourceCallable, ...]:
66
            """Add django settings as config source."""
67
            return (
5✔
68
                init_settings,
69
                env_settings,
70
                file_secret_settings,
71
                _django_settings_source,
72
            )
73

74

75
@functools.lru_cache(maxsize=1)
5✔
76
def get_widget_settings() -> WidgetSettings:
5✔
77
    """Initialize and return WidgetSettings."""
78
    return WidgetSettings()
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