mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-20 15:51:36 +02:00
changes
This commit is contained in:
0
app/apps/common/widgets/crispy/__init__.py
Normal file
0
app/apps/common/widgets/crispy/__init__.py
Normal file
65
app/apps/common/widgets/crispy/submit.py
Normal file
65
app/apps/common/widgets/crispy/submit.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from crispy_forms.layout import BaseInput
|
||||
|
||||
|
||||
class NoClassSubmit(BaseInput):
|
||||
"""
|
||||
Used to create a Submit button descriptor for the {% crispy %} template tag.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
template: str
|
||||
The default template which this Layout Object will be rendered
|
||||
with.
|
||||
field_classes: str
|
||||
CSS classes to be applied to the ``<input>``.
|
||||
input_type: str
|
||||
The ``type`` attribute of the ``<input>``.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The name attribute of the button.
|
||||
value : str
|
||||
The value attribute of the button.
|
||||
css_id : str, optional
|
||||
A custom DOM id for the layout object. If not provided the name
|
||||
argument is slugified and turned into the id for the submit button.
|
||||
By default None.
|
||||
css_class : str, optional
|
||||
Additional CSS classes to be applied to the ``<input>``. By default
|
||||
None.
|
||||
template : str, optional
|
||||
Overrides the default template, if provided. By default None.
|
||||
**kwargs : dict, optional
|
||||
Additional attributes are passed to `flatatt` and converted into
|
||||
key="value", pairs. These attributes are added to the ``<input>``.
|
||||
|
||||
Examples
|
||||
--------
|
||||
Note: ``form`` arg to ``render()`` is not required for ``BaseInput``
|
||||
inherited objects.
|
||||
|
||||
>>> submit = Submit('Search the Site', 'search this site')
|
||||
>>> submit.render("", "", Context())
|
||||
'<input type="submit" name="search-the-site" value="search this site" '
|
||||
'class="btn btn-primary" id="submit-id-search-the-site"/>'
|
||||
|
||||
>>> submit = Submit('Search the Site', 'search this site', css_id="custom-id",
|
||||
css_class="custom class", my_attr=True, data="my-data")
|
||||
>>> submit.render("", "", Context())
|
||||
'<input type="submit" name="search-the-site" value="search this site" '
|
||||
'class="btn btn-primary custom class" id="custom-id" data="my-data" my-attr/>'
|
||||
|
||||
Usually you will not call the render method on the object directly. Instead
|
||||
add it to your ``Layout`` manually or use the `add_input` method::
|
||||
|
||||
class ExampleForm(forms.Form):
|
||||
[...]
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.add_input(Submit('submit', 'Submit'))
|
||||
"""
|
||||
|
||||
input_type = "submit"
|
||||
field_classes = ""
|
||||
54
app/apps/common/widgets/tom_select.py
Normal file
54
app/apps/common/widgets/tom_select.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from django.forms import widgets, SelectMultiple
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class TomSelect(widgets.Select):
|
||||
def __init__(
|
||||
self,
|
||||
attrs=None,
|
||||
remove_button=False,
|
||||
remove_button_text=_("Remove"),
|
||||
create=False,
|
||||
create_text=_("Add"),
|
||||
clear_button=True,
|
||||
clear_text=_("Clear"),
|
||||
no_results_text=_("No results..."),
|
||||
checkboxes=False,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(attrs, *args, **kwargs)
|
||||
self.remove_button = remove_button
|
||||
self.remove_button_text = remove_button_text
|
||||
self.clear_button = clear_button
|
||||
self.create = create
|
||||
self.create_text = create_text
|
||||
self.clear_text = clear_text
|
||||
self.no_results_text = no_results_text
|
||||
self.checkboxes = checkboxes
|
||||
|
||||
def build_attrs(self, base_attrs, extra_attrs=None):
|
||||
attrs = super().build_attrs(base_attrs, extra_attrs)
|
||||
|
||||
attrs["data-txt-no-results"] = self.no_results_text
|
||||
|
||||
if self.remove_button:
|
||||
attrs["data-remove-button"] = "true"
|
||||
attrs["data-txt-remove"] = self.remove_button_text
|
||||
|
||||
if self.create:
|
||||
attrs["data-create"] = "true"
|
||||
attrs["data-txt-create"] = self.create_text
|
||||
|
||||
if self.clear_button:
|
||||
attrs["data-clear-button"] = "true"
|
||||
attrs["data-txt-clear"] = self.clear_text
|
||||
|
||||
if self.checkboxes:
|
||||
attrs["data-checkboxes"] = "true"
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
class TomSelectMultiple(SelectMultiple, TomSelect):
|
||||
pass
|
||||
Reference in New Issue
Block a user