django-tableaux 0.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. django_tableaux/__init__.py +26 -0
  2. django_tableaux/buttons.py +45 -0
  3. django_tableaux/columns.py +89 -0
  4. django_tableaux/static/django_tableaux/css/django_tableaux.css +310 -0
  5. django_tableaux/static/django_tableaux/js/django_tableaux.js +326 -0
  6. django_tableaux/templates/django_tableaux/basic/alert.html +4 -0
  7. django_tableaux/templates/django_tableaux/basic/block_content.html +18 -0
  8. django_tableaux/templates/django_tableaux/basic/block_head.html +2 -0
  9. django_tableaux/templates/django_tableaux/basic/block_scripts.html +5 -0
  10. django_tableaux/templates/django_tableaux/basic/button.html +2 -0
  11. django_tableaux/templates/django_tableaux/basic/cell_edit.html +17 -0
  12. django_tableaux/templates/django_tableaux/basic/cell_error.html +1 -0
  13. django_tableaux/templates/django_tableaux/basic/cell_form.html +15 -0
  14. django_tableaux/templates/django_tableaux/basic/load_more.html +2 -0
  15. django_tableaux/templates/django_tableaux/basic/modal_base.html +34 -0
  16. django_tableaux/templates/django_tableaux/basic/modal_filter.html +23 -0
  17. django_tableaux/templates/django_tableaux/basic/modal_form.html +20 -0
  18. django_tableaux/templates/django_tableaux/basic/page_link.html +7 -0
  19. django_tableaux/templates/django_tableaux/basic/render_footer.html +11 -0
  20. django_tableaux/templates/django_tableaux/basic/render_header.html +45 -0
  21. django_tableaux/templates/django_tableaux/basic/render_paginator.html +26 -0
  22. django_tableaux/templates/django_tableaux/basic/render_row.html +19 -0
  23. django_tableaux/templates/django_tableaux/basic/render_row_mobile.html +39 -0
  24. django_tableaux/templates/django_tableaux/basic/render_rows.html +47 -0
  25. django_tableaux/templates/django_tableaux/basic/render_table.html +11 -0
  26. django_tableaux/templates/django_tableaux/basic/render_table_data.html +15 -0
  27. django_tableaux/templates/django_tableaux/basic/select_checkbox.html +1 -0
  28. django_tableaux/templates/django_tableaux/basic/tableaux.html +20 -0
  29. django_tableaux/templates/django_tableaux/basic/tb_actions.html +28 -0
  30. django_tableaux/templates/django_tableaux/basic/tb_buttons.html +8 -0
  31. django_tableaux/templates/django_tableaux/basic/tb_columns.html +20 -0
  32. django_tableaux/templates/django_tableaux/basic/tb_filter_button.html +7 -0
  33. django_tableaux/templates/django_tableaux/basic/tb_filter_field.html +20 -0
  34. django_tableaux/templates/django_tableaux/basic/tb_filter_pills.html +7 -0
  35. django_tableaux/templates/django_tableaux/basic/tb_rows.html +32 -0
  36. django_tableaux/templates/django_tableaux/basic/toolbar_filter.html +43 -0
  37. django_tableaux/templates/django_tableaux/basic/toolbar_main.html +17 -0
  38. django_tableaux/templates/django_tableaux/basic/width_request.html +19 -0
  39. django_tableaux/templates/django_tableaux/block_content.html +18 -0
  40. django_tableaux/templates/django_tableaux/bootstrap4/alert.html +4 -0
  41. django_tableaux/templates/django_tableaux/bootstrap4/block_head.html +2 -0
  42. django_tableaux/templates/django_tableaux/bootstrap4/block_scripts.html +10 -0
  43. django_tableaux/templates/django_tableaux/bootstrap4/cell_edit.html +18 -0
  44. django_tableaux/templates/django_tableaux/bootstrap4/cell_error.html +1 -0
  45. django_tableaux/templates/django_tableaux/bootstrap4/cell_form.html +15 -0
  46. django_tableaux/templates/django_tableaux/bootstrap4/modal_base.html +34 -0
  47. django_tableaux/templates/django_tableaux/bootstrap4/modal_filter.html +23 -0
  48. django_tableaux/templates/django_tableaux/bootstrap4/modal_form.html +20 -0
  49. django_tableaux/templates/django_tableaux/bootstrap4/render_paginator.html +44 -0
  50. django_tableaux/templates/django_tableaux/bootstrap4/render_table.html +19 -0
  51. django_tableaux/templates/django_tableaux/bootstrap4/select_checkbox.html +1 -0
  52. django_tableaux/templates/django_tableaux/bootstrap4/show_more.html +2 -0
  53. django_tableaux/templates/django_tableaux/bootstrap4/tableaux.html +20 -0
  54. django_tableaux/templates/django_tableaux/bootstrap4/tb_actions.html +30 -0
  55. django_tableaux/templates/django_tableaux/bootstrap4/tb_buttons.html +8 -0
  56. django_tableaux/templates/django_tableaux/bootstrap4/tb_columns.html +25 -0
  57. django_tableaux/templates/django_tableaux/bootstrap4/tb_filter_button.html +7 -0
  58. django_tableaux/templates/django_tableaux/bootstrap4/tb_filter_field.html +10 -0
  59. django_tableaux/templates/django_tableaux/bootstrap4/tb_rows.html +13 -0
  60. django_tableaux/templates/django_tableaux/bootstrap4/toolbar_filter.html +22 -0
  61. django_tableaux/templates/django_tableaux/bootstrap4/toolbar_main.html +19 -0
  62. django_tableaux/templates/django_tableaux/bootstrap4/width_request.html +19 -0
  63. django_tableaux/templates/django_tableaux/bootstrap5/block_scripts.html +10 -0
  64. django_tableaux/templates/django_tableaux/bootstrap5/modal_base.html +34 -0
  65. django_tableaux/templates/django_tableaux/bootstrap5/modal_filter.html +23 -0
  66. django_tableaux/templates/django_tableaux/bootstrap5/modal_form.html +20 -0
  67. django_tableaux/templates/django_tableaux/bootstrap5_base.html +22 -0
  68. django_tableaux/templates/django_tableaux/picocss/block_head.html +2 -0
  69. django_tableaux/templates/django_tableaux/picocss/modal_base.html +17 -0
  70. django_tableaux/templates/django_tableaux/picocss/tb_actions.html +34 -0
  71. django_tableaux/templates/django_tableaux/picocss/tb_columns.html +23 -0
  72. django_tableaux/templates/django_tableaux/picocss/tb_rows.html +11 -0
  73. django_tableaux/templates/django_tableaux/picocss/toolbar_main.html +9 -0
  74. django_tableaux/templates/django_tableaux/tableaux.html +15 -0
  75. django_tableaux/templates/django_tableaux/toolbar.html +16 -0
  76. django_tableaux/templatetags/__init__.py +0 -0
  77. django_tableaux/templatetags/django_tableaux.py +51 -0
  78. django_tableaux/utils.py +241 -0
  79. django_tableaux/views.py +717 -0
  80. django_tableaux-0.7.2.dist-info/LICENSE +21 -0
  81. django_tableaux-0.7.2.dist-info/METADATA +41 -0
  82. django_tableaux-0.7.2.dist-info/RECORD +83 -0
  83. django_tableaux-0.7.2.dist-info/WHEEL +4 -0
@@ -0,0 +1,26 @@
1
+ """
2
+ Django tables with Advanced User eXperience
3
+ ===============
4
+ This project builds upon two well-established django apps: `django_tables2 <https://github.com/jieter/django-tables2>`_
5
+ and `django_filter <https://github.com/carltongibson/django-filter>`_ and enhances their functionality through a
6
+ sprinkling of `htmx <https://htmx.org>`_ magic. It provides a single class-based view in which you can enable multiple
7
+ features to deliver a customised user experience that embodies the best practice for interactive tables.
8
+
9
+ Key features
10
+ ============
11
+ * The columns to display can be user-defined
12
+ * Fully responsive: Define different column layouts for mobile, tablet and desktop
13
+ * Bulk actions on selected rows or on all (possibly filtered) rows
14
+ * Infinite scroll
15
+ * Infinite load-more data
16
+ * Position filters in a toolbar, in a modal or embed them within the table header
17
+ * Show active filters with ability to clear individual filters
18
+ * Edit specific fields directly inside the table
19
+ * Easy integration with generic views for CRUD operations
20
+
21
+ The project is still in beta but is fully usable.
22
+
23
+ Full documentation to follow.
24
+ """
25
+
26
+ __version__ = "0.7.2"
@@ -0,0 +1,45 @@
1
+ from django.template.loader import render_to_string
2
+ from django.utils.safestring import mark_safe
3
+ from django.utils.text import slugify
4
+ from .utils import get_template_path
5
+
6
+
7
+ class Button:
8
+ template_name = "button.html"
9
+ prefix = "btn_"
10
+ name = ""
11
+
12
+ def __init__(
13
+ self, content="", name="", typ="button", css="btn btn-primary", **kwargs
14
+ ):
15
+ if content == "" and name == "":
16
+ raise ValueError("Button content and name cannot both be empty.")
17
+ self.name = (
18
+ f"{self.prefix}{name}"
19
+ if name
20
+ else f"{self.prefix}{slugify(content).replace('-', '_')}"
21
+ )
22
+ self.context = {
23
+ "element": "a" if kwargs.get("href") else "button",
24
+ "content": content,
25
+ "name": self.name,
26
+ "class": css,
27
+ }
28
+ if self.context["element"] == "button":
29
+ self.context["type"] = typ
30
+ self.context.update(kwargs)
31
+
32
+ def render(self):
33
+ html = mark_safe(
34
+ render_to_string(
35
+ template_name=get_template_path(self.template_name),
36
+ context=self.context,
37
+ )
38
+ )
39
+ return html
40
+
41
+ def original_name(self):
42
+ """
43
+ Return the button name without the prefix added
44
+ """
45
+ return self.name[len(self.prefix) :]
@@ -0,0 +1,89 @@
1
+ import itertools
2
+ import django_tables2 as tables
3
+ from django.contrib.humanize.templatetags.humanize import intcomma
4
+ from .utils import get_template_path
5
+ from django.utils.safestring import mark_safe
6
+
7
+
8
+ class EditableColumn(tables.Column):
9
+ def render(self, value, record):
10
+ return value
11
+
12
+
13
+ class RightAlignedColumn(tables.Column):
14
+ def __init__(self, **kwargs):
15
+ super().__init__()
16
+ if "th" not in self.attrs:
17
+ self.attrs["th"] = {}
18
+ if "td" not in self.attrs:
19
+ self.attrs["td"] = {}
20
+ self.attrs["th"]["style"] = "text-align: right;"
21
+ self.attrs["td"]["style"] = "text-align: right;"
22
+
23
+
24
+ class CenteredColumn(tables.Column):
25
+ def __init__(self, **kwargs):
26
+ super().__init__(**kwargs)
27
+ if "th" not in self.attrs:
28
+ self.attrs["th"] = {}
29
+ if "td" not in self.attrs:
30
+ self.attrs["td"] = {}
31
+ self.attrs["th"]["style"] = "text-align: center;"
32
+ self.attrs["td"]["style"] = "text-align: center;"
33
+
34
+
35
+ class CenteredTrueColumn(CenteredColumn):
36
+ def render(self, value):
37
+ if value:
38
+ return "\u2705"
39
+ return ""
40
+
41
+
42
+ class CenteredTrueFalseColumn(CenteredColumn):
43
+ def render(self, value):
44
+ if value:
45
+ return "\u2705"
46
+ return "\u274c"
47
+
48
+
49
+ class CurrencyColumn(RightAlignedColumn):
50
+ def __init__(self, **kwargs):
51
+ self.integer = kwargs.pop("integer", None)
52
+ self.prefix = kwargs.pop("prefix", "")
53
+ self.suffix = kwargs.pop("suffix", "")
54
+ super().__init__(**kwargs)
55
+
56
+ def render(self, value):
57
+ if self.integer:
58
+ value = int(value)
59
+ return mark_safe(f"{self.prefix}{intcomma(value)}{self.suffix}")
60
+
61
+
62
+ class CheckBoxColumn(tables.TemplateColumn):
63
+ def __init__(self, **kwargs):
64
+ kwargs["template_name"] = get_template_path("custom_checkbox.html")
65
+ super().__init__(**kwargs)
66
+
67
+
68
+ class SelectionColumn(tables.TemplateColumn):
69
+ def __init__(self, **kwargs):
70
+ kwargs["template_name"] = get_template_path("select_checkbox.html")
71
+ kwargs["verbose_name"] = ""
72
+ kwargs["accessor"] = "id"
73
+ kwargs["orderable"] = False
74
+ super().__init__(**kwargs)
75
+
76
+
77
+ class CounterColumn(tables.Column):
78
+ row_counter = None
79
+
80
+ def __init__(self, **kwargs):
81
+ kwargs["orderable"] = False
82
+ kwargs["empty_values"] = ()
83
+ kwargs["verbose_name"] = ""
84
+ super().__init__(**kwargs)
85
+
86
+ def render(self, value):
87
+ if not self.row_counter:
88
+ self.row_counter = itertools.count()
89
+ return next(self.row_counter) + 1
@@ -0,0 +1,310 @@
1
+ :root {
2
+ --background: whitesmoke;
3
+ --header-background: aquamarine;
4
+ --header-color: darkgreen;
5
+ --border-color: grey;
6
+ }
7
+
8
+
9
+
10
+ .dt-table {
11
+ table {
12
+ border-collapse: collapse;
13
+ width: 100%
14
+ }
15
+ th, td {
16
+ padding: 5px;
17
+ text-align: left;
18
+ border: 1px solid;
19
+ border-color: var(--border-color);
20
+ }
21
+ th {
22
+ background-color: var(--header-background);
23
+ color: #111;
24
+ }
25
+
26
+
27
+ td {
28
+ background-color: var(--background);
29
+ color: var(--header-color);
30
+ }
31
+ td.odd {
32
+ background-color: yellow;
33
+ }
34
+ td.even{
35
+ background-color: orange;
36
+ }
37
+ caption {
38
+ caption-side: bottom;
39
+ text-align: left
40
+ }
41
+ }
42
+
43
+
44
+ .container {
45
+ width: 100%;
46
+ padding-right: 15px;
47
+ padding-left: 15px;
48
+ margin-right: auto;
49
+ margin-left: auto;
50
+ }
51
+
52
+ @media (min-width: 576px) {
53
+ .container {
54
+ max-width: 540px;
55
+ }
56
+ }
57
+
58
+ @media (min-width: 768px) {
59
+ .container {
60
+ max-width: 720px;
61
+ }
62
+ }
63
+
64
+ @media (min-width: 992px) {
65
+ .container {
66
+ max-width: 960px;
67
+ }
68
+ }
69
+
70
+ @media (min-width: 1200px) {
71
+ .container {
72
+ max-width: 1140px;
73
+ }
74
+ }
75
+ .container-fluid {
76
+ width: 100%;
77
+ padding-right: 15px;
78
+ padding-left: 15px;
79
+ margin-right: auto;
80
+ margin-left: auto;
81
+ }
82
+
83
+ .sticky-header {
84
+ thead {
85
+ position: sticky;
86
+ top: -1px;
87
+ }
88
+ }
89
+
90
+ .fixed_headers {
91
+ width: 100px;
92
+ table-layout: fixed;
93
+ border-collapse: collapse;
94
+
95
+ th {
96
+ text-decoration: underline;
97
+ }
98
+
99
+
100
+ /*
101
+ td:nth-child(1), th:nth-child(1) { min-width: @column_one_width; }
102
+ td:nth-child(2), th:nth-child(2) { min-width: @column_two_width; }
103
+ td:nth-child(3), th:nth-child(3) { width: @column_three_width; }
104
+ */
105
+
106
+ th {
107
+ background-color: #ddd;
108
+ color: #fff;
109
+
110
+ tr {
111
+ display: block;
112
+ position: relative;
113
+ }
114
+ }
115
+
116
+ tbody {
117
+ display: block;
118
+ overflow: auto;
119
+ width: 100%;
120
+ /*height: 700px;*/
121
+
122
+ tr:nth-child(even) {
123
+ background-color: #ddd
124
+ }
125
+ }
126
+ }
127
+ .even {
128
+ background-color: #ddd;!important;
129
+ }
130
+ .odd {
131
+ background-color: #ffffff;!important;
132
+ }
133
+ /*
134
+ th.asc:after {
135
+ content: '\0000a0\0025b2';
136
+ float: right;
137
+ }
138
+ th.desc:after {
139
+ content: '\0000a0\0025bc';
140
+ float: right;
141
+ }
142
+ */
143
+ .filter-pill {
144
+ font-size: .9rem;
145
+ background-color: deepskyblue;
146
+ color: darkblue;
147
+ padding: 3px 10px;
148
+ border: 1px solid cadetblue;
149
+ border-radius: 10px;
150
+ margin-right: 10px;
151
+ }
152
+
153
+ .filter-value {
154
+ color: white;
155
+ padding: 5px;
156
+ }
157
+
158
+ .filter-clear {
159
+ background-color: transparent;
160
+ color: gray;
161
+ border: 1px transparent;
162
+ }
163
+
164
+ .filter-clear:hover {
165
+ cursor: pointer;
166
+ }
167
+
168
+ .filter-x {
169
+ color: white;
170
+ }
171
+
172
+ .filter-x:hover {
173
+ cursor: pointer;
174
+ }
175
+
176
+
177
+
178
+ .td-edit {
179
+ cursor: pointer;
180
+ }
181
+
182
+ .td-edit:hover {
183
+ background-color: floralwhite;
184
+ }
185
+
186
+ tr:hover {
187
+ cursor: pointer;
188
+ background-color: floralwhite;
189
+ }
190
+
191
+ .select-list {
192
+ .select-title {
193
+ display: inline-block;
194
+ cursor: pointer;
195
+ background: #fff;
196
+ border: 1px solid #eaeaea;
197
+ border-radius: 5px;
198
+ padding: 5px 10px 5px 10px;
199
+
200
+ &::after {
201
+ display: inline-block;
202
+ content: '>';
203
+ margin-left: 15px;
204
+ font-size: 11px;
205
+ transform: rotate(90deg) scale(1.5, 2) translate(-2px, 0);
206
+ }
207
+
208
+ &:hover {
209
+ background: #eaeaea;
210
+ }
211
+ }
212
+
213
+ .select-options {
214
+ margin-top: 5px;
215
+ display: none;
216
+ position: absolute;
217
+ z-index: 500;
218
+ border: 1px solid #808080;
219
+ border-radius: 5px;
220
+ background: #fff;
221
+
222
+ .select-option {
223
+ line-height: 1;
224
+ padding: 5px 5px 5px 5px;
225
+
226
+ label {
227
+ display: inline-block;
228
+ }
229
+
230
+ &:hover {
231
+ background: #eaeaea;
232
+ }
233
+
234
+ input {
235
+ margin: 0px 5px 0px 5px;
236
+ }
237
+ }
238
+ }
239
+ .selected{
240
+ background: #a0f0f0;
241
+ }
242
+ .opened {
243
+ display: block;
244
+ }
245
+ }
246
+ .flex-display {
247
+ display: flex;
248
+ margin: 2px 0 2px 0;
249
+ }
250
+ .flex-row {
251
+ flex-direction: row;
252
+ }
253
+ .flex-start{
254
+ justify-content: flex-start;
255
+ }
256
+ .flex-end {
257
+ justify-content: flex-end;
258
+ }
259
+ .flex-between {
260
+ justify-content: space-between;
261
+ }
262
+
263
+ .pagination {
264
+ display: flex;
265
+ justify-content: center;
266
+ padding-left: 0;
267
+ list-style: none;
268
+ border-radius: 0.25rem;
269
+ }
270
+
271
+ .page-link {
272
+ position: relative;
273
+ display: block;
274
+ padding: 0.5rem 0.75rem;
275
+ margin-left: -1px;
276
+ line-height: 1.25;
277
+ text-decoration: none;
278
+ color: #5156ff;
279
+ background-color: var(--background);
280
+ border: 1px solid var(--border-color);
281
+ }
282
+
283
+ .page-link:hover {
284
+ z-index: 2;
285
+ color: #050cff;
286
+ text-decoration: none;
287
+ background-color: var(--background);
288
+ border-color: var(--border-color);
289
+ }
290
+
291
+ .page-link:focus {
292
+ z-index: 2;
293
+ outline: 0;
294
+ box-shadow: none;
295
+ }
296
+
297
+ .page-item.active .page-link {
298
+ z-index: 1;
299
+ color: #FFF;
300
+ background-color: #1C685A;
301
+ border-color: #1C685A;
302
+ }
303
+
304
+ .page-item.disabled .page-link {
305
+ color: #6c757d;
306
+ pointer-events: none;
307
+ cursor: auto;
308
+ background-color: #FFF;
309
+ border-color: #dee2e6;
310
+ }