Skip to main content

A Django widget for the Tempus Dominus Bootstrap 4 DateTime picker.

Project description

Django Tempus Dominus

Django Tempus Dominus provides Django widgets for the Tempus Dominus Bootstrap 4 DateTime date and time picker.

A Note About the Future of This Package

The parent project to this package, Tempus Dominus, is being reworked. This package will not receive any updates until the parent project releases version 6, which will deprecate jQuery and Bootstrap as dependencies. When that occurs, we'll update this package to support v6.

Installation

  • From PyPI: pip install django-tempus-dominus

Then add tempus_dominus to INSTALLED_APPS in your Django settings.

Usage & Django Settings

The following settings are available:

  • TEMPUS_DOMINUS_LOCALIZE (default: False): if True, widgets will be translated to the selected browser language and use the localized date and time formats.
  • TEMPUS_DOMINUS_INCLUDE_ASSETS (default: True): if True, loads Tempus Dominus and moment JS and CSS from Cloudflare's CDN, otherwise loading the JS and CSS are up to you.

Three widgets are provided:

  • DatePicker
    • Defaults to YYYY-MM-DD
    • Defaults to L if TEMPUS_DOMINUS_LOCALIZE is True
  • DateTimePicker
    • Defaults to YYYY-MM-DD HH:mm:ss
    • Defaults to L LTS if TEMPUS_DOMINUS_LOCALIZE is True
  • TimePicker
    • Defaults to HH:mm:ss
    • Defaults to LTS if TEMPUS_DOMINUS_LOCALIZE is True

In your Django form, you can use the widgets like this:

from django import forms
from tempus_dominus.widgets import DatePicker, TimePicker, DateTimePicker

class MyForm(forms.Form):
    date_field = forms.DateField(widget=DatePicker())
    date_field_required_with_min_max_date = forms.DateField(
        required=True,
        widget=DatePicker(
            options={
                'minDate': '2009-01-20',
                'maxDate': '2017-01-20',
            },
        ),
        initial='2013-01-01',
    )
    """
    In this example, the date portion of `defaultDate` is irrelevant;
    only the time portion is used. The reason for this is that it has
    to be passed in a valid MomentJS format. This will default the time
    to be 14:56:00 (or 2:56pm).
    """
    time_field = forms.TimeField(
        widget=TimePicker(
            options={
                'enabledHours': [9, 10, 11, 12, 13, 14, 15, 16],
                'defaultDate': '1970-01-01T14:56:00'
            },
            attrs={
                'input_toggle': True,
                'input_group': False,
            },
        ),
    )
    datetime_field = forms.DateTimeField(
        widget=DateTimePicker(
            options={
                'useCurrent': True,
                'collapse': False,
            },
            attrs={
                'append': 'fa fa-calendar',
                'icon_toggle': True,
            }
        ),
    )

Then in your template, include jQuery, {{ form.media }}, and render the form:

<html>
  <head>
    {# Include FontAwesome; required for icon display #}
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">

    {# Include Bootstrap 4 and jQuery #}
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

    {# Django Tempus Dominus assets are included in `{{ form.media }}` #}
    {{ form.media }}
  </head>

  <body>
    <div class="container">
      <div class="row">
        <div class="col">
          <form method="post" action=".">
            {% csrf_token %}
            {{ form.as_p }}
          </form>
        </div>
      </div>
    </div>
  </body>
</html>

Widget Options

  • options (dictionary): This dictionary will be passed to Tempus Dominus. A full list of options is available here.
  • input_toggle (boolean, default True): Controls whether clicking on the input field toggles the datepicker popup. Typically is set to False when an icon is in use.
  • input_group (boolean, default True): Whether to include a Bootstrap 4 input-group around the picker.
  • size (string): Controls the size of the input group (small or large). Defaults to the default size.
  • prepend (string): Name of a Font Awesome icon to prepend to the input field (fa fa-calendar).
  • append (string): Name of a Font Awesome icon to append to the input field (fa fa-calendar).
  • icon_toggle (boolean, default True): Controls whether clicking on the icon toggles the datepicker popup. Typically is set to False when an icon is in use.

Change Log

  • 5.1.2.14: Bug fix for MomentJS times with certain granularities.
  • 5.1.2.13: Add deprecation notice to README.
  • 5.1.2.12: Fix issues with initial values not showing up in TimePicker.
  • 5.1.2.11: Fix deprecations introduced in Django 3.0 (force_text -> force_str).
  • 5.1.2.9: Include JS assets from the parent form if TEMPUS_DOMINUS_INCLUDE_ASSETS is False. Switch to using setuptools-scm instead of MANIFEST.in.
  • 5.1.2.7 / 5.1.2.8: Bug fix: if a field had a hyphen in the id, this would cause an error in the JS function. Force hyphens to underscores.
  • 5.1.2.6: Include a defer function to play more nicely with different jQuery configurations.
  • 5.1.2.5: Typo bug in INCLUDE_ASSETS; switch to Black code formatting.
  • 5.1.2.4: Add support for disabling the Bootstrap input-group with a new option. Fix an icon.
  • 5.1.2.3: Fix a bug which caused a page lag when switching locales.
  • 5.1.2.2: Fix a bug with duplicate DOM IDs in template.
  • 5.1.2.1: Fix a bug with time formatting to use ISO time format (T12:34:56)
  • 5.1.2.0: Upgrade Tempus Dominus to 5.1.2. Support for new widget attributes (size, prepend, append, input_toggle, icon_toggle, class). DatePicker now closes after losing focus, and widget attributes are properly passed.
  • 5.0.1.5: Fix to ensure options are passed in proper JSON.
  • 5.0.1.4: Include template in the MANIFEST.in file.
  • 5.0.1.3: Add setting to exclude CDN CSS and JS assets. Add initial test suite.
  • 5.0.1.2: Documentation clean up.
  • 5.0.1.1: Option to use l10n and i18n to all pickers.
  • 5.0.1.0: Upgrade to Tempus Dominus full release version 5.0.1. Fix bug for populating initial values.
  • 0.1.2: UX enhancement: auto-dismiss dialog if the input loses focus.
  • 0.1.1: Bug fixes.
  • 0.1.0: Initial release.

Maintainers

This package is largely maintained by the staff of Wharton Research Data Services. We are thrilled that The Wharton School allows us a certain amount of time to contribute to open-source projects. We add features as they are necessary for our projects, and try to keep up with Issues and Pull Requests as best we can. Due to time constraints (our full time jobs!), Feature Requests without a Pull Request may not be implemented, but we are always open to new ideas and grateful for contributions and our package users.

Contributors & DjangoCon US Sprinters (Thank You!)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tempus-dominus-5.1.2.14.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

django_tempus_dominus-5.1.2.14-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file django-tempus-dominus-5.1.2.14.tar.gz.

File metadata

  • Download URL: django-tempus-dominus-5.1.2.14.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for django-tempus-dominus-5.1.2.14.tar.gz
Algorithm Hash digest
SHA256 6d766148302333d1ce97859bbb02f2c24e193895ed5f001bfd40f4fffdd7096e
MD5 f3fde8c023527393713847e057b4fd2f
BLAKE2b-256 7b0b41c43c24af842a1887dc7daf60fbc1fffb21d9fa99934242a7decf52e2ad

See more details on using hashes here.

File details

Details for the file django_tempus_dominus-5.1.2.14-py3-none-any.whl.

File metadata

  • Download URL: django_tempus_dominus-5.1.2.14-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for django_tempus_dominus-5.1.2.14-py3-none-any.whl
Algorithm Hash digest
SHA256 f766d2d2c2885276cd0f39dbfadd2416d661a48dc992a0f0ee09a3461d484bbd
MD5 e8ed5916e6d365a665b4c8135141d942
BLAKE2b-256 4ecb67e21fb858938fb8bd33fb94c5930a4232aead94afe25c794aeeb2573ffb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page