Skip to content

Commit e9bb8e7

Browse files
committed
Docs update:: Walkthrough, Troubleshooting, Template customizing
1 parent 1de65bc commit e9bb8e7

File tree

8 files changed

+343
-8
lines changed

8 files changed

+343
-8
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ If applicable, add screenshots to help explain your problem.
2929
- Bootstrap version [e.g. 3/4]
3030
- jQuery version [e.g. 1.7.1]
3131

32-
**Additional context**
33-
Add any other context about the problem here.
32+
[x] I have followed the [configuration instructions][configuration_page] and checked out the
33+
[common error troubleshooting][troubleshooting_page] page.
34+
35+
[configuration_page]: https://monim67.github.io/django-bootstrap-datepicker-plus/configure/
36+
[troubleshooting_page]: https://django-bootstrap-datepicker-plus.readthedocs.io/en/latest/Troubleshooting.html

.github/ISSUE_TEMPLATE/custom.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ of the HTML source of the page is http://...
3434
- Bootstrap version [e.g. 3/4]
3535
- jQuery version [e.g. 1.7.1]
3636

37-
**Additional context**
38-
Add any other context about the problem here.
37+
[x] I have followed the [configuration instructions][configuration_page] and checked out the
38+
[common error troubleshooting][troubleshooting_page] page.
39+
40+
[configuration_page]: https://monim67.github.io/django-bootstrap-datepicker-plus/configure/
41+
[troubleshooting_page]: https://django-bootstrap-datepicker-plus.readthedocs.io/en/latest/Troubleshooting.html

docs/Getting_Started.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Add ``bootstrap_datepicker_plus`` to the list of ``INSTALLED_APPS`` in your ``se
2727
'bootstrap_datepicker_plus',
2828
]
2929
30-
This installation instruction assumes you have ``jQuery`` and Bootstrap JS/CSS files present in your template
31-
and you are using ``form.media`` in your django template. If not you should checkout our
32-
`configuration instructions <https://monim67.github.io/django-bootstrap-datepicker-plus/configure/>`__
33-
which covers almost everything you need to get the widget running.
30+
.. warning:: This installation instruction assumes you have ``jQuery`` and Bootstrap JS/CSS files present
31+
in your template and you are using ``form.media`` in your django template. If not you should checkout our
32+
`configuration instructions <https://monim67.github.io/django-bootstrap-datepicker-plus/configure/>`__
33+
which covers almost everything you need to get the widget running.

docs/Template_Customizing.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Template Customizing
2+
--------------------
3+
4+
5+
The calendar is not yet available for customizing, but the input field template can be customized. You can use a custom template for the input field to render.
6+
7+
8+
.. code:: python
9+
10+
# File: forms.py
11+
from bootstrap_datepicker_plus import DatePickerInput
12+
from django import forms
13+
14+
class MyDatePickerInput(DatePickerInput):
15+
template_name = 'my_app/date-picker.html'
16+
17+
class ToDoForm(forms.Form):
18+
date = forms.DateField(
19+
widget=MyDatePickerInput(format='%m/%d/%Y')
20+
)
21+
22+
Now you have to create a HTML template for date-picker input.
23+
24+
.. code-block:: HTML
25+
26+
<!-- File: my_app/templates/my_app/date-picker.html -->
27+
28+
<h5>This is a customized date-picker</h5>
29+
<div class="input-group date my-custom-class">
30+
{% include "bootstrap_datepicker_plus/input.html" %}
31+
<div class="input-group-addon input-group-append">
32+
<div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
33+
</div>
34+
</div>
35+
36+
You can also create a template for TimePickerInput and create a custom time-picker input.
37+
38+
.. code-block:: HTML
39+
40+
<!-- File: my_app/templates/my_app/time-picker.html -->
41+
42+
<h5>This is a customized time-picker</h5>
43+
<div class="input-group date my-custom-class">
44+
{% include "bootstrap_datepicker_plus/input.html" %}
45+
<div class="input-group-addon input-group-append">
46+
<div class="input-group-text"><i class="glyphicon glyphicon-time"></i></div>
47+
</div>
48+
</div>

docs/Troubleshooting.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
TroubleShooting
2+
---------------
3+
4+
5+
If the date-picker calendar does not show up, possibility is you missed something of the installation procedure.
6+
Check out the following errors and you might find your solution.
7+
8+
Errors displayed on browser screen
9+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
11+
.. error:: TemplateSyntaxError: bootstrap3/4 is not a registered tag library.
12+
13+
This means you did not install django-bootstrap3 and add it to the list of INSTALLED_APPS. Checkout our
14+
`configuration instructions <configuration_page_>`_ to see how to do it.
15+
16+
.. error:: TemplateDoesNotExist bootstrap_datepicker_plus/date-picker.html
17+
18+
This means you did not install django-bootstrap-datepicker-plus and add it to the list of INSTALLED_APPS.
19+
Checkout our `configuration instructions <configuration_page_>`_ to see how to do it.
20+
21+
.. error:: TemplateSyntaxError: Invalid block tag 'bootstrap_form'.
22+
23+
You have not loaded bootstrap3/bootstrap4 tag. Checkout our
24+
`configuration instructions <configuration_page_>`_ to see how to do it.
25+
26+
Errors displayed on browser console
27+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
Sometimes the page loads just fine, but errors are logged into browser's developer console.
29+
30+
.. error:: Uncaught TypeError: Cannot read property 'fn' of undefined
31+
.. error:: Uncaught Error: Bootstrap's JavaScript requires jQuery
32+
.. error:: Uncaught ReferenceError: jQuery is not defined
33+
.. error:: Uncaught bootstrap-datetimepicker requires jQuery to be loaded first
34+
35+
The above errors are listed in the console if you forget to add jQuery to your template. Bootstrap's
36+
JavaScript should be preceded by jQuery, otherwise Bootstrap will throw an error. Checkout our
37+
`configuration instructions <configuration_page_>`_ to see various options to do it.
38+
39+
.. error:: Uncaught TypeError: Cannot read property 'Constructor' of undefined
40+
41+
You forgot to add bootstrap JavaScript file to your template, make sure you have both Bootstrap JavasScript
42+
and CSS files to your included in your template. Checkout our `configuration instructions <configuration_page_>`_
43+
to see various options to do it.
44+
45+
No errors anywhere, but the calendar does not show up!
46+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
You forgot to add ``{{ form.media }}`` to your template. Checkout our `configuration instructions <configuration_page_>`_
48+
to learn more about this issue.
49+
50+
My error is not listed here
51+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
Please `create an issue <create_issue_page_>`_ on the project's GitHub repository providing as much information
53+
you can.
54+
55+
56+
.. _create_issue_page: https://github.com/monim67/django-bootstrap-datepicker-plus/issues/new/choose
57+
.. _configuration_page: https://monim67.github.io/django-bootstrap-datepicker-plus/configure/

docs/Usage.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ Usage
22
-----
33

44

5+
Usage in Generic View
6+
^^^^^^^^^^^^^^^^^^^^^^
7+
8+
.. code:: python
9+
10+
# File: views.py
11+
from bootstrap_datepicker_plus import DateTimePickerInput
12+
from django.views import generic
13+
from .models import Question
14+
15+
class CreateView(generic.edit.CreateView):
16+
model = Question
17+
fields = ['question_text', 'pub_date']
18+
def get_form(self):
19+
form = super().get_form()
20+
form.fields['pub_date'].widget = DateTimePickerInput()
21+
return form
22+
23+
524
Custom Form usage
625
^^^^^^^^^^^^^^^^^
726

@@ -27,6 +46,7 @@ Model Form usage
2746
2847
# File: forms.py
2948
from bootstrap_datepicker_plus import DatePickerInput
49+
from .models import Event
3050
from django import forms
3151
3252
class EventForm(forms.ModelForm):

docs/Walkthrough.rst

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
Quick Walkthrough Tutorial
2+
--------------------------
3+
4+
This tutorial will take off where django official tutorial `Writing your first Django app, part 4 <django_tutorial_04_>`_
5+
left off. The Question model has a datetime field. We are going to create a page to add new poll questions
6+
and a page to edit them.
7+
8+
9+
10+
.. tip:: We are going to use Bootstrap 4 here, if you are using Bootstrap 3 just replace the 4's with 3's in the
11+
codes and instructions below.
12+
13+
Open up your console and install the following packages:
14+
15+
::
16+
17+
pip install django-bootstrap4
18+
pip install django-bootstrap-datepicker-plus
19+
20+
21+
Add these packages to the list of INSTALLED_APPS as you did here on `Tutorial 02 <django_tutorial_activating_model_>`_.
22+
23+
.. code:: python
24+
25+
# FIle: mysite/settings.py
26+
INSTALLED_APPS = [
27+
'polls.apps.PollsConfig',
28+
'django.contrib.admin',
29+
'django.contrib.auth',
30+
'django.contrib.contenttypes',
31+
'django.contrib.sessions',
32+
'django.contrib.messages',
33+
'django.contrib.staticfiles',
34+
"bootstrap4",
35+
"bootstrap_datepicker_plus",
36+
]
37+
38+
39+
CreateView for Question model
40+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
42+
Add a CreateView for Question model. The ``get_form`` method is used to specify widgets on the form fields.
43+
44+
.. code:: python
45+
46+
# FIle: polls/views.py
47+
from django.http import HttpResponseRedirect
48+
from django.shortcuts import get_object_or_404, render
49+
from django.urls import reverse
50+
from django.views import generic
51+
52+
from bootstrap_datepicker_plus import DateTimePickerInput
53+
54+
from .models import Choice, Question
55+
56+
57+
class CreateView(generic.edit.CreateView):
58+
model = Question
59+
fields = ['question_text', 'pub_date']
60+
def get_form(self):
61+
form = super().get_form()
62+
form.fields['pub_date'].widget = DateTimePickerInput()
63+
return form
64+
65+
# Leave other classes unchanged
66+
67+
68+
Create a template named question_form.html in your app to render the form. If you use a different name you have to
69+
set template_name property of CreateView class in your views.py file above.
70+
71+
.. code:: html
72+
73+
<!-- File: polls/templates/polls/question_form.html -->
74+
{% load bootstrap4 %}
75+
{% bootstrap_css %}
76+
{% bootstrap_javascript jquery='full' %}
77+
{{ form.media }}
78+
79+
<form method="post">{% csrf_token %}
80+
{% bootstrap_form form %}
81+
<input type="submit" value="Save">
82+
</form>
83+
84+
Add a ``get_absolute_url`` method to your Question model.
85+
86+
.. code:: python
87+
88+
# FIle: polls/models.py
89+
import datetime
90+
91+
from django.db import models
92+
from django.urls import reverse
93+
from django.utils import timezone
94+
95+
96+
class Question(models.Model):
97+
question_text = models.CharField(max_length=200)
98+
pub_date = models.DateTimeField('date published')
99+
100+
def __str__(self):
101+
return self.question_text
102+
103+
def was_published_recently(self):
104+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
105+
106+
def get_absolute_url(self):
107+
return reverse('polls:detail', kwargs={'pk': self.pk})
108+
109+
110+
Add an urlpattern for creating new poll question.
111+
112+
.. code:: python
113+
114+
# FIle: polls/urls.py
115+
from django.urls import path
116+
117+
from . import views
118+
119+
app_name = 'polls'
120+
urlpatterns = [
121+
path('', views.IndexView.as_view(), name='index'),
122+
path('create', views.CreateView.as_view(), name='create'),
123+
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
124+
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
125+
path('<int:question_id>/vote/', views.vote, name='vote'),
126+
]
127+
128+
129+
Now run the developement server and visit http://localhost:8000/polls/create, if everything works fine
130+
you can wrap up your template in proper HTML.
131+
132+
.. code:: html
133+
134+
<!DOCTYPE html>
135+
<html lang="en">
136+
<head>
137+
<meta charset="UTF-8">
138+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
139+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
140+
<title>Document</title>
141+
{% load bootstrap4 %}
142+
{% bootstrap_css %}
143+
{% bootstrap_javascript jquery='full' %}
144+
{{ form.media }}
145+
</head>
146+
<body>
147+
<div class="container">
148+
<div class="col-md-3">
149+
<form method="post">{% csrf_token %}
150+
{% bootstrap_form form %}
151+
{% buttons %}
152+
<button type="submit" class="btn btn-primary">Save</button>
153+
{% endbuttons %}
154+
</form>
155+
</div>
156+
</div>
157+
</body>
158+
</html>
159+
160+
161+
UpdateView for Question model
162+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163+
164+
We can now add a page to update a poll question. First we add an UpdateView to our views.
165+
166+
.. code:: python
167+
168+
# FIle: add these to polls/views.py
169+
class UpdateView(generic.edit.UpdateView):
170+
model = Question
171+
fields = ['question_text', 'pub_date']
172+
def get_form(self):
173+
form = super().get_form()
174+
form.fields['pub_date'].widget = DateTimePickerInput()
175+
return form
176+
177+
Then add a urlpattern to access the question update page.
178+
179+
.. code:: python
180+
181+
# FIle: polls/urls.py
182+
from django.urls import path
183+
184+
from . import views
185+
186+
app_name = 'polls'
187+
urlpatterns = [
188+
path('', views.IndexView.as_view(), name='index'),
189+
path('create', views.CreateView.as_view(), name='create'),
190+
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
191+
path('<int:pk>/update', views.UpdateView.as_view(), name='update'),
192+
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
193+
path('<int:question_id>/vote/', views.vote, name='vote'),
194+
]
195+
196+
That's it, run the developement server and visit http://localhost:8000/polls/1/update, if everything works fine
197+
you can checkout usage in custom form and model form in Usage page of the docs.
198+
199+
200+
.. _django_tutorial_04: https://docs.djangoproject.com/en/2.1/intro/tutorial04/
201+
.. _django_tutorial_activating_model: https://docs.djangoproject.com/en/2.1/intro/tutorial02/#activating-models

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ Demo
3535
:caption: Contents:
3636

3737
Getting_Started
38+
Walkthrough
3839
Usage
40+
Template_Customizing
41+
Troubleshooting
3942
Contributing
4043

4144

0 commit comments

Comments
 (0)