From 9a734e7069904acec6ef25249702c3ccab3d4a58 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 13 Sep 2022 14:06:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/__init__.py | 5 +--- apps/assets/api/account/__init__.py | 4 ++++ .../api/{accounts.py => account/account.py} | 6 ++--- .../{account_backup.py => account/backup.py} | 6 ++--- .../history.py} | 6 ++--- .../template.py} | 0 .../migrations/0113_auto_20220913_1311.py | 24 +++++++++++++++++++ apps/assets/models/account.py | 9 ++++++- 8 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 apps/assets/api/account/__init__.py rename apps/assets/api/{accounts.py => account/account.py} (96%) rename apps/assets/api/{account_backup.py => account/backup.py} (93%) rename apps/assets/api/{account_history.py => account/history.py} (92%) rename apps/assets/api/{account_template.py => account/template.py} (100%) create mode 100644 apps/assets/migrations/0113_auto_20220913_1311.py diff --git a/apps/assets/api/__init__.py b/apps/assets/api/__init__.py index 14fd38e9a..5dba09522 100644 --- a/apps/assets/api/__init__.py +++ b/apps/assets/api/__init__.py @@ -2,11 +2,8 @@ from .mixin import * from .platform import * from .asset import * from .label import * -from .accounts import * +from .account import * from .node import * from .domain import * from .gathered_user import * from .favorite_asset import * -from .account_template import * -from .account_backup import * -from .account_history import * diff --git a/apps/assets/api/account/__init__.py b/apps/assets/api/account/__init__.py new file mode 100644 index 000000000..6e402a550 --- /dev/null +++ b/apps/assets/api/account/__init__.py @@ -0,0 +1,4 @@ +from .account import * +from .backup import * +from .history import * +from .template import * diff --git a/apps/assets/api/accounts.py b/apps/assets/api/account/account.py similarity index 96% rename from apps/assets/api/accounts.py rename to apps/assets/api/account/account.py index 00f569357..3e73fd353 100644 --- a/apps/assets/api/accounts.py +++ b/apps/assets/api/account/account.py @@ -9,9 +9,9 @@ from common.drf.filters import BaseFilterSet, UUIDInFilter from common.mixins import RecordViewLogMixin from common.permissions import UserConfirmation from authentication.const import ConfirmType -from ..tasks.account_connectivity import test_accounts_connectivity_manual -from ..models import Account, Node -from .. import serializers +from assets.tasks.account_connectivity import test_accounts_connectivity_manual +from assets.models import Account, Node +from assets import serializers __all__ = ['AccountFilterSet', 'AccountViewSet', 'AccountSecretsViewSet', 'AccountTaskCreateAPI'] diff --git a/apps/assets/api/account_backup.py b/apps/assets/api/account/backup.py similarity index 93% rename from apps/assets/api/account_backup.py rename to apps/assets/api/account/backup.py index bce4ce55b..79ae721f8 100644 --- a/apps/assets/api/account_backup.py +++ b/apps/assets/api/account/backup.py @@ -4,9 +4,9 @@ from rest_framework import status, viewsets from rest_framework.response import Response from orgs.mixins.api import OrgBulkModelViewSet -from .. import serializers -from ..tasks import execute_account_backup_plan -from ..models import ( +from assets import serializers +from assets.tasks import execute_account_backup_plan +from assets.models import ( AccountBackupPlan, AccountBackupPlanExecution ) diff --git a/apps/assets/api/account_history.py b/apps/assets/api/account/history.py similarity index 92% rename from apps/assets/api/account_history.py rename to apps/assets/api/account/history.py index 6ca4fd349..0db682177 100644 --- a/apps/assets/api/account_history.py +++ b/apps/assets/api/account/history.py @@ -1,9 +1,9 @@ -from assets.api.accounts import ( +from .account import ( AccountFilterSet, AccountViewSet, AccountSecretsViewSet ) from common.mixins import RecordViewLogMixin -from .. import serializers -from ..models import Account +from assets import serializers +from assets.models import Account __all__ = ['AccountHistoryViewSet', 'AccountHistorySecretsViewSet'] diff --git a/apps/assets/api/account_template.py b/apps/assets/api/account/template.py similarity index 100% rename from apps/assets/api/account_template.py rename to apps/assets/api/account/template.py diff --git a/apps/assets/migrations/0113_auto_20220913_1311.py b/apps/assets/migrations/0113_auto_20220913_1311.py new file mode 100644 index 000000000..d2d19483f --- /dev/null +++ b/apps/assets/migrations/0113_auto_20220913_1311.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.14 on 2022-09-13 05:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0112_auto_20220909_1907'), + ] + + operations = [ + migrations.AddField( + model_name='account', + name='su_from', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='su_to', to='assets.account', verbose_name='Su from'), + ), + migrations.AddField( + model_name='historicalaccount', + name='su_from', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.account', verbose_name='Su from'), + ), + ] diff --git a/apps/assets/models/account.py b/apps/assets/models/account.py index 7b9e543a2..3a9f668bf 100644 --- a/apps/assets/models/account.py +++ b/apps/assets/models/account.py @@ -10,7 +10,14 @@ __all__ = ['Account', 'AccountTemplate'] class Account(BaseAccount): - asset = models.ForeignKey('assets.Asset', related_name='accounts', on_delete=models.CASCADE, verbose_name=_('Asset')) + asset = models.ForeignKey( + 'assets.Asset', related_name='accounts', + on_delete=models.CASCADE, verbose_name=_('Asset') + ) + su_from = models.ForeignKey( + 'assets.Account', related_name='su_to', null=True, + on_delete=models.SET_NULL, verbose_name=_("Su from") + ) version = models.IntegerField(default=0, verbose_name=_('Version')) history = HistoricalRecords()