django-bootstrap3-datetimepicker
django-bootstrap3-datetimepicker copied to clipboard
Why do widgets not specify static libraries?
By specifying the media for a form widget, django takes care of making sure all of the necessary static files are call using {form.media}}
. Without this we either need to guess which files the bootstrap-datepicker
files are required on or load them on every page call, even when a form isn't available and if a user has no form access privileges.
Would you be open to a pull request that added these back?
I'd be happy to accept a pull request which added a DateTimePickerWithAssets
class which subclassed DateTimePicker
but adds the Media
class.
You can see here for the code which was removed.
This leads to a problem as the Media
class needs to reference the location of the assets so those files really need to be included here.
I have a pathological aversion to including static assets in projects which only reference them. It's mixing code with references and it leads to tears.
However there's a solution to this: add a grablib.yml
file to this project which defines which assets are required, then check they're downloaded in setup.py
. You'll also need to add a reference to those files in setup.py
so they're included in the installed package.
(haven't tried this so it might need some checking)
grablib.yml, should look something like
download_root: bootstrap3_datetime/static/bootstrap3_datetime/
download:
'GITHUB/moment/moment/2.13.0/min/moment-with-locales.min.js': 'js/'
'GITHUB/Eonasdan/bootstrap-datetimepicker/4.15.35/build/js/bootstrap-datetimepicker.min.js': 'js/'
'GITHUB/Eonasdan/bootstrap-datetimepicker/4.15.35/build/css/bootstrap-datetimepicker.css': 'css/'
4.15.35
is the version we're currently using at TutorCruncher, however newer version will probably work fine too.
update: add moment which i forgot.