[Update] 修改协议小问题

pull/1571/head
ibuler 2018-07-17 17:09:36 +08:00
parent 4d1da56872
commit 790652ff4d
5 changed files with 8 additions and 10 deletions

View File

@ -3,6 +3,7 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from orgs.mixins import OrgModelForm
from ..models import Domain, Asset, Gateway
from .user import PasswordAndKeyAuthForm
@ -34,7 +35,7 @@ class DomainForm(forms.ModelForm):
return instance
class GatewayForm(PasswordAndKeyAuthForm):
class GatewayForm(PasswordAndKeyAuthForm, OrgModelForm):
def save(self, commit=True):
# Because we define custom field, so we need rewrite :method: `save`

View File

@ -19,7 +19,7 @@ signer = get_signer()
class AssetUser(OrgModelMixin):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
name = models.CharField(max_length=128, verbose_name=_('Name'))
username = models.CharField(max_length=32, blank=True, verbose_name=_('Username'), validators=[alphanumeric])
_password = models.CharField(max_length=256, blank=True, null=True, verbose_name=_('Password'))
_private_key = models.TextField(max_length=4096, blank=True, null=True, verbose_name=_('SSH private key'), validators=[private_key_validator, ])

View File

@ -34,7 +34,7 @@ class Domain(OrgModelMixin):
return random.choice(self.gateways)
class Gateway(AssetUser):
class Gateway(AssetUser, OrgModelMixin):
SSH_PROTOCOL = 'ssh'
RDP_PROTOCOL = 'rdp'
PROTOCOL_CHOICES = (
@ -51,3 +51,5 @@ class Gateway(AssetUser):
def __str__(self):
return self.name
class Meta:
unique_together = ['name', 'org']

View File

@ -64,9 +64,6 @@ class Node(OrgModelMixin):
def create_child(self, value):
with transaction.atomic():
child_key = self.get_next_child_key()
print("Create child")
print(self.key)
print(child_key)
child = self.__class__.objects.create(key=child_key, value=value)
return child
@ -123,8 +120,6 @@ class Node(OrgModelMixin):
return self.get_all_assets().valid()
def is_root(self):
print(type(self.key))
print(self.key)
if self.key.isdigit():
return True
else:
@ -159,7 +154,6 @@ class Node(OrgModelMixin):
if self.is_root():
root = self.__class__.root()
return [root]
print(self.key)
_key = self.key.split(':')
if not with_self:
_key.pop()
@ -187,7 +181,6 @@ class Node(OrgModelMixin):
@classmethod
def root(cls):
root = cls.objects.filter(key__regex=r'^[0-9]+$')
print("GET ROOT NODE")
if len(root) == 1:
return root.get()
else:

View File

@ -69,6 +69,7 @@ class AdminUser(AssetUser):
class Meta:
ordering = ['name']
unique_together = ['name', 'org']
verbose_name = _("Admin user")
@classmethod
@ -156,6 +157,7 @@ class SystemUser(AssetUser):
class Meta:
ordering = ['name']
unique_together = ['name', 'org']
verbose_name = _("System user")
@classmethod