zostera / django-bootstrap5 Goto Github PK
View Code? Open in Web Editor NEWBootstrap 5 for Django
License: BSD 3-Clause "New" or "Revised" License
Bootstrap 5 for Django
License: BSD 3-Clause "New" or "Revised" License
The template tag buttons...endbuttons
does not do anything that you couldn't do manually. We should either make it useful or drop it.
There is too much mark_safe
and not enough format_html
in the code.
Allow form and field definition to affect bootstrap_form
and bootstrap_field
parameters.
Tested using Django 2.2 on Windows and Ubuntu 20.04
Using regular Django fields works just fine, but a bootstrap_field like {% bootstrap_field form.image_upload show_label=False %}
introduces a <br>
tag between the label and the input fields. It seems to happen both with the FileInput / ClearableFileInput widgets as far as I can tell.
Make sure we know which input types support floating labels. Currently we check for not matching an input type, which will give problems with range, date, time, et cetera.
Currently it is not possible to render checkboxes inline as in Bootstrap documentation: https://getbootstrap.com/docs/5.1/forms/checks-radios/#inline
I would need this option in the bootstrap_field
template tag.
Example:
{% bootstrap_form form exclude="ignore_field" %}
field renderer returns empty (unsafe) string when encountering the ignored field. When concatenated with safe text, the resulting string becomes unsafe and renders escaped html string into template instead rendering the form.
The buttons
tag was introduced to align automatically generated buttons with the fields in the form.
In Bootstrap 5, this magic is no longer necessary. Also, the output of the tag was hard to predict. It's better to let users style their own buttons, with the option to use the bootstrap_button
tag.
Reference: https://getbootstrap.com/docs/5.0/forms/form-control/#file-input
Note that we also have clearable file inputs.
Extended support for Django 3.0 stopped on April 1, 2021.
Floating labels do not affect the layout of the entire form, just how certain input types are rendered. We should not use the layout setting for this.
Hi. Sometimes it's important to change the global form/field layout to 'horizontal' or 'floating'
Here is pull request that implements it.
Our custom widget doesn't render because the template_name
is overwritten in renderers.py
.
render_tag
should not try to form attributes:
> render_tag('div', {'class': '{tag}'})
expected: <div class="{tag}"></div>
actual: <div class="div"></div>
> render_tag('div', {'class': '{foo}'})
expected: <div class="{foo}"></div>
actual: KeyError
Message containing hyperlinks is rendered with html being escaped.
With regular updates, dependancies on Bootstrap versions and issues whether or not something is a breaking change, CalVer is a better fit for versioning. For example, YY.0M.MICRO.
See also zostera/django-bootstrap4#177
A call to bootstrap_button
should allow HTML attributes.
{% bootstrap_form form layout='inline' show_label=False %}
It looks like inline is not being evaluated correctly.
using layout='horizontal' has the expected render
Update this method to fix it.
def get_checkbox_classes(self):
"""Return CSS classes for checkbox."""
classes = ["form-check"]
if self.checkbox_style == "switch":
classes.append("form-switch")
if self.checkbox_layout == "inline":
classes.append("form-check-inline")
if self.field_errors:
classes.append(self.error_css_class)
elif self.field.form.is_bound:
classes.append(self.success_css_class)
return merge_css_classes(*classes)
if it was me, I would add a method like this to make getting valid/invalid easier:
def get_valid(self):
if self.field_errors:
return self.error_css_class
elif self.field.form.is_bound:
return self.success_css_class
return None # or return '' for concatenation
I'm using Material Design Bootstrap (MDB) and there is very stylish form field layout variant in use.
If you would allow layout='outline' and the use the 'form-outline' class instead of 'form-floating' it would work fine.
The problem is, that the label has to be rendered after the input widget (like as in floating layout). So there is no easy workaround for this.
Documentation is outdated, check parameters for bootstrap_field, bootstrap_form and bootstrap_formset.
Check docstrings, especially public functions, methods and classes.
The document says addon_after_class
will work, but there is no handling logics at all.
Note. Here is how django-bootstrap4 are handling it.
https://github.com/zostera/django-bootstrap4/blob/adc99067b2459d1dafac9904db6f8748acaefe85/src/bootstrap4/renderers.py#L388
In django-bootstrap4, bootstrap_field field form_group_class='foo'
will use a form group class of foo
.
In django-bootstrap5, bootstrap_field field wrapper_class='foo'
will use a wrapper class of foo mb-3
.
This breaks cases where you need to remove the default margin.
A possible workaround is to use layout='inline'
, but that adds unrelated styling which might cause other issues.
As a user of Conda environments on Windows 10,
I want to extend C:\Users\Test\Programming\anaconda3\envs\Django\lib\site-packages\django_bootstrap5\src\django_bootstrap5\templates\django_bootstrap5\bootstrap5.html
by a template inside some app of my Django project; eg C:\Users\Test\Programming\team\project\app\templates\app\base.html
.
How can I do it?
Exception Type: NoReverseMatch
Exception Value: Reverse for 'home' not found. 'home' is not a valid view function or pattern name.
Exception Location: C:\Users\Test\Programming\anaconda3\envs\Django\lib\site-packages\django\urls\resolvers.py, line 694, in _reverse_with_prefix
Error during template rendering
In template C:\Users\Test\Programming\anaconda3\envs\Django\lib\site-packages\django_bootstrap5\templates\django_bootstrap5\bootstrap5.html, error at line 11
<input class="form-check-input #ADD ERROR HERE"
on each form-check-input the error should be displayed
I'll update this if I figure out where this code gets generated.
It's super hack-y but this works added to the end of renderers.py
html = format_html(
'<{tag} class="{wrapper_classes}">{label}{field_with_help_and_errors}</{tag}>',
tag=WRAPPER_TAG,
wrapper_classes=self.get_wrapper_classes(),
label=label,
field_with_help_and_errors=field_with_help_and_errors,
)
if isinstance(self.widget,CheckboxSelectMultiple):
addition = None
if self.field_errors:
addition = self.error_css_class
elif self.field.form.is_bound:
addition = self.success_css_class
if addition:
html = html.replace('<input class="form-check-input','<input class="form-check-input {addition}'.format(addition=addition))
html = format_html(html)
return html
I just started using django_bootstrap5 in my projects where I'm using Material Design Bootstrap (MDB).
Unfortunately they use a different 'prefix' for (at least the event names). For example they use 'data-mdb-dismiss' instead of the 'data-bs-dismiss'. This has the effect, that for example the closing button on alerts does not work.
As the rendering of alerts is done in a function and not with a template, I have no chance to change it.
I don't know what the best solution for this problem is. But one could be to make this prefix ('mdb' or 'bs' or ..) configurable.
For sure there are be more places in the source code where MDB will have effects.
Django 3.2 was released on April 6, 2021.
See: https://docs.djangoproject.com/en/3.2/releases/3.2/
https://getbootstrap.com/docs/5.0/getting-started/download/#cdn-via-jsdelivr
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
self.field_errors is always none for CheckboxInput even when the field is required
The BootstrapException classes have nu added value or function. Standard classes offer more clarity.
Upon running the example server, and navigating to "form_inline" I got this error page:
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/form_inline |
Django Version: | 3.1.7 |
Exception Type: | AttributeError |
Exception Value: | module 'django_bootstrap5.renderers' has no attribute 'InlineFieldRenderer' |
Exception Location: | /Users/username/.pyenv/versions/3.9.1/lib/python3.9/site-packages/django_bootstrap5/core.py, line 72, in get_renderer |
Python Executable: | /Users/username/.pyenv/versions/3.9.1/bin/python |
Python Version: | 3.9.1 |
Python Path: | ['/Users/username/django-bootstrap5/django_bootstrap5', '/Users/jdhemsath1/django-bootstrap5/example', '/Users/username/.pyenv/versions/3.9.1/lib/python39.zip', '/Users/jdhemsath1/.pyenv/versions/3.9.1/lib/python3.9', '/Users/username/.pyenv/versions/3.9.1/lib/python3.9/lib-dynload', '/Users/username/.pyenv/versions/3.9.1/lib/python3.9/site-packages'] |
Server time: | Wed, 24 Mar 2021 00:53:53 +0100 |
I tried adding and deleting 'field_renderers': { 'default': 'django_bootstrap5.renderers.FieldRenderer', 'inline': 'django_bootstrap5.renderers.InlineFieldRenderer', },
to the settings.py file in the Example folder, with no change.
Looking at the source renderers.py it looks like there is no class for InlineFieldRenderer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.