2021-01-05 15:39:38 +00:00
|
|
|
from rest_framework import serializers
|
2021-01-03 21:27:03 +00:00
|
|
|
from applications import const
|
2021-01-05 15:39:38 +00:00
|
|
|
from . import application_category, application_type
|
2021-01-03 21:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
2021-01-06 04:44:12 +00:00
|
|
|
'category_serializer_classes_mapping',
|
|
|
|
'type_serializer_classes_mapping',
|
2021-01-05 15:39:38 +00:00
|
|
|
'get_serializer_class_by_application_type',
|
2021-01-03 21:27:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-01-06 04:44:12 +00:00
|
|
|
# define `attrs` field `category serializers mapping`
|
|
|
|
# ---------------------------------------------------
|
2021-01-03 21:27:03 +00:00
|
|
|
|
2021-01-06 04:44:12 +00:00
|
|
|
category_serializer_classes_mapping = {
|
2021-07-27 08:06:00 +00:00
|
|
|
const.AppCategory.db.value: application_category.DBSerializer,
|
|
|
|
const.AppCategory.remote_app.value: application_category.RemoteAppSerializer,
|
|
|
|
const.AppCategory.cloud.value: application_category.CloudSerializer,
|
2021-01-06 04:44:12 +00:00
|
|
|
}
|
2021-01-03 21:27:03 +00:00
|
|
|
|
2021-01-06 04:44:12 +00:00
|
|
|
# define `attrs` field `type serializers mapping`
|
|
|
|
# -----------------------------------------------
|
|
|
|
|
|
|
|
type_serializer_classes_mapping = {
|
|
|
|
# db
|
2021-07-27 08:06:00 +00:00
|
|
|
const.AppType.mysql.value: application_type.MySQLSerializer,
|
|
|
|
const.AppType.mariadb.value: application_type.MariaDBSerializer,
|
|
|
|
const.AppType.oracle.value: application_type.OracleSerializer,
|
|
|
|
const.AppType.pgsql.value: application_type.PostgreSerializer,
|
2021-11-18 08:44:33 +00:00
|
|
|
const.AppType.sqlserver.value: application_type.SQLServerSerializer,
|
2021-01-06 04:44:12 +00:00
|
|
|
# remote-app
|
2021-07-27 08:06:00 +00:00
|
|
|
const.AppType.chrome.value: application_type.ChromeSerializer,
|
|
|
|
const.AppType.mysql_workbench.value: application_type.MySQLWorkbenchSerializer,
|
|
|
|
const.AppType.vmware_client.value: application_type.VMwareClientSerializer,
|
|
|
|
const.AppType.custom.value: application_type.CustomSerializer,
|
2021-01-06 04:44:12 +00:00
|
|
|
# cloud
|
2021-07-27 08:06:00 +00:00
|
|
|
const.AppType.k8s.value: application_type.K8SSerializer
|
2021-01-03 21:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 15:39:38 +00:00
|
|
|
def get_serializer_class_by_application_type(_application_type):
|
2021-01-06 04:44:12 +00:00
|
|
|
return type_serializer_classes_mapping.get(_application_type)
|