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

monim67 / django-bootstrap-datepicker-plus / 7860847020

11 Feb 2024 08:43AM CUT coverage: 100.0%. Remained the same
7860847020

push

github

monim67
Fix clear input on form reset, fix #110

142 of 142 relevant lines covered (100.0%)

5.0 hits per line

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

100.0
/src/bootstrap_datepicker_plus/settings.py
1
"""Package settings."""
5✔
2

3
import functools
5✔
4
from typing import Any, Dict, Optional, Tuple
5✔
5

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

8
try:
5✔
9
    from pydantic import Field, validator
5✔
10
    from pydantic.env_settings import BaseSettings, SettingsSourceCallable
5✔
11
except Exception:  # pragma: no cover
12
    from pydantic.v1 import Field, validator  # type: ignore
13
    from pydantic.v1.env_settings import (  # type: ignore
14
        BaseSettings,
15
        SettingsSourceCallable,
16
    )
17

18
from .schemas import WidgetOptions, WidgetVariant
5✔
19

20

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

24

25
class WidgetSettings(BaseSettings):  # pyright: ignore
5✔
26
    """Settings to customize input widgets."""
5✔
27

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

54
    @validator("addon_icon_classes")
5✔
55
    def _merge_with_default_dict_value(cls, v, field):  # type: ignore
5✔
56
        return {**field.default, **v}
5✔
57

58
    class Config:
5✔
59
        """Customize pydantic config."""
5✔
60

61
        env_prefix = "BOOTSTRAP_DATEPICKER_PLUS_"
5✔
62

63
        @classmethod
5✔
64
        def customise_sources(
5✔
65
            cls,
66
            init_settings: SettingsSourceCallable,  # pyright: ignore
67
            env_settings: SettingsSourceCallable,  # pyright: ignore
68
            file_secret_settings: SettingsSourceCallable,  # pyright: ignore
69
        ) -> Tuple[SettingsSourceCallable, ...]:  # pyright: ignore
70
            """Add django settings as config source."""
71
            return (
5✔
72
                init_settings,
73
                env_settings,
74
                file_secret_settings,
75
                _django_settings_source,
76
            )
77

78

79
@functools.lru_cache(maxsize=1)
5✔
80
def get_widget_settings() -> WidgetSettings:
5✔
81
    """Initialize and return WidgetSettings."""
82
    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