2017-03-09 06:55:33 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
2022-11-11 11:20:17 +00:00
|
|
|
import uuid
|
2018-03-30 14:03:43 +00:00
|
|
|
|
2017-03-09 06:55:33 +00:00
|
|
|
from django.db import models
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2017-12-10 16:29:25 +00:00
|
|
|
|
2022-10-08 08:55:14 +00:00
|
|
|
from common.utils import get_logger
|
2017-03-09 06:55:33 +00:00
|
|
|
|
2022-11-29 11:44:12 +00:00
|
|
|
__all__ = ["AdHoc"]
|
2017-03-09 06:55:33 +00:00
|
|
|
|
2024-09-06 09:41:09 +00:00
|
|
|
from common.db.models import JMSBaseModel
|
|
|
|
from ops.const import AdHocModules, Scope
|
2022-12-15 09:25:21 +00:00
|
|
|
|
2017-12-22 13:42:12 +00:00
|
|
|
logger = get_logger(__file__)
|
2017-03-09 06:55:33 +00:00
|
|
|
|
|
|
|
|
2024-09-06 09:41:09 +00:00
|
|
|
class AdHoc(JMSBaseModel):
|
2022-11-11 11:20:17 +00:00
|
|
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
|
|
|
name = models.CharField(max_length=128, verbose_name=_('Name'))
|
2022-10-08 08:55:14 +00:00
|
|
|
pattern = models.CharField(max_length=1024, verbose_name=_("Pattern"), default='all')
|
2023-09-21 07:57:04 +00:00
|
|
|
module = models.CharField(max_length=128, choices=AdHocModules.choices, default=AdHocModules.shell,
|
2022-11-11 11:20:17 +00:00
|
|
|
verbose_name=_('Module'))
|
2023-04-13 07:47:16 +00:00
|
|
|
args = models.CharField(max_length=8192, default='', verbose_name=_('Args'))
|
2022-11-29 11:44:12 +00:00
|
|
|
creator = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)
|
2022-11-29 11:52:48 +00:00
|
|
|
comment = models.CharField(max_length=1024, default='', verbose_name=_('Comment'), null=True, blank=True)
|
2024-09-06 09:41:09 +00:00
|
|
|
scope = models.CharField(max_length=64, default=Scope.public, verbose_name=_('Scope'))
|
2022-11-29 11:52:48 +00:00
|
|
|
|
2022-11-11 11:20:17 +00:00
|
|
|
@property
|
|
|
|
def row_count(self):
|
|
|
|
if len(self.args) == 0:
|
|
|
|
return 0
|
|
|
|
count = str(self.args).count('\n')
|
|
|
|
return count + 1
|
2022-10-08 11:12:04 +00:00
|
|
|
|
2022-11-11 11:20:17 +00:00
|
|
|
@property
|
|
|
|
def size(self):
|
|
|
|
return len(self.args)
|
2017-12-21 18:08:29 +00:00
|
|
|
|
2017-12-15 07:50:15 +00:00
|
|
|
def __str__(self):
|
2022-10-08 08:55:14 +00:00
|
|
|
return "{}: {}".format(self.module, self.args)
|
2022-12-23 07:49:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
2024-09-06 09:41:09 +00:00
|
|
|
unique_together = [('name', 'creator')]
|
2023-02-15 03:17:57 +00:00
|
|
|
verbose_name = _("Adhoc")
|