dyve / django-bootstrap-toolkit Goto Github PK
View Code? Open in Web Editor NEWBootstrap support for Django projects
License: Other
Bootstrap support for Django projects
License: Other
First of all, thank you for this cool package.
Now, we all know the {% bootstrap_stylesheet_tag %}
template tag which renders <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
But what if you want to use the responsive bootstrap css, i.e. <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css">
? You have to manually include it in the html head.
What do you think about extending the template tag to accept an optional parameter (i.e. "bootstrap-responsive.css")?
When using a standard RadioSelect widget with custom attrs like:
widget = forms.RadioSelect(attrs = {'data-control-jqgridselector': self.add_prefix(fname)})
these attrs are being ignored.
I believe it's due to the way choice fields are handled in field_choices.html template - this code takes no custom attributes into account.
This would be a feature request: why not creating a mechanism for displaying field placeholders? For example, if the developer sets something like "BOOTSTRAP_TOOLKIT_PLACEHOLDERS = True" in the settings, the toolkit puts them in the fields.
I do not know why ImportError is occurred in Python 3.3
I worked off this example to create a type-ahead input box in a template tag. Is there a way to implement this with bootstrap-toolkit?
pagination template filters should switch to a templatetag, so we will be able to pass context vars to the template rendering method. just imagine to add pagination to a page that is using custom url params (i.e. ?page=2¶m1=foo¶m2=bar), actually this is not possible!
When I load the demo project, the css does not load. The bootstrap url gets 404 response.
Edit: Didn't bother to check the closed issues. sorry. please close.
Hi!
What about client-side forms validation? Do you plan to implement it?
Hello, have any methods beautiful with django bootstrap_toolkit for upload files?
With current implementation, in horizontal form, field error message is rendered after field help. By default the help message is block, thus it causes the error message to be rendered as a new line under the help info. What I want is to display the error message at the right of a field, and help message under the field.
The "inline" in template seems to controls help layout (inline or block), as well as error (opposite to help), however in either case the help is always rendered before error.
I know I can change the rendering order in template, but still I was wondering if there is a better way to take care of it automatically, for both cases. Say if help is block and error is inline, the field error message should then be rendered before help. On the other hand, if help is inline and error is block, then help is rendered first.
Now the "inline" is hard-coded in template based on form style. It would be great if there is a way to gain more control over it (but not too much complication).
Is there a documentation available about the new widgets and attributes?
Hello Dyve, the BootstrapDateInput appends a <i class='icon-calendar'>
While is clear to us devs that it isn't a button, final users tend to click on it and nothing happens. Putting a button in place and making this button activate datepicker solve the problem.
Hello!
I used django twitter bootstrap alot and I created a live demo site on a free heroku. I think it will be useful.
The site can be accessed at: http://django-bootstrap-toolkit.herokuapp.com/
return BOOTSTRAP_BASE_URL + 'bootstrap_toolkit-' + name + '.js'
Should be:
return BOOTSTRAP_BASE_URL + 'bootstrap-' + name + '.js'
The comment above this line should also be fixed.
bootstrap_toolkit$ find . -name .DS_Store
./static/datepicker/.DS_Store
./static/.DS_Store
Maybe adding a
recursive-exclude * .DS_Store
line to MANIFEST.in
could help?
I'm not sure, but maybe it's better to use new url: 'http://twitter.github.io/bootstrap/assets/' for BOOTSTRAP_BASE_URL, not 'http://twitter.github.com/bootstrap/assets/', isn't it? please consider this issue.
Thanks for the project! I see there are a few and it is a little confusing which one to pick. However https://github.com/madisona/djbootstrap had a cool template for rendering django's messages in a template, and it would be slick to turn this into a templatetag that renders the messages this way.
Thanks for your time and any thoughts.
How do I specify a horizontal form with inline errors? I've been through the test project but I can't seem to figure it out.
It's not a big deal, but app add a lot of empty lines in HTML
class AuthorBidForm(forms.Form):
description = forms.CharField(widget=forms.Textarea)
watchperday = forms.IntegerField()
website = forms.URLField()
contacts = forms.CharField(max_length=500)
<form method="POST" action="/author/save">
{% csrf_token %}
<fieldset>
{{ form|as_bootstrap }}
<button type="submit" class="btn btn-success btn-large">Отправить</button>
</fieldset>
</form>
<form method="POST" action="/author/save">
<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='...' /></div>
<fieldset>
<div class="control-group required">
<label class="control-label" for="id_description">Description</label>
<div class="controls">
<textarea id="id_description" rows="10" cols="40" name="description"></textarea>
this causes an error(Uncaught TypeError: Object has no method 'toggle') in bootstrap-datepicker.js
in line: 323
this.picker.find('tfoot th.today')
.text(dates[this.language].today)
.toggle(this.todayBtn !== false);
Multicheckbox inputs should have a label added for the overall group, something like this in field_vertical.html:
{% if input_type == "multicheckbox" %}
<label{% if field.required %} class="required"{% endif %}>{{ field.label }}</label>
{% include "bootstrap_toolkit/field_choices.html" with type="checkbox" %}
{% include "bootstrap_toolkit/field_help.html" with inline=False %}
{% include "bootstrap_toolkit/field_errors.html" with inline=False %}
I've tried both from pypi & github. I had to copy all templates manually.
you're redefining a python reserved keyword
https://github.com/dyve/django-bootstrap-toolkit/blob/master/bootstrap_toolkit/templatetags/bootstrap_toolkit.py#L93
I have tried to run the demo.But the error occurs like the title.Then I fix the base.html, and delete the '' in the chunk of url. After that, it works ok! Does the version of django make this?
Given a form like the following:
class TypicalForm(forms.Form):
field_name = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple(),
)
and using form|as_bootstrap in the template, the form doesn't render properly. Checkboxes that were selected do not appear checked (via checked="checked" in the DOM)
Congratulations for this amazing work. But my concern is about serving all css and js files on local server instead of over internet. It might be interesting for some web applications where the server may not permitted access to internet.
I've tried
BOOTSTRAP_BASE_URL = STATIC_ROOT + 'bootstrap/' with no luck.
When use modelform, there is an exception: Caught ValueError while rendering: Expected a Field, got a <type 'str'>
Wrong checkboxes are rendered with the 'checked' attribute in the following scenario:
CHOICES = (
...
(3, '...'),
...
(33, '...'),
)
and
the_field = MultipleChoiceField(choices=CHOICES,
widget=CheckboxSelectMultiple())
If the form is submitted with 33 checked, then the rendering of this widget will also display 3 as checked. The actual QueryDict is not altered (only 33 is obtained from getlist).
On a very quick search, I believe the problem may be with:
{% if type == "checkbox" %}{% if choice_id|safe in field.value|safe %} checked{% endif %}
since, indeed, 3 is 'in' 33.
A workaround is to use values for CHOICES which do not 'confuse' the rendering logic, such as values which do not share substrings.
I have followed the tutorial with installation being successful, i have made sure i have bootstrap in my installed_Apps but wherever i reference the {% load bootstrap_toolkit %} tag. i can see in my logs that the .css file does not get referenced nor in firebug chrome inspector. There are no errors yet none of the bootstrap .class files work.
For example i want to use the span css style for a div and nothing works.
This awesome django toolkit should support the InlineFormset, to be able to do:
{{myinlineformset|as_bootstrap}}
Please host an online example of the capabilities of this toolkit!
Love it!
templatetags/bootstrap_toolkit.py:125
@register.filter
def bootstrap_input_type(field):
"""
Return input type to use for field
"""
try:
widget = field.field.widget
except:
raise ValueError("Expected a Field, got a %s" % type(field))
input_type = getattr(widget.attrs, 'bootstrap_input_type', None)
input_type is always None at this point. There is no way to override this property. Maybe you should use get on attrs dict?
is there aversion to support right to left languages
I have been able to do a work around (by looping) but figured a nice feature would be to be able to do something like:
{{ formset|as_bootstrap }}
The management_form would need to get rendered as well as that is the normal expectation of:
{{ formset }}
Perhaps you could also make this work too:
{{ formset.management_form }}
{{ formset.forms|as_bootstrap }}
Thanks!
This one commit is missing bb60eb5 in code , where it is?
Or i miss and do not understand something?
I think it would be pretty great if the package would include the original Twitter Bootstrap source code and would be simply configurable to use django_assets or similar assets manager to create and minify bundles of CSS/LESS files automatically.
The datepicker creates dates in the format dd-mm-yyyy, but django complains it's invalid. dd.mm.yyyy works
I just tried to create a form with a single checkbox and an inline help_text next to it, like this:
[x] This is the help_text
As I understood bootstrap_toolkit a tried the following:
{{ my_form.thefield|as_bootstrap:'inline' }}
However, this didn't work like I expected, instead I got this result:
[x]
This is the help_text
Getting curious, I look in the source for field_inline.html
and saw {% include "bootstrap_toolkit/field_help.html" with inline=True %}
and in the field_help.html
template I found the {% if inline %}
condition with an <span class="help-inline">
in the body of it. Checking with the bootstrap documentation this is the correct class for an inline help_text directly next to a field. Putting some additional text within the true- and false-branch of the condition I discovered that, the true-branch is never run.
At first, this made no sense to me. After all, the template is included with inline=True
so inline should be true, or shouldn't it? As it turns out, no! Turns out that True
is not a literal in the Django template syntax. Instead True
is resolved as a variable for the current context where it (most likely) doesn't exist so TEMPLATE_STRING_IF_INVALID is outputted. TEMPLATE_STRING_IF_INVALID in turn defaults to an empty string and an empty string is false. So even if you pass inline=True
inline is actually false.
In short: It's currently not possible to format fields with 'help-inline' class because the code is not reachable.
Hi,
small thing - when showing forms w. checkboxes and using the form in a template doing the normal django-all-the-way stuff a checkbox field shows the label and the checkbox. Now, when I use the 'as_bootstrap' filter I get the label text repeated next to the checkbox.
{{ form }} --> text box
{{ form | as_bootstrap }} --> text box text
Anyway to get around this? or perhaps would make sense to ensure same behavioral as with default django forms.
Thanks for great code, saves me tons of time !!!!
/ Jens
Changes are needed for upgrading to bootstrap 2.0.0:
Duplicate for #71 because I made typo in commit statement. For future reference.
Commit d02b56a introduced Django < 1.5 incompatibility. In particular, this:
from django.utils.html import format_html_join
would like to have {% bootstrap_javascript_tag %} and the styles tag be https by request
Django's default form templates, such as as_p, as_ul and as_table, mark the help_text as 'safe', so you can use HTML in your help_text.
This behavior is broken when adopting bootstrap-toolkit.
I suggest adding '|safe' to the help_text in templates/field_help.html
As the demo project seems not to use a multi line textarea I am wondering how this could be achieved?
Hi there,
looks like twitter has been fiddling with urls. Right now this does not work:
BOOTSTRAP_BASE_URL = getattr(settings, 'BOOTSTRAP_BASE_URL',
'http://twitter.github.com/bootstrap/assets/'
)
but this does:
BOOTSTRAP_BASE_URL = getattr(settings, 'BOOTSTRAP_BASE_URL',
'http://twitter.github.io/bootstrap/assets/'
)
cheers,
Andy.
https://github.com/dyve/django-bootstrap-toolkit/blob/master/bootstrap_toolkit/widgets.py#L84
This line impedes a language that has a suffix (child Language) to be added to the media, just adding the language "mother"
as in my case never adds "pt-BR" only "pt"
suggestion to fix the bug:
lang = translation.get_language()
lang = "%s-%s" % (lang.split('-')[0].lower(), lang.split('-')[1].upper()) if '-' in lang else lang
When setting a form field of type ChoiceField to readonly the generated form field is in a wrong state.
Example of currently generated select field:
<select readonly="True" name="groupType" id="id_groupType">
<option value="Primary">Primary</option>
<option value="Secondary" selected="selected">Secondary</option>
</select>
which should be changed into:
<select readonly="True" name="groupType" id="id_groupType" disabled>
<option value="Primary">Primary</option>
<option value="Secondary" selected="selected">Secondary</option>
</select>
to include the "disabled" tag.
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.