2022-01-10 11:02:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
|
|
|
from ops.mixin import PeriodTaskSerializerMixin
|
|
|
|
from common.utils import get_logger
|
2022-11-09 10:15:21 +00:00
|
|
|
from common.const.choices import Trigger
|
|
|
|
from common.drf.fields import LabeledChoiceField
|
2022-01-10 11:02:18 +00:00
|
|
|
|
2022-09-20 08:18:23 +00:00
|
|
|
from assets.models import AccountBackupPlan, AccountBackupPlanExecution
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
__all__ = ['AccountBackupPlanSerializer', 'AccountBackupPlanExecutionSerializer']
|
|
|
|
|
|
|
|
|
|
|
|
class AccountBackupPlanSerializer(PeriodTaskSerializerMixin, BulkOrgResourceModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = AccountBackupPlan
|
|
|
|
fields = [
|
|
|
|
'id', 'name', 'is_periodic', 'interval', 'crontab', 'date_created',
|
|
|
|
'date_updated', 'created_by', 'periodic_display', 'comment',
|
2022-11-07 09:01:28 +00:00
|
|
|
'recipients', 'types'
|
2022-01-10 11:02:18 +00:00
|
|
|
]
|
|
|
|
extra_kwargs = {
|
|
|
|
'name': {'required': True},
|
|
|
|
'periodic_display': {'label': _('Periodic perform')},
|
|
|
|
'recipients': {'label': _('Recipient'), 'help_text': _(
|
|
|
|
'Currently only mail sending is supported'
|
|
|
|
)}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class AccountBackupPlanExecutionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AccountBackupPlanExecution
|
2022-11-09 10:15:21 +00:00
|
|
|
read_only_fields = [
|
2022-01-10 11:02:18 +00:00
|
|
|
'id', 'date_start', 'timedelta', 'plan_snapshot', 'trigger', 'reason',
|
|
|
|
'is_success', 'org_id', 'recipients'
|
2022-11-09 10:15:21 +00:00
|
|
|
]
|
|
|
|
fields = read_only_fields + ['plan']
|