brilliance-admin 0.43.3__py3-none-any.whl → 0.43.5__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.
- brilliance_admin/integrations/sqlalchemy/auth.py +2 -2
- brilliance_admin/integrations/sqlalchemy/fields.py +4 -2
- brilliance_admin/integrations/sqlalchemy/fields_schema.py +13 -10
- brilliance_admin/integrations/sqlalchemy/table/base.py +4 -4
- brilliance_admin/integrations/sqlalchemy/table/create.py +3 -3
- brilliance_admin/integrations/sqlalchemy/table/delete.py +1 -1
- brilliance_admin/integrations/sqlalchemy/table/list.py +4 -4
- brilliance_admin/integrations/sqlalchemy/table/retrieve.py +17 -5
- brilliance_admin/integrations/sqlalchemy/table/update.py +5 -5
- brilliance_admin/locales/en.yml +13 -10
- brilliance_admin/locales/ru.yml +14 -10
- brilliance_admin/schema/category.py +0 -1
- brilliance_admin/schema/table/fields/base.py +37 -8
- brilliance_admin/schema/table/fields_schema.py +2 -1
- brilliance_admin/translations.py +3 -3
- brilliance_admin/utils.py +3 -3
- {brilliance_admin-0.43.3.dist-info → brilliance_admin-0.43.5.dist-info}/METADATA +1 -1
- {brilliance_admin-0.43.3.dist-info → brilliance_admin-0.43.5.dist-info}/RECORD +21 -21
- {brilliance_admin-0.43.3.dist-info → brilliance_admin-0.43.5.dist-info}/WHEEL +0 -0
- {brilliance_admin-0.43.3.dist-info → brilliance_admin-0.43.5.dist-info}/licenses/LICENSE +0 -0
- {brilliance_admin-0.43.3.dist-info → brilliance_admin-0.43.5.dist-info}/top_level.txt +0 -0
|
@@ -54,7 +54,7 @@ class SQLAlchemyJWTAdminAuthentication(AdminAuthentication):
|
|
|
54
54
|
logger.exception(
|
|
55
55
|
'SQLAlchemy %s login db error: %s', type(self).__name__, e,
|
|
56
56
|
)
|
|
57
|
-
msg = _('connection_refused_error') % {'error': str(e)}
|
|
57
|
+
msg = _('errors.connection_refused_error') % {'error': str(e)}
|
|
58
58
|
raise AdminAPIException(
|
|
59
59
|
APIError(message=msg, code='connection_refused_error'),
|
|
60
60
|
status_code=500,
|
|
@@ -127,7 +127,7 @@ class SQLAlchemyJWTAdminAuthentication(AdminAuthentication):
|
|
|
127
127
|
logger.exception(
|
|
128
128
|
'SQLAlchemy %s authenticate db error: %s', type(self).__name__, e,
|
|
129
129
|
)
|
|
130
|
-
msg = _('connection_refused_error') % {'error': str(e)}
|
|
130
|
+
msg = _('errors.connection_refused_error') % {'error': str(e)}
|
|
131
131
|
raise AdminAPIException(
|
|
132
132
|
APIError(message=msg, code='connection_refused_error'),
|
|
133
133
|
status_code=500,
|
|
@@ -149,13 +149,15 @@ class SQLAlchemyRelatedField(TableField):
|
|
|
149
149
|
if self.many:
|
|
150
150
|
related = getattr(record, self.rel_name, None)
|
|
151
151
|
if related is None:
|
|
152
|
-
|
|
152
|
+
msg = f'Many Related field "{self.rel_name}" is missing on record "{record}" (many=True)'
|
|
153
|
+
raise FieldError(msg)
|
|
153
154
|
|
|
154
155
|
return [{'key': get_pk(obj), 'title': str(obj)} for obj in related]
|
|
155
156
|
|
|
156
157
|
related = getattr(record, self.rel_name, None)
|
|
157
158
|
if related is None:
|
|
158
|
-
|
|
159
|
+
msg = f'Related field "{self.rel_name}" is missing on record "{record}" (many=False)'
|
|
160
|
+
raise FieldError(msg)
|
|
159
161
|
|
|
160
162
|
return {'key': get_pk(related), 'title': str(related)}
|
|
161
163
|
|
|
@@ -54,9 +54,6 @@ class SQLAlchemyFieldsSchema(schema.FieldsSchema):
|
|
|
54
54
|
and not col.primary_key
|
|
55
55
|
)
|
|
56
56
|
|
|
57
|
-
if "choices" in info:
|
|
58
|
-
field_data["choices"] = [(c[0], c[1]) for c in info["choices"]]
|
|
59
|
-
|
|
60
57
|
col_type = col.type
|
|
61
58
|
try:
|
|
62
59
|
py_t = col_type.python_type
|
|
@@ -70,6 +67,10 @@ class SQLAlchemyFieldsSchema(schema.FieldsSchema):
|
|
|
70
67
|
if col.foreign_keys:
|
|
71
68
|
continue
|
|
72
69
|
|
|
70
|
+
elif "choices" in info:
|
|
71
|
+
field_data["choices"] = info['choices']
|
|
72
|
+
field_class = schema.ChoiceField
|
|
73
|
+
|
|
73
74
|
elif isinstance(col_type, (sqltypes.BigInteger, sqltypes.Integer)) or py_t is int:
|
|
74
75
|
field_class = schema.IntegerField
|
|
75
76
|
|
|
@@ -239,15 +240,17 @@ class SQLAlchemyFieldsSchema(schema.FieldsSchema):
|
|
|
239
240
|
return stmt
|
|
240
241
|
|
|
241
242
|
async def serialize(self, record, extra: dict, *args, **kwargs) -> dict:
|
|
242
|
-
# pylint: disable=import-outside-toplevel
|
|
243
|
-
from sqlalchemy import inspect
|
|
244
243
|
|
|
245
244
|
# Convert model values to dict
|
|
246
|
-
record_data = {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
245
|
+
record_data = {}
|
|
246
|
+
|
|
247
|
+
for slug, field in self.get_fields().items():
|
|
248
|
+
# pylint: disable=protected-access
|
|
249
|
+
if field._type == 'related':
|
|
250
|
+
record_data[slug] = record
|
|
251
|
+
else:
|
|
252
|
+
record_data[slug] = getattr(record, slug, None)
|
|
253
|
+
|
|
251
254
|
return await super().serialize(record_data, extra, *args, **kwargs)
|
|
252
255
|
|
|
253
256
|
def validate_incoming_data(self, data):
|
|
@@ -123,11 +123,11 @@ class SQLAlchemyAdminBase(SQLAlchemyAdminAutocompleteMixin, CategoryTable):
|
|
|
123
123
|
# pylint: disable=protected-access
|
|
124
124
|
if field._type == "related":
|
|
125
125
|
|
|
126
|
-
# pylint: disable=import-outside-toplevel
|
|
127
|
-
from sqlalchemy import inspect
|
|
128
|
-
|
|
129
|
-
model_attrs = [attr.key for attr in inspect(self.model).mapper.attrs]
|
|
130
126
|
if not hasattr(self.model, field.rel_name):
|
|
127
|
+
# pylint: disable=import-outside-toplevel
|
|
128
|
+
from sqlalchemy import inspect
|
|
129
|
+
model_attrs = [attr.key for attr in inspect(self.model).mapper.attrs]
|
|
130
|
+
|
|
131
131
|
msg = EXCEPTION_REL_NAME.format(
|
|
132
132
|
slug=slug,
|
|
133
133
|
model_name=self.model.__name__,
|
|
@@ -18,7 +18,7 @@ class SQLAlchemyAdminCreate:
|
|
|
18
18
|
language_context: LanguageContext,
|
|
19
19
|
) -> schema.CreateResult:
|
|
20
20
|
if not self.has_create:
|
|
21
|
-
raise AdminAPIException(APIError(message=_('method_not_allowed')), status_code=500)
|
|
21
|
+
raise AdminAPIException(APIError(message=_('errors.method_not_allowed')), status_code=500)
|
|
22
22
|
|
|
23
23
|
# pylint: disable=import-outside-toplevel
|
|
24
24
|
from sqlalchemy.exc import IntegrityError
|
|
@@ -37,7 +37,7 @@ class SQLAlchemyAdminCreate:
|
|
|
37
37
|
type(self).__name__, self.table_schema.model.__name__, e,
|
|
38
38
|
extra={'data': data},
|
|
39
39
|
)
|
|
40
|
-
msg = _('connection_refused_error') % {'error': str(e)}
|
|
40
|
+
msg = _('errors.connection_refused_error') % {'error': str(e)}
|
|
41
41
|
raise AdminAPIException(
|
|
42
42
|
APIError(message=msg, code='connection_refused_error'),
|
|
43
43
|
status_code=500,
|
|
@@ -62,7 +62,7 @@ class SQLAlchemyAdminCreate:
|
|
|
62
62
|
extra={'data': data},
|
|
63
63
|
)
|
|
64
64
|
raise AdminAPIException(
|
|
65
|
-
APIError(message=_('db_error_create'), code='db_error_create'), status_code=500,
|
|
65
|
+
APIError(message=_('errors.db_error_create'), code='db_error_create'), status_code=500,
|
|
66
66
|
) from e
|
|
67
67
|
|
|
68
68
|
logger.info(
|
|
@@ -14,5 +14,5 @@ class SQLAlchemyDeleteAction:
|
|
|
14
14
|
)
|
|
15
15
|
async def delete(self, action_data: ActionData):
|
|
16
16
|
if not self.has_delete:
|
|
17
|
-
raise AdminAPIException(APIError(message=_('method_not_allowed')), status_code=500)
|
|
17
|
+
raise AdminAPIException(APIError(message=_('errors.method_not_allowed')), status_code=500)
|
|
18
18
|
return ActionResult(message=ActionMessage(_('deleted_successfully')))
|
|
@@ -109,7 +109,7 @@ class SQLAlchemyAdminListMixin:
|
|
|
109
109
|
'list_data': list_data,
|
|
110
110
|
}
|
|
111
111
|
)
|
|
112
|
-
msg = _('filter_error') % {'error': e.message}
|
|
112
|
+
msg = _('errors.filter_error') % {'error': e.message}
|
|
113
113
|
raise AdminAPIException(APIError(message=msg, code='filters_exception'), status_code=500) from e
|
|
114
114
|
|
|
115
115
|
except Exception as e:
|
|
@@ -120,7 +120,7 @@ class SQLAlchemyAdminListMixin:
|
|
|
120
120
|
'list_data': list_data,
|
|
121
121
|
}
|
|
122
122
|
)
|
|
123
|
-
raise AdminAPIException(APIError(message=_('filters_exception'), code='filters_exception'), status_code=500) from e
|
|
123
|
+
raise AdminAPIException(APIError(message=_('errors.filters_exception'), code='filters_exception'), status_code=500) from e
|
|
124
124
|
|
|
125
125
|
data = []
|
|
126
126
|
|
|
@@ -143,7 +143,7 @@ class SQLAlchemyAdminListMixin:
|
|
|
143
143
|
'list_data': list_data,
|
|
144
144
|
}
|
|
145
145
|
)
|
|
146
|
-
msg = _('connection_refused_error') % {'error': str(e)}
|
|
146
|
+
msg = _('errors.connection_refused_error') % {'error': str(e)}
|
|
147
147
|
raise AdminAPIException(
|
|
148
148
|
APIError(message=msg, code='connection_refused_error'),
|
|
149
149
|
status_code=500,
|
|
@@ -172,7 +172,7 @@ class SQLAlchemyAdminListMixin:
|
|
|
172
172
|
}
|
|
173
173
|
)
|
|
174
174
|
raise AdminAPIException(
|
|
175
|
-
APIError(message=_('db_error_list'), code='db_error_list'), status_code=500,
|
|
175
|
+
APIError(message=_('errors.db_error_list'), code='db_error_list'), status_code=500,
|
|
176
176
|
) from e
|
|
177
177
|
|
|
178
178
|
return schema.TableListResult(data=data, total_count=int(total_count or 0))
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
3
|
from brilliance_admin import auth, schema
|
|
4
|
-
from brilliance_admin.exceptions import AdminAPIException, APIError
|
|
4
|
+
from brilliance_admin.exceptions import AdminAPIException, APIError, FieldError
|
|
5
|
+
from brilliance_admin.integrations.sqlalchemy.fields_schema import SQLAlchemyFieldsSchema
|
|
5
6
|
from brilliance_admin.translations import LanguageContext
|
|
6
7
|
from brilliance_admin.translations import TranslateText as _
|
|
7
8
|
from brilliance_admin.utils import get_logger
|
|
@@ -12,6 +13,8 @@ logger = get_logger()
|
|
|
12
13
|
class SQLAlchemyAdminRetrieveMixin:
|
|
13
14
|
has_retrieve: bool = True
|
|
14
15
|
|
|
16
|
+
table_schema: SQLAlchemyFieldsSchema
|
|
17
|
+
|
|
15
18
|
async def retrieve(
|
|
16
19
|
self,
|
|
17
20
|
pk: Any,
|
|
@@ -19,7 +22,7 @@ class SQLAlchemyAdminRetrieveMixin:
|
|
|
19
22
|
language_context: LanguageContext,
|
|
20
23
|
) -> schema.RetrieveResult:
|
|
21
24
|
if not self.has_delete:
|
|
22
|
-
raise AdminAPIException(APIError(message=_('method_not_allowed')), status_code=500)
|
|
25
|
+
raise AdminAPIException(APIError(message=_('errors.method_not_allowed')), status_code=500)
|
|
23
26
|
|
|
24
27
|
# pylint: disable=import-outside-toplevel
|
|
25
28
|
from sqlalchemy import inspect
|
|
@@ -38,16 +41,25 @@ class SQLAlchemyAdminRetrieveMixin:
|
|
|
38
41
|
extra={"record": record, "user": user},
|
|
39
42
|
)
|
|
40
43
|
|
|
44
|
+
except FieldError as e:
|
|
45
|
+
logger.exception(
|
|
46
|
+
'SQLAlchemy %s retrieve %s #%s field error: %s',
|
|
47
|
+
type(self).__name__, self.model.__name__, pk, e,
|
|
48
|
+
)
|
|
49
|
+
msg = _('errors.serialize_field_error') % {'error': e.message}
|
|
50
|
+
raise AdminAPIException(APIError(message=msg, code='filters_exception'), status_code=500) from e
|
|
51
|
+
|
|
41
52
|
except Exception as e:
|
|
42
53
|
logger.exception(
|
|
43
|
-
'SQLAlchemy %s retrieve db error: %s',
|
|
54
|
+
'SQLAlchemy %s retrieve %s #%s db error: %s',
|
|
55
|
+
type(self).__name__, self.model.__name__, pk, e,
|
|
44
56
|
)
|
|
45
57
|
raise AdminAPIException(
|
|
46
|
-
APIError(message=_('db_error_retrieve'), code='db_error_retrieve'), status_code=500,
|
|
58
|
+
APIError(message=_('errors.db_error_retrieve'), code='db_error_retrieve'), status_code=500,
|
|
47
59
|
) from e
|
|
48
60
|
|
|
49
61
|
if record is None:
|
|
50
|
-
msg = _('record_not_found') % {'pk_name': self.pk_name, 'pk': pk}
|
|
62
|
+
msg = _('errors.record_not_found') % {'pk_name': self.pk_name, 'pk': pk}
|
|
51
63
|
raise AdminAPIException(
|
|
52
64
|
APIError(message=msg, code='record_not_found'),
|
|
53
65
|
status_code=400,
|
|
@@ -21,7 +21,7 @@ class SQLAlchemyAdminUpdate:
|
|
|
21
21
|
language_context: LanguageContext,
|
|
22
22
|
) -> schema.UpdateResult:
|
|
23
23
|
if not self.has_update:
|
|
24
|
-
raise AdminAPIException(APIError(message=_('method_not_allowed')), status_code=500)
|
|
24
|
+
raise AdminAPIException(APIError(message=_('errors.method_not_allowed')), status_code=500)
|
|
25
25
|
|
|
26
26
|
# pylint: disable=import-outside-toplevel
|
|
27
27
|
from sqlalchemy import inspect
|
|
@@ -29,7 +29,7 @@ class SQLAlchemyAdminUpdate:
|
|
|
29
29
|
|
|
30
30
|
if pk is None:
|
|
31
31
|
raise AdminAPIException(
|
|
32
|
-
APIError(message=_('pk_not_found') % {'pk_name': self.pk_name}, code='pk_not_found'),
|
|
32
|
+
APIError(message=_('errors.pk_not_found') % {'pk_name': self.pk_name}, code='pk_not_found'),
|
|
33
33
|
status_code=400,
|
|
34
34
|
)
|
|
35
35
|
|
|
@@ -42,7 +42,7 @@ class SQLAlchemyAdminUpdate:
|
|
|
42
42
|
async with self.db_async_session() as session:
|
|
43
43
|
record = (await session.execute(stmt)).scalars().first()
|
|
44
44
|
if record is None:
|
|
45
|
-
msg = _('record_not_found') % {'pk_name': self.pk_name, 'pk': pk}
|
|
45
|
+
msg = _('errors.record_not_found') % {'pk_name': self.pk_name, 'pk': pk}
|
|
46
46
|
raise AdminAPIException(
|
|
47
47
|
APIError(message=msg, code='record_not_found'),
|
|
48
48
|
status_code=400,
|
|
@@ -59,7 +59,7 @@ class SQLAlchemyAdminUpdate:
|
|
|
59
59
|
type(self).__name__, self.table_schema.model.__name__, pk, e,
|
|
60
60
|
extra={'data': data},
|
|
61
61
|
)
|
|
62
|
-
msg = _('connection_refused_error') % {'error': str(e)}
|
|
62
|
+
msg = _('errors.connection_refused_error') % {'error': str(e)}
|
|
63
63
|
raise AdminAPIException(
|
|
64
64
|
APIError(message=msg, code='connection_refused_error'),
|
|
65
65
|
status_code=400,
|
|
@@ -84,7 +84,7 @@ class SQLAlchemyAdminUpdate:
|
|
|
84
84
|
extra={'data': data}
|
|
85
85
|
)
|
|
86
86
|
raise AdminAPIException(
|
|
87
|
-
APIError(message=_('db_error_update'), code='db_error_update'), status_code=500,
|
|
87
|
+
APIError(message=_('errors.db_error_update'), code='db_error_update'), status_code=500,
|
|
88
88
|
) from e
|
|
89
89
|
|
|
90
90
|
logger.info(
|
brilliance_admin/locales/en.yml
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
delete: 'Delete'
|
|
2
2
|
delete_confirmation_text: "Are you sure you want to delete those records?\nThis action cannot be undone."
|
|
3
3
|
deleted_successfully: 'The entries were successfully deleted.'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
db_error_create: 'Error creating a record in the database.'
|
|
7
|
-
db_error_update: 'Error updating the record in the database.'
|
|
8
|
-
db_error_retrieve: 'Error retrieving the record from the database.'
|
|
9
|
-
db_error_list: 'Failed to retrieve table data from the database.'
|
|
10
|
-
|
|
4
|
+
|
|
5
|
+
errors:
|
|
6
|
+
db_error_create: 'Error creating a record in the database.'
|
|
7
|
+
db_error_update: 'Error updating the record in the database.'
|
|
8
|
+
db_error_retrieve: 'Error retrieving the record from the database.'
|
|
9
|
+
db_error_list: 'Failed to retrieve table data from the database.'
|
|
10
|
+
pk_not_found: 'The "%(pk_name)s" field was not found in the submitted data.'
|
|
11
|
+
record_not_found: 'No record found for %(pk_name)s=%(pk)s.'
|
|
12
|
+
connection_refused_error: 'Database connection error: %(error)s'
|
|
13
|
+
filters_exception: 'An unknown technical error occurred while filtering data.'
|
|
14
|
+
method_not_allowed: 'Error, method not allowed. This action is not permitted.'
|
|
15
|
+
filter_error: 'An error occurred during filtering: {error}'
|
|
16
|
+
|
|
11
17
|
search_help: 'Available search fields: %(fields)s'
|
|
12
18
|
sqlalchemy_search_help: |
|
|
13
19
|
<b>Available search fields:</b>
|
|
@@ -17,6 +23,3 @@ sqlalchemy_search_help: |
|
|
|
17
23
|
<b>""</b> - quotes for exact match
|
|
18
24
|
<b>%%</b> - any sequence of characters
|
|
19
25
|
<b>_</b> - any single character
|
|
20
|
-
filters_exception: 'An unknown technical error occurred while filtering data.'
|
|
21
|
-
method_not_allowed: 'Error, method not allowed. This action is not permitted.'
|
|
22
|
-
filter_error: 'An error occurred during filtering: {error}'
|
brilliance_admin/locales/ru.yml
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
delete: 'Удалить'
|
|
2
2
|
delete_confirmation_text: "Вы уверены, что хотите удалить данные записи?\nДанное действие нельзя отменить."
|
|
3
3
|
deleted_successfully: 'Записи успешно удалены.'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
|
|
5
|
+
errors:
|
|
6
|
+
pk_not_found: 'Поле "%(pk_name)s" не найдено среди переданных данных.'
|
|
7
|
+
record_not_found: 'Запись по ключу %(pk_name)s=%(pk)s не найдена.'
|
|
8
|
+
db_error_create: 'Ошибка создания записи в базе данных.'
|
|
9
|
+
db_error_update: 'Ошибка обновления записи в базе данных.'
|
|
10
|
+
db_error_retrieve: 'Ошибка получения записи из базы данных.'
|
|
11
|
+
db_error_list: 'Ошибка получения данных таблицы из базы данных.'
|
|
12
|
+
connection_refused_error: 'Ошибка подключения к базе данных: %(error)s'
|
|
13
|
+
filters_exception: 'Произошла неизвестная техническая ошибка при фильтрации данных.'
|
|
14
|
+
method_not_allowed: 'Ошибка, данный метод недоступен.'
|
|
15
|
+
filter_error: 'Проишла ошибка при фильтрации: %(error)s'
|
|
16
|
+
serialize_field_error: 'Ошибка чтения данных: %(error)s'
|
|
17
|
+
|
|
11
18
|
search_help: 'Доступные поля для поиска: %(fields)s'
|
|
12
19
|
sqlalchemy_search_help: |
|
|
13
20
|
<b>Доступные поля для поиска:</b>
|
|
@@ -17,6 +24,3 @@ sqlalchemy_search_help: |
|
|
|
17
24
|
<b>""</b> - кавычки для точного совпадения
|
|
18
25
|
<b>%%</b> - любая последовательность символов
|
|
19
26
|
<b>_</b> - один любой символ
|
|
20
|
-
filters_exception: 'Произошла неизвестная техническая ошибка при фильтрации данных.'
|
|
21
|
-
method_not_allowed: 'Ошибка, данный метод недоступен.'
|
|
22
|
-
filter_error: 'Проишла ошибка при фильтрации: {error}'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import datetime
|
|
3
|
-
from
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any, ClassVar
|
|
4
5
|
|
|
5
6
|
from pydantic.dataclasses import dataclass
|
|
6
7
|
|
|
@@ -52,6 +53,8 @@ class TableField(abc.ABC, FieldSchemaData):
|
|
|
52
53
|
class IntegerField(TableField):
|
|
53
54
|
_type = 'integer'
|
|
54
55
|
|
|
56
|
+
choices: Any | None = None
|
|
57
|
+
|
|
55
58
|
max_value: int | None = None
|
|
56
59
|
min_value: int | None = None
|
|
57
60
|
|
|
@@ -62,8 +65,6 @@ class IntegerField(TableField):
|
|
|
62
65
|
def generate_schema(self, user, field_slug, language_context: LanguageContext) -> FieldSchemaData:
|
|
63
66
|
schema = super().generate_schema(user, field_slug, language_context)
|
|
64
67
|
|
|
65
|
-
schema.choices = self.choices
|
|
66
|
-
|
|
67
68
|
if self.max_value is not None:
|
|
68
69
|
schema.max_value = self.max_value
|
|
69
70
|
|
|
@@ -95,13 +96,12 @@ class StringField(TableField):
|
|
|
95
96
|
min_length: int | None = None
|
|
96
97
|
max_length: int | None = None
|
|
97
98
|
|
|
98
|
-
choices:
|
|
99
|
+
choices: Any | None = None
|
|
99
100
|
|
|
100
101
|
def generate_schema(self, user, field_slug, language_context: LanguageContext) -> FieldSchemaData:
|
|
101
102
|
schema = super().generate_schema(user, field_slug, language_context)
|
|
102
103
|
|
|
103
104
|
schema.multilined = self.multilined
|
|
104
|
-
schema.choices = self.choices
|
|
105
105
|
schema.ckeditor = self.ckeditor
|
|
106
106
|
schema.tinymce = self.tinymce
|
|
107
107
|
|
|
@@ -227,23 +227,52 @@ class ImageField(TableField):
|
|
|
227
227
|
class ChoiceField(TableField):
|
|
228
228
|
_type = 'choice'
|
|
229
229
|
|
|
230
|
+
# Tag color available:
|
|
230
231
|
# https://vuetifyjs.com/en/styles/colors/#classes
|
|
231
|
-
|
|
232
|
+
choices: Any | None = None
|
|
232
233
|
|
|
233
234
|
# https://vuetifyjs.com/en/components/chips/#color-and-variants
|
|
234
235
|
variant: str = 'elevated'
|
|
235
236
|
size: str = 'default'
|
|
236
237
|
|
|
238
|
+
def __post_init__(self):
|
|
239
|
+
self.choices = self.generate_choices()
|
|
240
|
+
|
|
241
|
+
def generate_choices(self):
|
|
242
|
+
if not self.choices:
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
if issubclass(self.choices, Enum):
|
|
246
|
+
return [
|
|
247
|
+
{'value': c.value, 'title': c.label, 'tag_color': getattr(c, 'tag_color', None)}
|
|
248
|
+
for c in self.choices
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
msg = f'Field choices is not suppored: {self.choices}'
|
|
252
|
+
raise NotImplementedError(msg)
|
|
253
|
+
|
|
254
|
+
def find_choice(self, value):
|
|
255
|
+
if not self.choices:
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
return next((c for c in self.choices if c.get('value') == value), None)
|
|
259
|
+
|
|
237
260
|
def generate_schema(self, user, field_slug, language_context: LanguageContext) -> FieldSchemaData:
|
|
238
261
|
schema = super().generate_schema(user, field_slug, language_context)
|
|
239
262
|
|
|
240
263
|
schema.choices = self.choices
|
|
241
264
|
|
|
242
|
-
schema.tag_colors = self.tag_colors
|
|
243
265
|
schema.size = self.size
|
|
244
266
|
schema.variant = self.variant
|
|
245
267
|
|
|
246
268
|
return schema
|
|
247
269
|
|
|
248
270
|
async def serialize(self, value, extra: dict, *args, **kwargs) -> Any:
|
|
249
|
-
|
|
271
|
+
if not value:
|
|
272
|
+
return
|
|
273
|
+
|
|
274
|
+
choice = self.find_choice(value)
|
|
275
|
+
return {
|
|
276
|
+
'value': value,
|
|
277
|
+
'title': choice.get('title') or value if choice else value.capitalize(),
|
|
278
|
+
}
|
|
@@ -148,9 +148,10 @@ class FieldsSchema:
|
|
|
148
148
|
list_display=self.list_display,
|
|
149
149
|
)
|
|
150
150
|
|
|
151
|
+
context = {'language_context': language_context}
|
|
151
152
|
for field_slug, field in self.get_fields().items():
|
|
152
153
|
field_schema: FieldSchemaData = field.generate_schema(user, field_slug, language_context)
|
|
153
|
-
fields_schema.fields[field_slug] = field_schema.to_dict(keep_none=False)
|
|
154
|
+
fields_schema.fields[field_slug] = field_schema.to_dict(keep_none=False, context=context)
|
|
154
155
|
|
|
155
156
|
return fields_schema
|
|
156
157
|
|
brilliance_admin/translations.py
CHANGED
|
@@ -63,14 +63,14 @@ class LanguageManager(abc.ABC):
|
|
|
63
63
|
|
|
64
64
|
builtin_locales_dir = resources.files("brilliance_admin").joinpath("locales")
|
|
65
65
|
self.phrases.load_folder(builtin_locales_dir)
|
|
66
|
-
logger.
|
|
66
|
+
logger.debug('Language manager builtin dir loaded: %s', builtin_locales_dir)
|
|
67
67
|
|
|
68
68
|
if locales_dir:
|
|
69
69
|
self.phrases.load_folder(locales_dir)
|
|
70
|
-
logger.
|
|
70
|
+
logger.debug('Language manager locales_dir loaded: %s', locales_dir)
|
|
71
71
|
|
|
72
72
|
langs = ', '.join(self.phrases.data.keys())
|
|
73
|
-
logger.
|
|
73
|
+
logger.debug('Language manager setup completed; languages: %s', langs)
|
|
74
74
|
|
|
75
75
|
def get_text(self, text, language) -> str:
|
|
76
76
|
if not isinstance(text, TranslateText):
|
brilliance_admin/utils.py
CHANGED
|
@@ -42,8 +42,8 @@ class DataclassBase:
|
|
|
42
42
|
adapter = TypeAdapter(type(self))
|
|
43
43
|
return adapter.dump_python(self, *args, **kwargs)
|
|
44
44
|
|
|
45
|
-
def to_dict(self, keep_none=True) -> dict:
|
|
46
|
-
data = self.model_dump()
|
|
45
|
+
def to_dict(self, *args, keep_none=True, **kwargs) -> dict:
|
|
46
|
+
data = self.model_dump(*args, **kwargs)
|
|
47
47
|
return {
|
|
48
48
|
k: v for k, v in data.items()
|
|
49
49
|
if v is not None and not keep_none
|
|
@@ -150,4 +150,4 @@ class YamlI18n:
|
|
|
150
150
|
if isinstance(node, str):
|
|
151
151
|
return node
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
return slug
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: brilliance-admin
|
|
3
|
-
Version: 0.43.
|
|
3
|
+
Version: 0.43.5
|
|
4
4
|
Summary: Simple and lightweight admin panel framework powered by FastAPI and Vue3 Vuetify together.. Some call it heavenly in its brilliance.
|
|
5
5
|
License-Expression: AGPL-3.0
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -2,8 +2,8 @@ brilliance_admin/__init__.py,sha256=qxGzLVhFNm2FKL2lVt7bEFb6pTPqyXEQvUsDfyfv6SM,
|
|
|
2
2
|
brilliance_admin/auth.py,sha256=d57XRfLJIbOosLP1-0SCFkePPT8M5WhLcwxu4yW92RA,673
|
|
3
3
|
brilliance_admin/docs.py,sha256=fKeJKuiCCi1jHRmNcmkuDD6_2di7bwc6-w8V1VCTu0s,1231
|
|
4
4
|
brilliance_admin/exceptions.py,sha256=7_L3qVTwdLrzmDJjGv2yqCOVECP35wh0NyTvgjP7ETc,913
|
|
5
|
-
brilliance_admin/translations.py,sha256=
|
|
6
|
-
brilliance_admin/utils.py,sha256=
|
|
5
|
+
brilliance_admin/translations.py,sha256=I_iSfj05Qv5fbZqDvnnHZGUFsi1wk-J0EXSftKBLw5Q,3850
|
|
6
|
+
brilliance_admin/utils.py,sha256=RB88GC3qeysP1PpUGiXSgUZRpdxHGLB0FRgramScLaA,4584
|
|
7
7
|
brilliance_admin/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
brilliance_admin/api/routers.py,sha256=GXz-GFXRH5VbDH1r5O9LLnnmaMhbQq4RctzVEubHnsk,810
|
|
9
9
|
brilliance_admin/api/utils.py,sha256=ezvHK49OlpCdT9fLB41Y1nswZDLdzC3zTcQtGtuTYUk,999
|
|
@@ -17,32 +17,32 @@ brilliance_admin/api/views/settings.py,sha256=2A9suZQONEtW9LkFban29Fe5ipQaaGT0Cz
|
|
|
17
17
|
brilliance_admin/api/views/table.py,sha256=29vLEwueHWBS8Dq6nBvujwy4CTs9v8ZcM1ErF9lYgIc,5932
|
|
18
18
|
brilliance_admin/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
brilliance_admin/integrations/sqlalchemy/__init__.py,sha256=tIegMU2eIW_zA-PdblCXCjenHAY4sGBUWKuz97ns4gE,275
|
|
20
|
-
brilliance_admin/integrations/sqlalchemy/auth.py,sha256=
|
|
20
|
+
brilliance_admin/integrations/sqlalchemy/auth.py,sha256=NvOLKeeSJuNTzFhisNO9R3sEmGRS8IQrCwghPrtuzaw,4924
|
|
21
21
|
brilliance_admin/integrations/sqlalchemy/autocomplete.py,sha256=baRroMwGg35uR5zt-aiQc2-ugX4hpwNf79R6bZH9UX0,1416
|
|
22
|
-
brilliance_admin/integrations/sqlalchemy/fields.py,sha256=
|
|
23
|
-
brilliance_admin/integrations/sqlalchemy/fields_schema.py,sha256=
|
|
22
|
+
brilliance_admin/integrations/sqlalchemy/fields.py,sha256=DmxaxI4IaUgh4mgk_LeP-kSd6cKtBTtilfPcOlYLKjo,9520
|
|
23
|
+
brilliance_admin/integrations/sqlalchemy/fields_schema.py,sha256=7WkOrt5dVvrsZppNZEZS8QaQPMSrfcWChwOaOFSRVOg,11419
|
|
24
24
|
brilliance_admin/integrations/sqlalchemy/table/__init__.py,sha256=g_in2pLTi8UQnT5uNFA8mLW5mxlT84irQ7yVaP_OSS4,605
|
|
25
|
-
brilliance_admin/integrations/sqlalchemy/table/base.py,sha256
|
|
26
|
-
brilliance_admin/integrations/sqlalchemy/table/create.py,sha256=
|
|
27
|
-
brilliance_admin/integrations/sqlalchemy/table/delete.py,sha256=
|
|
28
|
-
brilliance_admin/integrations/sqlalchemy/table/list.py,sha256
|
|
29
|
-
brilliance_admin/integrations/sqlalchemy/table/retrieve.py,sha256=
|
|
30
|
-
brilliance_admin/integrations/sqlalchemy/table/update.py,sha256=
|
|
31
|
-
brilliance_admin/locales/en.yml,sha256=
|
|
32
|
-
brilliance_admin/locales/ru.yml,sha256=
|
|
25
|
+
brilliance_admin/integrations/sqlalchemy/table/base.py,sha256=-osqhTvqE7YcBxsAjqIUMWyYk1df04GIDmdvtieTXcg,4885
|
|
26
|
+
brilliance_admin/integrations/sqlalchemy/table/create.py,sha256=QY_Hbn4iu6Kq7reFsEUC-isCvcDK6vU4n5F0Bo1EOEs,2714
|
|
27
|
+
brilliance_admin/integrations/sqlalchemy/table/delete.py,sha256=toH9at-MAWO46K_4YmvkOqXX2-cFANVVhAURiZ-dwWQ,738
|
|
28
|
+
brilliance_admin/integrations/sqlalchemy/table/list.py,sha256=WPH4GoLrIU-TcGMrNoq46i3sJIz6vV76UaacmtG3Ytk,6720
|
|
29
|
+
brilliance_admin/integrations/sqlalchemy/table/retrieve.py,sha256=O6mJ_XxfLJ59Hx_V5VdAZNxObkY6p5L7gZED8QGXfy0,2744
|
|
30
|
+
brilliance_admin/integrations/sqlalchemy/table/update.py,sha256=RfIXTQHHEoZCrOtVeOxZ3ql0-is5czsgVAfO_1_gF7w,3578
|
|
31
|
+
brilliance_admin/locales/en.yml,sha256=hq4ktzZZYmfbI7RVHHwvkUD9qjETMW1Fq2DQPCQAPao,1159
|
|
32
|
+
brilliance_admin/locales/ru.yml,sha256=ySYstybcfNhWUgdYeTnepaddgOlPTu4cIAWKLAVYLeo,1770
|
|
33
33
|
brilliance_admin/schema/__init__.py,sha256=X-izShvv84jkFU47WfpUwtvRh3NOv570iUB3NRNEIDU,248
|
|
34
34
|
brilliance_admin/schema/admin_schema.py,sha256=fKVtaLkFkDF8ZkjIftackZ4rfCDcqLvci8PO6ZLycgc,6393
|
|
35
|
-
brilliance_admin/schema/category.py,sha256=
|
|
35
|
+
brilliance_admin/schema/category.py,sha256=hkE4BJQeNbjtuloIgkNEy8Fz068lcMK98-lnZADClg4,4070
|
|
36
36
|
brilliance_admin/schema/group.py,sha256=Gdz3ME_EfQP_CFPou6OOJZWGWXKIYgB3zNX_oWsClwE,2240
|
|
37
37
|
brilliance_admin/schema/graphs/__init__.py,sha256=qvmZv9QWdiutPtN5VYQLYbsjY2SOg8p_XRaz2rUlIxY,44
|
|
38
38
|
brilliance_admin/schema/graphs/category_graphs.py,sha256=2nj_oiAoGXwGhc-gNVNFMNKDCkCdUWVn6u9CRCsb2DA,1513
|
|
39
39
|
brilliance_admin/schema/table/__init__.py,sha256=vuRw8HBuak2LaTZi2dNn5YOrJPalQps-O3Ht-d0AZV4,378
|
|
40
40
|
brilliance_admin/schema/table/admin_action.py,sha256=0ymRL9DKkBK-AF6wKy7K9R4hkmblh55eHuZA_rjO1Lk,2018
|
|
41
41
|
brilliance_admin/schema/table/category_table.py,sha256=BNdxspZ9Di6_bX0QQEGxgZLlddC7GIAWjBYha6bLtZo,6449
|
|
42
|
-
brilliance_admin/schema/table/fields_schema.py,sha256=
|
|
42
|
+
brilliance_admin/schema/table/fields_schema.py,sha256=Tlnxpzb1RgMKLDqFpRD3t6x9lDEAf--hnmzRC3vHZpo,8350
|
|
43
43
|
brilliance_admin/schema/table/table_models.py,sha256=xidraifRYbXGkiVLn6dJ96dkOhW8-22ynE-fbiOjfAU,1018
|
|
44
44
|
brilliance_admin/schema/table/fields/__init__.py,sha256=RW-sIFTAaSQo4mMR6iWtnefogWPjmg6KAsDwe9mKW1k,291
|
|
45
|
-
brilliance_admin/schema/table/fields/base.py,sha256=
|
|
45
|
+
brilliance_admin/schema/table/fields/base.py,sha256=fllUue5ZWj8qA8FGm72zyLHDNyGCkWHLxzpTx6dLLXQ,8507
|
|
46
46
|
brilliance_admin/schema/table/fields/function_field.py,sha256=4fm9kS8zpBG5oqp9sA81NQDHiqvU0BQmpf-wjkTuuwM,1780
|
|
47
47
|
brilliance_admin/static/index-D9axz5zK.js,sha256=KB_EHC9hoBK_LinkeMaE897Ws4Tl8xlJ8c_smbis_VE,3202111
|
|
48
48
|
brilliance_admin/static/index-vlBToOhT.css,sha256=hoVCpcStTHdAVRm37k1umrNdXjOwIIveu9lxk4ocpEc,983028
|
|
@@ -67,8 +67,8 @@ brilliance_admin/static/tinymce/plugins/codesample/css/prism.css,sha256=exAdMtHb
|
|
|
67
67
|
brilliance_admin/static/tinymce/plugins/customLink/plugin.js,sha256=illBNpnHDkBsLG6wo_jDPF6z7CGnO1MQWUoDwZKy6vQ,5589
|
|
68
68
|
brilliance_admin/static/tinymce/plugins/customLink/css/link.css,sha256=gh5nvY8Z92hJfCEBPnIm4jIPCcKKbJnab-30oIfX7Hc,56
|
|
69
69
|
brilliance_admin/templates/index.html,sha256=ZLJ_TKUvBDIo_hYfbW43ov0S_bFrzBF-283XP6BKtDI,1294
|
|
70
|
-
brilliance_admin-0.43.
|
|
71
|
-
brilliance_admin-0.43.
|
|
72
|
-
brilliance_admin-0.43.
|
|
73
|
-
brilliance_admin-0.43.
|
|
74
|
-
brilliance_admin-0.43.
|
|
70
|
+
brilliance_admin-0.43.5.dist-info/licenses/LICENSE,sha256=PjeDRXGbVLtKul5Xpfco_6CyB6bYGWVVPrO0oubquuM,727
|
|
71
|
+
brilliance_admin-0.43.5.dist-info/METADATA,sha256=9XHeRi6ZkN894lYJSjesSnB-3A9CsMwB8DEonYnWLrI,7459
|
|
72
|
+
brilliance_admin-0.43.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
73
|
+
brilliance_admin-0.43.5.dist-info/top_level.txt,sha256=almFFSWrVYieI3i54hYL0fMUaeuIYiazS2Kx4wtK-ns,17
|
|
74
|
+
brilliance_admin-0.43.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|