Commit c99a2b7f authored by BaiJiangJie's avatar BaiJiangJie

[Feature] 应用管理: Database 添加Model、APIView

parent ebd92547
from .remote_app import *
from .database import *
# coding: utf-8
#
from rest_framework.pagination import LimitOffsetPagination
from rest_framework_bulk import BulkModelViewSet
from ..hands import IsOrgAdmin
from ..models import Database
from ..serializers import DatabaseSerializer
__all__ = ['DataBaseViewSet']
class DataBaseViewSet(BulkModelViewSet):
filter_fields = ('name',)
search_fields = filter_fields
permission_classes = (IsOrgAdmin,)
queryset = Database.objects.all()
serializer_class = DatabaseSerializer
pagination_class = LimitOffsetPagination
from .remote_app import *
from .database import *
# coding: utf-8
#
import uuid
from django.db import models
from django.utils.translation import ugettext_lazy as _
from orgs.mixins import OrgModelMixin
from common.validators import alphanumeric
from common import fields
__all__ = ['Database']
class Database(OrgModelMixin):
LOGIN_AUTO = 'auto'
LOGIN_MANUAL = 'manual'
LOGIN_MODE_CHOICES = (
(LOGIN_AUTO, _('Automatic login')),
(LOGIN_MANUAL, _('Manually login'))
)
TYPE_MYSQL = 'mysql'
TYPE_CHOICES = (
(TYPE_MYSQL, _('MySQL')),
)
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, verbose_name=_('Name'))
login_mode = models.CharField(
choices=LOGIN_MODE_CHOICES, default=LOGIN_AUTO, max_length=10,
verbose_name=_('Login mode')
)
type = models.CharField(
choices=TYPE_CHOICES, default=TYPE_MYSQL, max_length=10,
verbose_name=_('Type')
)
host = models.CharField(max_length=128, verbose_name=_('Host'))
port = models.IntegerField(default=3306, verbose_name=_('Port'))
user = models.CharField(
max_length=32, blank=True, null=True, validators=[alphanumeric],
verbose_name=_('User')
)
password = fields.EncryptCharField(
max_length=256, blank=True, null=True, verbose_name=_('Password')
)
database = models.CharField(
max_length=128, blank=True, null=True, verbose_name=_('Database')
)
comment = models.TextField(blank=True, verbose_name=_('Comment'))
created_by = models.CharField(
max_length=128, null=True, verbose_name=_('Created by')
)
date_created = models.DateTimeField(
auto_now_add=True, verbose_name=_('Date Created')
)
date_updated = models.DateTimeField(
auto_now=True, verbose_name=_('Date updated')
)
class Meta:
verbose_name = _('Database')
unique_together = [('org_id', 'name')]
ordering = ('name',)
def __str__(self):
return self.name
from .remote_app import *
from .database import *
# coding: utf-8
#
from common.serializers import AdaptedBulkListSerializer
from orgs.mixins import BulkOrgResourceModelSerializer
from ..models import Database
__all__ = ['DatabaseSerializer']
class DatabaseSerializer(BulkOrgResourceModelSerializer):
class Meta:
model = Database
list_serializer_class = AdaptedBulkListSerializer
fields = [
'id', 'name', 'login_mode', 'host', 'port', 'user', 'password',
'database', 'comment', 'created_by', 'date_created', 'date_updated',
]
read_only_fields = [
'created_by', 'date_created', 'date_updated'
]
extra_kwargs = {
'password': {'write_only': True},
}
......@@ -11,6 +11,7 @@ app_name = 'applications'
router = BulkRouter()
router.register(r'remote-apps', api.RemoteAppViewSet, 'remote-app')
router.register(r'databases', api.DataBaseViewSet, 'database')
urlpatterns = [
path('remote-apps/<uuid:pk>/connection-info/',
......@@ -18,7 +19,7 @@ urlpatterns = [
name='remote-app-connection-info')
]
old_version_urlpatterns = [
re_path('(?P<resource>remote-app)/.*', capi.redirect_plural_name_api)
re_path('(?P<resource>remote-app|database)/.*', capi.redirect_plural_name_api)
]
urlpatterns += router.urls + old_version_urlpatterns
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment