jumpserver/apps/assets/models/platform.py

44 lines
1.4 KiB
Python
Raw Normal View History

2022-04-02 10:35:46 +00:00
from django.db import models
from django.utils.translation import gettext_lazy as _
2022-04-07 10:51:35 +00:00
from assets.const import Category, AllTypes
2022-04-02 10:35:46 +00:00
from common.fields.model import JsonDictTextField
2022-04-20 02:15:20 +00:00
2022-04-02 10:35:46 +00:00
__all__ = ['Platform']
class Platform(models.Model):
CHARSET_CHOICES = (
('utf8', 'UTF-8'),
('gbk', 'GBK'),
)
name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True)
2022-04-07 10:51:35 +00:00
category = models.CharField(max_length=16, choices=Category.choices, verbose_name=_("Category"))
2022-04-12 09:53:56 +00:00
type = models.CharField(choices=AllTypes.choices, max_length=32, default='Linux', verbose_name=_("Type"))
2022-04-02 10:35:46 +00:00
charset = models.CharField(default='utf8', choices=CHARSET_CHOICES, max_length=8, verbose_name=_("Charset"))
meta = JsonDictTextField(blank=True, null=True, verbose_name=_("Meta"))
internal = models.BooleanField(default=False, verbose_name=_("Internal"))
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
@classmethod
def default(cls):
linux, created = cls.objects.get_or_create(
defaults={'name': 'Linux'}, name='Linux'
)
return linux.id
def is_windows(self):
2022-04-12 09:53:56 +00:00
return self.type.lower() in ('windows',)
2022-04-02 10:35:46 +00:00
def is_unixlike(self):
2022-04-12 09:53:56 +00:00
return self.type.lower() in ("linux", "unix", "macos", "bsd")
2022-04-02 10:35:46 +00:00
def __str__(self):
return self.name
class Meta:
verbose_name = _("Platform")
# ordering = ('name',)