This repository was archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_widget.py
More file actions
75 lines (54 loc) · 2.26 KB
/
_widget.py
File metadata and controls
75 lines (54 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""PytSite Content Plugin Widgets
"""
__author__ = 'Oleksandr Shepetko'
__email__ = 'a@shepetko.com'
__license__ = 'MIT'
from pytsite import lang
from plugins import widget, odm_ui
from . import _api
class ModelSelect(widget.select.Select):
"""Content Model Select
"""
def __init__(self, uid: str, **kwargs):
items = []
for k, v in _api.get_models().items():
items.append((k, lang.t(v[1])))
super().__init__(uid, items=sorted(items, key=lambda x: x[1]), **kwargs)
class ModelCheckboxes(widget.select.Checkboxes):
"""Content Model Checkboxes
"""
def __init__(self, uid: str, **kwargs):
self._check_perms = kwargs.get('check_perms', True)
self._filter = kwargs.get('filter')
items = []
for model, info in _api.get_models().items():
items.append((model, lang.t(info[1])))
items = sorted(items, key=lambda x: x[1])
if callable(self._filter):
filtered_items = []
for item in items:
if self._filter(_api.dispense(item[0])):
filtered_items.append(item)
items = filtered_items
super().__init__(uid, items=items, **kwargs)
class StatusSelect(widget.select.Select):
"""Content Status Select
"""
def __init__(self, uid: str, entity, **kwargs):
"""Init
:type entity: plugins.content.model.Content
"""
status_field = entity.get_field(kwargs.get('status_field_name', 'status'))
statuses = entity.content_status_select_items()
kwargs.setdefault('label', lang.t('content@status'))
kwargs.setdefault('h_size', 'col-xs-12 col-12 col-sm-4 col-md-3')
kwargs.setdefault('required', status_field.is_required)
kwargs.setdefault('items', [(s, entity.t('content_status_{}_{}'.format(entity.model, s))) for s in statuses])
kwargs.setdefault('hidden', len(kwargs.get('items')) <= 1)
kwargs.setdefault('value', status_field.get_val())
super().__init__(uid, **kwargs)
class EntitySelect(odm_ui.widget.EntitySelect):
def __init__(self, uid: str, **kwargs):
kwargs.setdefault('model', list(_api.get_models().keys()))
kwargs.setdefault('sort_by', 'title')
super().__init__(uid, **kwargs)