Add organizations v2 API and registry enrichment
This commit is contained in:
1
src/organizations/management/__init__.py
Normal file
1
src/organizations/management/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
src/organizations/management/commands/__init__.py
Normal file
1
src/organizations/management/commands/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Populate canonical organizations from existing source tables."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from apps.core.management.commands.base import BaseAppCommand
|
||||
|
||||
from organizations.services import OrganizationPopulationService
|
||||
|
||||
|
||||
class Command(BaseAppCommand):
|
||||
"""Populate organizations directory from current database records."""
|
||||
|
||||
help = "Заполняет справочник organizations.Organization из существующих данных БД"
|
||||
use_transaction = True
|
||||
|
||||
def execute_command(self, *args, **options) -> str:
|
||||
result = OrganizationPopulationService.populate()
|
||||
rendered = json.dumps(
|
||||
{
|
||||
"scanned": result.scanned,
|
||||
"created": result.created,
|
||||
"updated": result.updated,
|
||||
"skipped": result.skipped,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
)
|
||||
self.log_success(rendered)
|
||||
return rendered
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Refresh precomputed organization data snapshots."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from apps.core.management.commands.base import BaseAppCommand
|
||||
|
||||
from organizations.services import OrganizationDataSnapshotRefreshService
|
||||
|
||||
|
||||
class Command(BaseAppCommand):
|
||||
"""Refresh organizations_data_snapshot rows for API v2."""
|
||||
|
||||
help = "Пересобирает organizations_data_snapshot для API v2"
|
||||
use_transaction = False
|
||||
|
||||
def add_arguments(self, parser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument(
|
||||
"--uid",
|
||||
action="append",
|
||||
dest="uids",
|
||||
default=None,
|
||||
help="UID организации. Можно передать несколько раз.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--batch-size",
|
||||
type=int,
|
||||
default=100,
|
||||
help="Размер пачки организаций для пересборки.",
|
||||
)
|
||||
|
||||
def execute_command(self, *args, **options) -> str:
|
||||
result = OrganizationDataSnapshotRefreshService.refresh(
|
||||
organization_uids=options.get("uids"),
|
||||
batch_size=options["batch_size"],
|
||||
)
|
||||
rendered = json.dumps(
|
||||
{
|
||||
"processed": result.processed,
|
||||
"created": result.created,
|
||||
"updated": result.updated,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
)
|
||||
self.log_success(rendered)
|
||||
return rendered
|
||||
Reference in New Issue
Block a user