Debian Codegraph @

django_widget_tweaks.egg-info/PKG-INFO

raw
1 Metadata-Version: 1.1
2 Name: django-widget-tweaks
3 Version: 1.4.8
4 Summary: Tweak the form field rendering in templates, not in python-level form definitions.
5 Home-page: https://github.com/jazzband/django-widget-tweaks
6 Author: Mikhail Korobov
7 Author-email: [email protected]
8 License: MIT license
9 Description: ====================
10 django-widget-tweaks
11 ====================
12
13 .. image:: https://jazzband.co/static/img/badge.svg
14 :target: https://jazzband.co/
15 :alt: Jazzband
16
17 .. image:: https://img.shields.io/pypi/v/django-widget-tweaks.svg
18 :target: https://pypi.python.org/pypi/django-widget-tweaks
19 :alt: PyPI Version
20
21 .. image:: https://img.shields.io/travis/jazzband/django-widget-tweaks/master.svg
22 :target: http://travis-ci.org/jazzband/django-widget-tweaks
23 :alt: Build Status
24
25
26 Tweak the form field rendering in templates, not in python-level
27 form definitions. Altering CSS classes and HTML attributes is supported.
28
29 That should be enough for designers to customize field presentation (using
30 CSS and unobtrusive javascript) without touching python code.
31
32 License is MIT.
33
34 Installation
35 ============
36
37 You can get Django Widget Tweaks by using pip::
38
39 $ pip install django-widget-tweaks
40
41 To enable `widget_tweaks` in your project you need to add it to `INSTALLED_APPS` in your projects
42 `settings.py` file::
43
44 INSTALLED_APPS = [
45 ...
46 'widget_tweaks',
47 ...
48 ]
49
50 Usage
51 =====
52
53 This app provides two sets of tools that may be used together or standalone:
54
55 1. a ``render_field`` template tag for customizing form fields by using an
56 HTML-like syntax.
57 2. several template filters for customizing form field HTML attributes and CSS
58 classes
59
60 The ``render_field`` tag should be easier to use and should make form field
61 customizations much easier for designers and front-end developers.
62
63 The template filters are more powerful than the ``render_field`` tag, but they
64 use a more complex and less HTML-like syntax.
65
66 render_field
67 ------------
68
69 This is a template tag that can be used as an alternative to aforementioned
70 filters. This template tag renders a field using a syntax similar to plain
71 HTML attributes.
72
73 Example::
74
75 {% load widget_tweaks %}
76
77 <!-- change input type (e.g. to HTML5) -->
78 {% render_field form.search_query type="search" %}
79
80 <!-- add/change several attributes -->
81 {% render_field form.text rows="20" cols="20" title="Hello, world!" %}
82
83 <!-- append to an attribute -->
84 {% render_field form.title class+="css_class_1 css_class_2" %}
85
86 <!-- template variables can be used as attribute values -->
87 {% render_field form.text placeholder=form.text.label %}
88
89 <!-- double colon -->
90 {% render_field form.search_query v-bind::class="{active:isActive}" %}
91
92
93 For fields rendered with ``{% render_field %}`` tag it is possible
94 to set error class and required fields class by using
95 ``WIDGET_ERROR_CLASS`` and ``WIDGET_REQUIRED_CLASS`` template variables::
96
97 {% with WIDGET_ERROR_CLASS='my_error' WIDGET_REQUIRED_CLASS='my_required' %}
98 {% render_field form.field1 %}
99 {% render_field form.field2 %}
100 {% render_field form.field3 %}
101 {% endwith %}
102
103 You can be creative with these variables: e.g. a context processor could
104 set a default CSS error class on all fields rendered by
105 ``{% render_field %}``.
106
107
108 attr
109 ----
110 Adds or replaces any single html attribute for the form field.
111
112 Examples::
113
114 {% load widget_tweaks %}
115
116 <!-- change input type (e.g. to HTML5) -->
117 {{ form.search_query|attr:"type:search" }}
118
119 <!-- add/change several attributes -->
120 {{ form.text|attr:"rows:20"|attr:"cols:20"|attr:"title:Hello, world!" }}
121
122 <!-- attributes without parameters -->
123 {{ form.search_query|attr:"autofocus" }}
124
125
126 <!-- attributes with double colon Vuejs output: v-bind:class="{active:ValueEnabled}" -->
127 {{ form.search_query|attr:"v-bind::class:{active:ValueEnabled}" }}
128
129
130 add_class
131 ---------
132
133 Adds CSS class to field element. Split classes by whitespace in order to add
134 several classes at once.
135
136 Example::
137
138 {% load widget_tweaks %}
139
140 <!-- add 2 extra css classes to field element -->
141 {{ form.title|add_class:"css_class_1 css_class_2" }}
142
143 set_data
144 --------
145
146 Sets HTML5 data attribute ( http://ejohn.org/blog/html-5-data-attributes/ ).
147 Useful for unobtrusive javascript. It is just a shortcut for 'attr' filter
148 that prepends attribute names with 'data-' string.
149
150 Example::
151
152 {% load widget_tweaks %}
153
154 <!-- data-filters:"OverText" will be added to input field -->
155 {{ form.title|set_data:"filters:OverText" }}
156
157 append_attr
158 -----------
159
160 Appends attribute value with extra data.
161
162 Example::
163
164 {% load widget_tweaks %}
165
166 <!-- add 2 extra css classes to field element -->
167 {{ form.title|append_attr:"class:css_class_1 css_class_2" }}
168
169 'add_class' filter is just a shortcut for 'append_attr' filter that
170 adds values to the 'class' attribute.
171
172
173 remove_attr
174 -----------
175 Removes any single html attribute for the form field.
176
177 Example::
178
179 {% load widget_tweaks %}
180
181 <!-- removes autofocus attribute from field element -->
182 {{ form.title|remove_attr:"autofocus" }}
183
184
185 add_label_class
186 ---------------
187
188 The same as `add_class` but adds css class to form labels.
189
190 Example::
191
192 {% load widget_tweaks %}
193
194 <!-- add 2 extra css classes to field label element -->
195 {{ form.title|add_label_class:"label_class_1 label_class_2" }}
196
197
198 add_error_class
199 ---------------
200
201 The same as 'add_class' but adds css class only if validation failed for
202 the field (field.errors is not empty).
203
204 Example::
205
206 {% load widget_tweaks %}
207
208 <!-- add 'error-border' css class on field error -->
209 {{ form.title|add_error_class:"error-border" }}
210
211
212 add_error_attr
213 --------------
214
215 The same as 'attr' but sets an attribute only if validation failed for
216 the field (field.errors is not empty). This can be useful when dealing
217 with accessibility::
218
219 {% load widget_tweaks %}
220
221 <!-- add aria-invalid="true" attribute on field error -->
222 {{ form.title|add_error_attr:"aria-invalid:true" }}
223
224 add_required_class
225 ------------------
226
227 The same as 'add_error_class' adds css class only for required field.
228
229 Example::
230
231 {% load widget_tweaks %}
232
233 <!-- add 'is-required' css class on field required -->
234 {{ form.title|add_required_class:"is-required" }}
235
236
237 field_type and widget_type
238 --------------------------
239
240 ``'field_type'`` and ``'widget_type'`` are template filters that return
241 field class name and field widget class name (in lower case).
242
243 Example::
244
245 {% load widget_tweaks %}
246
247 <div class="field {{ field|field_type }} {{ field|widget_type }} {{ field.html_name }}">
248 {{ field }}
249 </div>
250
251 Output::
252
253 <div class="field charfield textinput name">
254 <input id="id_name" type="text" name="name" maxlength="100" />
255 </div>
256
257
258 Mixing render_field and filters
259 ===============================
260
261 The render_field tag and filters mentioned above can be mixed.
262
263 Example::
264
265 {% render_field form.category|append_attr:"readonly:readonly" type="text" placeholder="Category" %}
266
267
268 returns::
269
270 <input name="category" placeholder="Profession" readonly="readonly" type="text">
271
272
273 Filter chaining
274 ===============
275
276 The order django-widget-tweaks filters apply may seem counter-intuitive
277 (leftmost filter wins)::
278
279 {{ form.simple|attr:"foo:bar"|attr:"foo:baz" }}
280
281 returns::
282
283 <input foo="bar" type="text" name="simple" id="id_simple" />
284
285 It is not a bug, it is a feature that enables creating reusable templates
286 with overridable defaults.
287
288 Reusable field template example::
289
290 {# inc/field.html #}
291 {% load widget_tweaks %}
292 <div>{{ field|attr:"foo:default_foo" }}</div>
293
294 Example usage::
295
296 {# my_template.html #}
297 {% load widget_tweaks %}
298 <form method='POST' action=''> {% csrf_token %}
299 {% include "inc/field.html" with field=form.title %}
300 {% include "inc/field.html" with field=form.description|attr:"foo:non_default_foo" %}
301 </form>
302
303 With 'rightmost filter wins' rule it wouldn't be possible to override
304 ``|attr:"foo:default_foo"`` in main template.
305
306 Contributing
307 ============
308
309 If you've found a bug, implemented a feature or have a suggestion,
310 do not hesitate to contact me, fire an issue or send a pull request.
311
312 * Source code: https://github.com/jazzband/django-widget-tweaks/
313 * Bug tracker: https://github.com/jazzband/django-widget-tweaks/issues
314
315 Testing
316 -------
317
318 Make sure you have `tox <http://tox.testrun.org/>`_ installed, then type
319
320 ::
321
322 tox
323
324 from the source checkout.
325
326 NOT SUPPORTED
327 =============
328
329 MultiWidgets: SplitDateTimeWidget, SplitHiddenDateTimeWidget
330
331
332 Changes
333 =======
334
335
336 1.4.8 (2020-03-12)
337 ------------------
338
339 * Fix Release version
340
341
342 1.4.7 (2020-03-10)
343 ------------------
344
345 * Fix Travis deployment to Jazzband site
346
347
348 1.4.6 (2020-03-09)
349 ------------------
350
351 * Feature remove attribute from field
352 * Added documentation for remove_attr feature
353 * Reformat code with black for PEP8 compatibility
354 * More consistent tox configuration
355 * adding a new templatetag, unittest and documentation
356 * Deprecate Python 2.7 support
357 * Use automatic formatting for all files
358
359
360 1.4.5 (2019-06-08)
361 ------------------
362
363 * Fix rST formatting errors.
364
365
366 1.4.4 (2019-06-05)
367 ------------------
368
369 * Add support for type attr.
370 * Add Python 3.7 and drop Python 3.3 support.
371 * Add support for double colon syntax.
372
373
374 1.4.3 (2018-09-6)
375 ------------------
376
377 * Added add_label_class filter for CSS on form labels
378 * Removed compatibility code for unsupported Django versions
379 * Fixed support for non-value attributes in Django < 1.8
380 * Support non-value attributes in HTML5 by setting their value to True
381
382
383 1.4.2 (2018-03-19)
384 ------------------
385
386 * update readme to make installation more clear
387 * shallow copy field before updating attributes
388 * drop Python 2.6 and Python 3.2 support
389 * always cast the result of render to a string
390 * fix import for django >= 2.0
391 * moved to jazzband
392
393
394 1.4.1 (2015-06-29)
395 ------------------
396
397 * fixed a regression in django-widget-tweaks v1.4
398 (the field is no longer deep copied).
399
400 1.4 (2015-06-27)
401 ----------------
402
403 * Django 1.7, 1.8 and 1.9 support;
404 * setup.py is switched to setuptools;
405 * testing improvements;
406 * Python 3.4 support is added;
407 * Python 2.5 is not longer supported;
408 * bitbucket repository is no longer supported (development is moved to github).
409
410 1.3 (2013-04-05)
411 ----------------
412
413 * added support for ``WIDGET_ERROR_CLASS`` and ``WIDGET_REQUIRED_CLASS``
414 template variables that affect ``{% render_field %}``.
415
416 1.2 (2013-03-23)
417 ----------------
418
419 * new ``add_error_attr`` template filter;
420 * testing improvements.
421
422 1.1.2 (2012-06-06)
423 ------------------
424
425 * support for template variables is added to ``render_field`` tag;
426 * new ``field_type`` and ``widget_type`` filters.
427
428 1.1.1 (2012-03-22)
429 ------------------
430
431 * some issues with ``render_field`` tag are fixed.
432
433 1.1 (2012-03-22)
434 ----------------
435
436 * ``render_field`` template tag.
437
438 1.0 (2012-02-06)
439 ----------------
440
441 * filters return empty strings instead of raising exceptions if field is missing;
442 * test running improvements;
443 * python 3 support;
444 * undocumented 'behave' filter is removed.
445
446 0.3 (2011-03-04)
447 ----------------
448
449 * ``add_error_class`` filter.
450
451 0.2.1 (2011-02-03)
452 ------------------
453
454 * Attributes customized in widgets are preserved;
455 * no more extra whitespaces;
456 * tests;
457
458 0.1 (2011-01-12)
459 ----------------
460
461 Initial release.
462
463 Platform: UNKNOWN
464 Classifier: Development Status :: 5 - Production/Stable
465 Classifier: Framework :: Django
466 Classifier: Intended Audience :: Developers
467 Classifier: License :: OSI Approved :: MIT License
468 Classifier: Programming Language :: Python
469 Classifier: Programming Language :: Python :: 3
470 Classifier: Programming Language :: Python :: 3.6
471 Classifier: Programming Language :: Python :: 3.7
472 Classifier: Programming Language :: Python :: 3.8
473 Classifier: Topic :: Software Development :: Libraries :: Python Modules
474 Requires: django (>=1.11)