Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use src/django_bootstrap4 structure #806

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pip install django-bootstrap4
```python
INSTALLED_APPS = (
# ...
"bootstrap4",
"django_bootstrap4",
# ...
)
```
Expand All @@ -45,7 +45,7 @@ INSTALLED_APPS = (
## Example template

```jinja
{% load bootstrap4 %}
{% load django_bootstrap4 %}

{# Display a form #}

Expand Down
2 changes: 1 addition & 1 deletion docs/example_template.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. code:: django

{# Load the tag library #}
{% load bootstrap4 %}
{% load django_bootstrap4 %}

{# Load CSS and JavaScript #}
{% bootstrap_css %}
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Be sure to use ``virtualenv`` if you develop python projects.

Add to INSTALLED_APPS in your ``settings.py``:

``'bootstrap4',``
``'django_bootstrap4',``

After installation, the :doc:`quickstart` will get you on your way to using ``django-bootstrap4``.
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Quickstart

After :doc:`installation`, you can use ``django-bootstrap4`` in your templates.:

Load the ``bootstrap4`` library and use the ``bootstrap_*`` tags:
Load the ``django_bootstrap4`` library and use the ``bootstrap_*`` tags:


Example template
Expand Down
8 changes: 4 additions & 4 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ The ``BOOTSTRAP4`` dict variable contains these settings and defaults:

# Renderers (only set these if you have studied the source and understand the inner workings)
'formset_renderers':{
'default': 'bootstrap4.renderers.FormsetRenderer',
'default': 'django_bootstrap4.renderers.FormsetRenderer',
},
'form_renderers': {
'default': 'bootstrap4.renderers.FormRenderer',
'default': 'django_bootstrap4.renderers.FormRenderer',
},
'field_renderers': {
'default': 'bootstrap4.renderers.FieldRenderer',
'inline': 'bootstrap4.renderers.InlineFieldRenderer',
'default': 'django_bootstrap4.renderers.FieldRenderer',
'inline': 'django_bootstrap4.renderers.InlineFieldRenderer',
},
}
2 changes: 1 addition & 1 deletion example/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.admin.widgets import AdminSplitDateTime
from django.forms import BaseFormSet, formset_factory

from bootstrap4.widgets import RadioSelectButtonGroup
from django_bootstrap4.widgets import RadioSelectButtonGroup

RADIO_CHOICES = (("1", "Radio 1"), ("2", "Radio 2"))

Expand Down
4 changes: 2 additions & 2 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ""))

# Include BOOTSTRAP4_FOLDER in path
BOOTSTRAP4_FOLDER = os.path.abspath(os.path.join(BASE_DIR, "..", "bootstrap4"))
BOOTSTRAP4_FOLDER = os.path.abspath(os.path.join(BASE_DIR, "..", "django_bootstrap4"))
if BOOTSTRAP4_FOLDER not in sys.path:
sys.path.insert(0, BOOTSTRAP4_FOLDER)

Expand Down Expand Up @@ -121,7 +121,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.admin",
"bootstrap4",
"django_bootstrap4",
"app",
)

Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/bootstrap.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block bootstrap4_content %}
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/bootstrap.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends 'bootstrap4/bootstrap4.html' %}
{% extends 'django_bootstrap4/bootstrap4.html' %}

{% block bootstrap4_title %}{% block title %}{% endblock %}{% endblock %}
2 changes: 1 addition & 1 deletion example/templates/app/form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Forms
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form_by_field.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Forms
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form_horizontal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Forms
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form_inline.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Forms
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/form_with_files.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Forms
Expand Down
2 changes: 1 addition & 1 deletion example/templates/app/formset.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Formset
Expand Down
4 changes: 2 additions & 2 deletions example/templates/app/home.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends 'app/base.html' %}
{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}django-bootstrap4{% endblock %}

{% block content %}
This is <em>bootstrap4</em> for <strong>Django</strong>.
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion example/templates/app/misc.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Miscellaneous
Expand Down
4 changes: 2 additions & 2 deletions example/templates/app/pagination.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'app/base.html' %}

{% load bootstrap4 %}
{% load django_bootstrap4 %}

{% block title %}
Pagination
Expand All @@ -22,4 +22,4 @@

{% bootstrap_pagination lines url="/pagination?page=1" size="large" %}

{% endblock %}
{% endblock %}
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ unfixable = [
]

[tool.ruff.lint.isort]
known-first-party = ["bootstrap4", "app"]
known-first-party = ["django_bootstrap4", "app"]
known-third-party = ["django"]

[tool.coverage.run]
branch = true
source = ["src", "tests"]

[tool.coverage.paths]
package = ["src/bootstrap4", "*/django_bootstrap4/src/bootstrap4"]
package = ["src/django_bootstrap4", "*/django_bootstrap4/src/bootstrap4"]

[tool.coverage.report]
show_missing = true
Expand All @@ -104,6 +104,3 @@ docs = [
"myst-parser>=3.0.1",
"sphinx>=7.1.2",
]

[tool.hatch.build.targets.wheel]
packages = ["src/bootstrap4"]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@
"required_css_class": "",
"error_css_class": "is-invalid",
"success_css_class": "is-valid",
"formset_renderers": {"default": "bootstrap4.renderers.FormsetRenderer"},
"form_renderers": {"default": "bootstrap4.renderers.FormRenderer"},
"formset_renderers": {"default": "django_bootstrap4.renderers.FormsetRenderer"},
"form_renderers": {"default": "django_bootstrap4.renderers.FormRenderer"},
"field_renderers": {
"default": "bootstrap4.renderers.FieldRenderer",
"inline": "bootstrap4.renderers.InlineFieldRenderer",
"default": "django_bootstrap4.renderers.FieldRenderer",
"inline": "django_bootstrap4.renderers.InlineFieldRenderer",
},
}


def get_bootstrap_setting(name, default=None):
"""Read a setting."""
# Start with a copy of default settings
BOOTSTRAP4 = BOOTSTRAP4_DEFAULTS.copy()
bootstrap4 = BOOTSTRAP4_DEFAULTS.copy()

# Override with user settings from settings.py
BOOTSTRAP4.update(getattr(settings, "BOOTSTRAP4", {}))
bootstrap4.update(getattr(settings, "BOOTSTRAP4", {}))

# Update use_i18n
BOOTSTRAP4["use_i18n"] = i18n_enabled()
bootstrap4["use_i18n"] = i18n_enabled()

return BOOTSTRAP4.get(name, default)
return bootstrap4.get(name, default)


def jquery_url():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _

from bootstrap4.utils import render_tag
from django_bootstrap4.utils import render_tag

from .text import text_value

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def render_errors(self):
formset_errors = self.get_formset_errors()
if formset_errors:
return render_template_file(
"bootstrap4/form_errors.html",
"django_bootstrap4/form_errors.html",
context={"errors": formset_errors, "form": self.formset, "layout": self.layout},
)
return ""
Expand Down Expand Up @@ -194,7 +194,7 @@ def render_errors(self, type="all"):

if form_errors:
return render_template_file(
"bootstrap4/form_errors.html",
"django_bootstrap4/form_errors.html",
context={"errors": form_errors, "form": self.form, "layout": self.layout, "type": type},
)

Expand Down Expand Up @@ -404,7 +404,7 @@ def append_help(self, html):
field_help = self.field_help or None
if field_help:
help_html = render_template_file(
"bootstrap4/field_help_text.html",
"django_bootstrap4/field_help_text.html",
context={
"field": self.field,
"field_help": field_help,
Expand All @@ -419,7 +419,7 @@ def append_errors(self, html):
field_errors = self.field_errors
if field_errors:
errors_html = render_template_file(
"bootstrap4/field_errors.html",
"django_bootstrap4/field_errors.html",
context={
"field": self.field,
"field_errors": field_errors,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
{% load bootstrap4 %}
{% load django_bootstrap4 %}
{% if 'use_i18n'|bootstrap_setting %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n bootstrap4 %}
{% load i18n %}
{% load django_bootstrap4 %}
{% for message in messages %}
<div class="{{ message|bootstrap_message_classes }} alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="{% trans 'close' %}">&#215;</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load bootstrap4 %}
{% load django_bootstrap4 %}
{% with bpurl=bootstrap_pagination_url|default:"" %}

<ul class="{{ pagination_css_classes }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def bootstrap_formset_errors(*args, **kwargs):
The formset that is being rendered

layout
Context value that is available in the template ``bootstrap4/form_errors.html`` as ``layout``.
Context value that is available in the template ``django_bootstrap4/form_errors.html`` as ``layout``.

**Usage**::

Expand Down Expand Up @@ -443,7 +443,7 @@ def bootstrap_form_errors(*args, **kwargs):
:default: ``'all'``

layout
Context value that is available in the template ``bootstrap4/form_errors.html`` as ``layout``.
Context value that is available in the template ``django_bootstrap4/form_errors.html`` as ``layout``.

**Usage**::

Expand Down Expand Up @@ -797,7 +797,7 @@ def bootstrap_messages(context, *args, **kwargs):
we have to set the jquery parameter too when using the
bootstrap_javascript tag.

Uses the template ``bootstrap4/messages.html``.
Uses the template ``django_bootstrap4/messages.html``.

**Tag name**::

Expand All @@ -820,10 +820,10 @@ def bootstrap_messages(context, *args, **kwargs):
if isinstance(context, Context):
context = context.flatten()
context.update({"message_constants": message_constants})
return render_template_file("bootstrap4/messages.html", context=context)
return render_template_file("django_bootstrap4/messages.html", context=context)


@register.inclusion_tag("bootstrap4/pagination.html")
@register.inclusion_tag("django_bootstrap4/pagination.html")
def bootstrap_pagination(page, **kwargs):
"""
Render pagination for a page.
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions src/bootstrap4/widgets.py → src/django_bootstrap4/widgets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.forms import RadioSelect
class RadioSelectButtonGroup(RadioSelect):
"""
Render a Bootstrap 4 set of buttons horizontally instead of typical radio buttons.
Much more mobile friendly.
"""
template_name = "bootstrap4/widgets/radio_select_button_group.html"
from django.forms import RadioSelect


class RadioSelectButtonGroup(RadioSelect):
"""
Render a Bootstrap 4 set of buttons horizontally instead of typical radio buttons.

Much more mobile friendly.
"""

template_name = "django_bootstrap4/widgets/radio_select_button_group.html"
2 changes: 1 addition & 1 deletion tests/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"django.contrib.staticfiles",
"django.contrib.gis",
# Our tests
"bootstrap4",
"django_bootstrap4",
"tests",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.admin.widgets import AdminSplitDateTime
from django.contrib.gis import forms as gisforms

from bootstrap4.widgets import RadioSelectButtonGroup
from django_bootstrap4.widgets import RadioSelectButtonGroup

RADIO_CHOICES = (("1", "Radio 1"), ("2", "Radio 2"))

Expand Down
Loading
Loading