Source code for berhoel.django.media.widgets

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""Widgets for media.
"""

# Django library imports.
from django.forms import DateInput, DateTimeInput

__date__ = "2022/08/11 21:32:21 hoel"
__author__ = "Berthold Höllmann"
__copyright__ = "Copyright © 2020 by Berthold Höllmann"
__credits__ = ["Berthold Höllmann"]
__maintainer__ = "Berthold Höllmann"
__email__ = "berhoel@gmail.com"


[docs]class BootstrapDatePickerInput(DateInput): template_name = "widgets/bootstrap_datepicker.html"
[docs] def get_context(self, name: str, value: str, attrs: dict) -> dict: datepicker_id = f"datepicker_{name}" if attrs is None: attrs = dict() attrs.update( { "data-target": f"#{datepicker_id}", "class": "form-control datepicker-input", } ) context = super().get_context(name, value, attrs) context["widget"]["datepicker_id"] = datepicker_id return context
[docs]class BootstrapDateTimePickerInput(DateTimeInput): template_name = "widgets/bootstrap_datetimepicker.html"
[docs] def get_context(self, name: str, value: str, attrs: dict) -> dict: datetimepicker_id = f"datetimepicker_{name}" if attrs is None: attrs = dict() attrs.update( { "data-target": f"#{datetimepicker_id}", "class": "form-control datetimepicker-input", } ) context = super().get_context(name, value, attrs) context["widget"]["datetimepicker_id"] = datetimepicker_id return context
# Local Variables: # mode: python # compile-command: "poetry run tox" # time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\"" # End: