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 feature 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
): ifTrue
, widgets will be translated to the selected browser language and use the localized date and time formats.TEMPUS_DOMINUS_INCLUDE_ASSETS
(default:True
): ifTrue
, loads Tempus Dominus andmoment
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
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
DateTimePicker
- Defaults to
YYYY-MM-DD HH:mm:ss
- Defaults to
L LTS
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
TimePicker
- Defaults to
HH:mm:ss
- Defaults to
LTS
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
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, defaultTrue
): 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, defaultTrue
): Whether to include a Bootstrap 4input-group
around the picker.size
(string): Controls the size of the input group (small
orlarge
). 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, defaultTrue
): Controls whether clicking on the icon toggles the datepicker popup. Typically is set to False when an icon is in use.
Maintainers
- Timothy Allen (https://github.com/FlipperPA)
- Ian Stewart (https://github.com/ianastewart)
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!)
- Stéphane "Twidi" Angel (https://github.com/twidi)
- Jake Bell (https://github.com/theunraveler)
- Bartłomiej Biernacki (https://github.com/pax0r)
- John Carroll (https://github.com/johnnyporkchops)
- Bryan Collazo (https://github.com/bcollazo)
- Katherine Dey (https://github.com/deyspring)
- Tiffany Huang (https://github.com/tiff8433)
- Václav 'ax' Hůla (https://github.com/AxTheB)
- Adam Johnson (https://github.com/adamchainz)
- Manuel Kappler (https://github.com/manuelkappler)
- Kenneth Love (https://github.com/kennethlove)
- Donna St. Louis (https://github.com/dcstlouis)
- Ryan Sullivan (https://github.com/rgs258)
- Kevan Swanberg (https://github.com/kevswanberg)
- Nick Träger (https://github.com/nick-traeger)
- waymou (https://github.com/waymao)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-tempus-dominus-5.1.2.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ef793d5163c6dbbe0291fbbac608f416a776c0a747c87742e89129361a5670a |
|
MD5 | d8697262864801ddb5918f8349be00f9 |
|
BLAKE2b-256 | 0e9a1019dc8c3333a4f5a3e27ddd2933304db4d48e8702817270ba98934ee883 |
Hashes for django_tempus_dominus-5.1.2.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af39178247a41951085c9803e53620b0c315916d51816babf7bb993b87f10de4 |
|
MD5 | 2f4cf495b8ff868ed27b2dbb10795046 |
|
BLAKE2b-256 | e146b5afc7c8f27f267a820adf5473175ee42f46df6478dde1d5a91c456cf09c |