educommon 3.18.0__py3-none-any.whl → 3.19.1__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.
- educommon/audit_log/management/commands/reinstall_audit_log.py +5 -0
- educommon/audit_log/sql/install_audit_log.sql +6 -2
- educommon/audit_log/utils/__init__.py +24 -0
- educommon/utils/enums.py +36 -0
- {educommon-3.18.0.dist-info → educommon-3.19.1.dist-info}/METADATA +1 -1
- {educommon-3.18.0.dist-info → educommon-3.19.1.dist-info}/RECORD +8 -7
- {educommon-3.18.0.dist-info → educommon-3.19.1.dist-info}/WHEEL +0 -0
- {educommon-3.18.0.dist-info → educommon-3.19.1.dist-info}/top_level.txt +0 -0
@@ -10,6 +10,9 @@ from django.core.management.base import (
|
|
10
10
|
from django.db import (
|
11
11
|
connection,
|
12
12
|
)
|
13
|
+
from psycopg2.extras import (
|
14
|
+
Json,
|
15
|
+
)
|
13
16
|
|
14
17
|
from educommon.audit_log.constants import (
|
15
18
|
INSTALL_AUDIT_LOG_SQL_FILE_NAME,
|
@@ -19,6 +22,7 @@ from educommon.audit_log.constants import (
|
|
19
22
|
from educommon.audit_log.utils import (
|
20
23
|
clear_audit_logs,
|
21
24
|
configure,
|
25
|
+
get_auto_now_fields_by_model,
|
22
26
|
get_db_connection_params,
|
23
27
|
)
|
24
28
|
|
@@ -69,6 +73,7 @@ class Command(BaseCommand):
|
|
69
73
|
"""Подготовка SQL-кода."""
|
70
74
|
params = get_db_connection_params()
|
71
75
|
params['lock_id'] = PG_LOCK_ID
|
76
|
+
params['auto_now_fields'] = Json(get_auto_now_fields_by_model())
|
72
77
|
|
73
78
|
self.stdout.write('preparing SQL-code..\n')
|
74
79
|
|
@@ -188,6 +188,8 @@ DECLARE
|
|
188
188
|
operation_code INTEGER;
|
189
189
|
len INTEGER;
|
190
190
|
text_error TEXT;
|
191
|
+
auto_now_field_names TEXT[];
|
192
|
+
all_changed_have_auto_now BOOLEAN;
|
191
193
|
BEGIN
|
192
194
|
operation_code := 0;
|
193
195
|
user_id := audit.get_param('audit_log.user_id');
|
@@ -202,8 +204,10 @@ BEGIN
|
|
202
204
|
data := hstore(OLD);
|
203
205
|
changes := hstore(NEW) - hstore(OLD);
|
204
206
|
len := array_length(akeys(changes),1);
|
205
|
-
|
206
|
-
|
207
|
+
auto_now_field_names := ARRAY(SELECT jsonb_array_elements_text({auto_now_fields}::jsonb -> TG_TABLE_NAME::TEXT));
|
208
|
+
all_changed_have_auto_now := auto_now_field_names @> akeys(changes);
|
209
|
+
-- Если изменений нет или изменения, только в автообновляемых полях, то не логируем.
|
210
|
+
IF (len IS NOT NULL OR len = 0) AND NOT all_changed_have_auto_now THEN
|
207
211
|
result_value := NEW;
|
208
212
|
operation_code := 2;
|
209
213
|
END IF;
|
@@ -469,3 +469,27 @@ def get_audit_log_context(request):
|
|
469
469
|
result['ip'] = get_ip(request)
|
470
470
|
|
471
471
|
return result
|
472
|
+
|
473
|
+
|
474
|
+
def get_auto_now_fields_by_model() -> dict[str, list[str]]:
|
475
|
+
"""Возвращает словарь с полями, имеющими auto_now=True, для моделей с флагом need_to_log = True.
|
476
|
+
|
477
|
+
Returns:
|
478
|
+
Словарь, где ключ это название таблицы, а значение это список названий полей имеющими auto_now=True.
|
479
|
+
"""
|
480
|
+
auto_now_fields = {}
|
481
|
+
|
482
|
+
for model in apps.get_models():
|
483
|
+
if not getattr(model, 'need_to_log', False):
|
484
|
+
continue
|
485
|
+
|
486
|
+
auto_now_field_names = [
|
487
|
+
field.name
|
488
|
+
for field in model._meta.get_fields()
|
489
|
+
if getattr(field, 'auto_now', False)
|
490
|
+
]
|
491
|
+
|
492
|
+
if auto_now_field_names:
|
493
|
+
auto_now_fields[model._meta.db_table] = auto_now_field_names
|
494
|
+
|
495
|
+
return auto_now_fields
|
educommon/utils/enums.py
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
from enum import (
|
2
|
+
Enum,
|
3
|
+
)
|
4
|
+
from functools import (
|
5
|
+
lru_cache,
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
class NamedIntEnum(Enum):
|
10
|
+
|
11
|
+
"""Базовый класс для набора пар число + строка.
|
12
|
+
|
13
|
+
Пример использования:
|
14
|
+
.. code-block:: python
|
15
|
+
class Status(NamedIntEnum):
|
16
|
+
|
17
|
+
NEW = (1, 'Новый')
|
18
|
+
PROGRESS = (2, 'В процессе')
|
19
|
+
CLOSED = (3, 'Закрыт')
|
20
|
+
|
21
|
+
"""
|
22
|
+
|
23
|
+
def __init__(self, id_: int, verbose: str) -> None:
|
24
|
+
self.id = id_
|
25
|
+
self.verbose = verbose
|
26
|
+
|
27
|
+
@classmethod
|
28
|
+
@lru_cache(maxsize=1)
|
29
|
+
def get_choices(cls) -> tuple[tuple[int, str], ...]:
|
30
|
+
return tuple((value.id, value.verbose) for value in cls)
|
31
|
+
|
32
|
+
def as_dict(self, *, verbose_field: str = 'verbose'):
|
33
|
+
return {
|
34
|
+
'id': self.id,
|
35
|
+
verbose_field: self.verbose,
|
36
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: educommon
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.19.1
|
4
4
|
Summary: Общая кодовая база для проектов БЦ Образование
|
5
5
|
Author-email: BARS Group <education_dev@bars-open.ru>
|
6
6
|
Project-URL: Homepage, https://stash.bars-open.ru/projects/EDUBASE/repos/educommon/browse
|
@@ -58,7 +58,7 @@ educommon/audit_log/error_log/actions.py,sha256=-KSy3RrBsbPWCML-gl5Hl5UGQdEsPZho
|
|
58
58
|
educommon/audit_log/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
59
59
|
educommon/audit_log/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
60
60
|
educommon/audit_log/management/commands/audit_log_migrate_data.py,sha256=J_ZIpamGVBcotc-6cYsz37AJADEEyuiUs-VVyKON47o,12695
|
61
|
-
educommon/audit_log/management/commands/reinstall_audit_log.py,sha256=
|
61
|
+
educommon/audit_log/management/commands/reinstall_audit_log.py,sha256=xr56lxpMtxR-KB3lKOmqYVmJ0aUOqzYSeod_6XYQmjc,3722
|
62
62
|
educommon/audit_log/migrations/0001_initial.py,sha256=HDhvBNyVSx_NlFmyA-t_ooFo_TiKf0UHNCZp1GOpLA8,6115
|
63
63
|
educommon/audit_log/migrations/0002_install_audit_log.py,sha256=kAhtd1Xz8b6g33wmxBQyRBJIl-LGJdOc7yFy5yhoRJ8,2825
|
64
64
|
educommon/audit_log/migrations/0003_logproxy.py,sha256=fx6nCoDtr3bZTtlwiOKP4QTVPxnnqyYDPMAT20Bv4n8,391
|
@@ -71,8 +71,8 @@ educommon/audit_log/migrations/0009_reinstall_audit_log.py,sha256=c95H2yamWyrCoG
|
|
71
71
|
educommon/audit_log/migrations/0010_alter_auditlog_time.py,sha256=XmujmdgNADMy4OhL4O7CIK6KDKtW2sSyfxLYWEGmtvI,509
|
72
72
|
educommon/audit_log/migrations/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
73
73
|
educommon/audit_log/sql/configure_audit_log.sql,sha256=M3QxNKTZbn-uNRxGDvNxE9iJh1EOQUTIho7rvc3yhlY,1511
|
74
|
-
educommon/audit_log/sql/install_audit_log.sql,sha256=
|
75
|
-
educommon/audit_log/utils/__init__.py,sha256=
|
74
|
+
educommon/audit_log/sql/install_audit_log.sql,sha256=EhyhGMYn8aYCGEBNC2AC7kuG5vfJiAPxhwTMq_2NADE,14505
|
75
|
+
educommon/audit_log/utils/__init__.py,sha256=FKktT7EeO3M1wqYYSnsgEQ6pSyY4OEzSAXP87ZitI5Q,17239
|
76
76
|
educommon/audit_log/utils/operations.py,sha256=skxL7wE4Jx1XlNdPx-Pl3SfiZ1G9jBmcZrXKSQDUGzw,2555
|
77
77
|
educommon/auth/__init__.py,sha256=xkGJgqQ5QaEU86n6tJV77ux-2bMTAKbjpVYBCDhcS0E,79
|
78
78
|
educommon/auth/rbac/__init__.py,sha256=guO7sOX6e1Z-dqptsqXjbnMdgbSdKp2suDKJa5_pdVU,317
|
@@ -290,6 +290,7 @@ educommon/utils/caching.py,sha256=eHf4xa6loSCCv9Is5XE8G4Fvi3_bzmwKIUHv9tyPDDw,40
|
|
290
290
|
educommon/utils/conversion.py,sha256=C7FHCQQG5eVbeFRulWv_WvBzIq10hsHjZB3VchlbDiY,1960
|
291
291
|
educommon/utils/crypto.py,sha256=kmoX1ntu8tYeobbSxLmyj5kKFabCRQriEfZIxCI7fuM,2139
|
292
292
|
educommon/utils/date.py,sha256=bnwEBMUDR3GYnGLEAYBZnnt-7M2toA1jZAba9Lk1J_A,16676
|
293
|
+
educommon/utils/enums.py,sha256=jc9JJ7FTbe0ynyLtQ6M7G7ESk5lF9tWu6aGlx4C7Jb0,864
|
293
294
|
educommon/utils/misc.py,sha256=6gMFsLoSTktuIv96-6-oouLLdMkSZQyKITz4sXlh-nM,4392
|
294
295
|
educommon/utils/object_grid.py,sha256=2ap8593I7Rs_-H3cTrQcIfEa57lrQ0AtcD119-xEwTU,8705
|
295
296
|
educommon/utils/plugins.py,sha256=F1A1JLSi-7aBxw2kEk5Gstvx4_rIpgY1D5M4bmbK2AA,9344
|
@@ -351,7 +352,7 @@ educommon/ws_log/smev/exceptions.py,sha256=VNfzNHlj5Pz8D4979d_msTkxC-RQVoMctsgoJ
|
|
351
352
|
educommon/ws_log/templates/report/smev_logs.xlsx,sha256=nnYgB0Z_ix8HoxsRICjsZfFRQBdra-5Gd8nWhCxTjYg,10439
|
352
353
|
educommon/ws_log/templates/ui-js/smev-logs-list-window.js,sha256=AGup3D8GTJSY9WdDPj0zBJeYQBFOmGgcbxPOJbKK-nY,513
|
353
354
|
educommon/ws_log/templates/ui-js/smev-logs-report-setting-window.js,sha256=nQ7QYK9frJcE7g7kIt6INg9TlEEJAPPayBJgRaoTePA,1103
|
354
|
-
educommon-3.
|
355
|
-
educommon-3.
|
356
|
-
educommon-3.
|
357
|
-
educommon-3.
|
355
|
+
educommon-3.19.1.dist-info/METADATA,sha256=bTmxkUclBTbBh8nVHUJdEpjKH3hzPyKp6WeSHzmOy_U,2380
|
356
|
+
educommon-3.19.1.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
357
|
+
educommon-3.19.1.dist-info/top_level.txt,sha256=z5fbW7bz_0V1foUm_FGcZ9_MTpW3N1dBN7-kEmMowl4,10
|
358
|
+
educommon-3.19.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|