django-bs

Bootstrap integration for django using widget templates
git clone https://git.ce9e.org/django-bs.git

commit
fa71b40a87ce2ef14e4359e493f318c8fda5fe4d
parent
e3a11d8093eb6b78c33fdaba0714cbebbd13155e
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-01-26 10:58
add some missing options for compat

Diffstat

M django-bs4/templates/bs4/field.html 28 ++++++++++++++++++++++++----
M django-bs4/templates/bs4/pagination.html 8 ++++----
M django-bs4/templatetags/bootstrap4.py 25 ++++++++++++++++++++++---

3 files changed, 50 insertions, 11 deletions


diff --git a/django-bs4/templates/bs4/field.html b/django-bs4/templates/bs4/field.html

@@ -1,12 +1,32 @@
    1    -1 <div class="form-group">
   -1     1 <div class="{{ form_group_class }}">
    2     2     {% if check %}
    3     3         <div class="form-check">
    4     4             {{ field }}
    5    -1             <label for="{{ field.id_for_label }}" class="form-check-label">{{ field.label }}</label>
   -1     5             {% if show_label %}
   -1     6                 <label for="{{ field.id_for_label }}" class="form-check-label {% ifequal show_label 'sr-only' %}sr-only{% endifequal %}">{{ field.label }}</label>
   -1     7             {% endif %}
    6     8         </div>
    7     9     {% else %}
    8    -1         <label for="{{ field.id_for_label }}">{{ field.label }}</label>
    9    -1         {{ field }}
   -1    10         {% if show_label %}
   -1    11             <label {% ifequal show_label 'sr-only' %}class="sr-only"{% endifequal %} for="{{ field.id_for_label }}">{{ field.label }}</label>
   -1    12         {% endif %}
   -1    13         {% if addon_before or addon_after %}
   -1    14             <div class="input-group">
   -1    15                 {% if addon_before %}
   -1    16                     <div class="input-group-prepend">
   -1    17                         <span class="input-group-text">{{ addon_before }}</span>
   -1    18                     </div>
   -1    19                 {% endif %}
   -1    20                 {{ field }}
   -1    21                 {% if addon_after %}
   -1    22                     <div class="input-group-append">
   -1    23                         <span class="input-group-text">{{ addon_after }}</span>
   -1    24                     </div>
   -1    25                 {% endif %}
   -1    26             </div>
   -1    27         {% else %}
   -1    28             {{ field }}
   -1    29         {% endif %}
   10    30     {% endif %}
   11    31     {% if field.help_text %}
   12    32         <small class="form-text text-muted">{{ field.help_text }}</small>

diff --git a/django-bs4/templates/bs4/pagination.html b/django-bs4/templates/bs4/pagination.html

@@ -1,15 +1,15 @@
    1     1 {% load i18n bootstrap4 %}
    2     2 
    3    -1 <ul class="pagination">
   -1     3 <ul class="pagination {% if size %}pagination-{{ size }}{% endif %}">
    4     4     <li class="page-item {% if not page.has_previous %}disabled{% endif %}">
    5    -1         <a class="page-link" {% if page.has_previous %}href="{% bootstrap_url_replace_param url 'page' page.previous_page_number %}"{% endif %}>
   -1     5         <a class="page-link" {% if page.has_previous %}href="{% bootstrap_url_replace_param url parameter_name page.previous_page_number %}"{% endif %}>
    6     6             {% trans 'Previous' %}
    7     7         </a>
    8     8     </li>
    9     9 
   10    10     {% for i in pages_shown %}
   11    11         <li class="page-item {% if i == page.number %}active{% endif %}" {% if i == page.number %}aria-current="page"{% endif %}>
   12    -1             <a class="page-link" href="{% bootstrap_url_replace_param url 'page' i %}">
   -1    12             <a class="page-link" href="{% bootstrap_url_replace_param url parameter_name i %}">
   13    13                 {% if has_previous and forloop.first %}
   14    14                     &hellip;
   15    15                 {% elif has_next and forloop.last %}
@@ -22,7 +22,7 @@
   22    22     {% endfor %}
   23    23 
   24    24     <li class="page-item {% if not page.has_next %}disabled{% endif %}">
   25    -1         <a class="page-link" {% if page.has_next %}href="{% bootstrap_url_replace_param url 'page' page.next_page_number %}"{% endif %}>
   -1    25         <a class="page-link" {% if page.has_next %}href="{% bootstrap_url_replace_param url parameter_name page.next_page_number %}"{% endif %}>
   26    26             {% trans 'Next' %}
   27    27         </a>
   28    28     </li>

diff --git a/django-bs4/templatetags/bootstrap4.py b/django-bs4/templatetags/bootstrap4.py

@@ -43,7 +43,13 @@ def bootstrap_url_replace_param(url, key, value):
   43    43 
   44    44 
   45    45 @register.inclusion_tag('bs4/field.html')
   46    -1 def bootstrap_field(boundfield):
   -1    46 def bootstrap_field(
   -1    47     boundfield,
   -1    48     addon_before=None,
   -1    49     addon_after=None,
   -1    50     show_label=True,
   -1    51     form_group_class='form-group',
   -1    52 ):
   47    53     widget = boundfield.field.widget
   48    54     return {
   49    55         'field': boundfield,
@@ -51,6 +57,10 @@ def bootstrap_field(boundfield):
   51    57             getattr(widget, 'input_type', None) in ['checkbox', 'radio']
   52    58             and not getattr(widget, 'option_template_name', None)
   53    59         ),
   -1    60         'addon_before': addon_before,
   -1    61         'addon_after': addon_after,
   -1    62         'show_label': show_label,
   -1    63         'form_group_class': form_group_class,
   54    64     }
   55    65 
   56    66 
@@ -67,7 +77,14 @@ def bootstrap_messages(context):
   67    77 
   68    78 
   69    79 @register.inclusion_tag('bs4/pagination.html', takes_context=True)
   70    -1 def bootstrap_pagination(context, page, pages_to_show=11):
   -1    80 def bootstrap_pagination(
   -1    81     context,
   -1    82     page,
   -1    83     pages_to_show=11,
   -1    84     url=None,
   -1    85     size=None,
   -1    86     parameter_name='page',
   -1    87 ):
   71    88     first = max(1, page.number - pages_to_show // 2)
   72    89     last = min(page.paginator.num_pages, first + pages_to_show)
   73    90     first = max(1, last - pages_to_show)
@@ -77,5 +94,7 @@ def bootstrap_pagination(context, page, pages_to_show=11):
   77    94         'pages_shown': range(first, last + 1),
   78    95         'has_previous': first > 1,
   79    96         'has_next': last < page.paginator.num_pages,
   80    -1         'url': context['request'].get_full_path(),
   -1    97         'url': url or context['request'].get_full_path(),
   -1    98         'size': size,
   -1    99         'parameter_name': parameter_name,
   81   100     }