perf: ticket action (#9090)

Co-authored-by: feng <1304903146@qq.com>
pull/9094/head
fit2bot 2022-11-17 15:07:23 +08:00 committed by GitHub
parent 73c2155864
commit 3a62abf381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View File

@ -32,3 +32,7 @@ class ActionChoices(BitChoices):
def has_perm(cls, action_name, total):
action_value = getattr(cls, action_name)
return action_value & total == action_value
@classmethod
def display(cls, value):
return ', '.join([c.label for c in cls if c.value & value == c.value])

View File

@ -18,3 +18,6 @@ class ApplyAssetTicket(Ticket):
apply_actions = models.IntegerField(verbose_name=_('Actions'), default=ActionChoices.all())
apply_date_start = models.DateTimeField(verbose_name=_('Date start'), null=True)
apply_date_expired = models.DateTimeField(verbose_name=_('Date expired'), null=True)
def get_apply_actions_display(self):
return ActionChoices.display(self.apply_actions)

View File

@ -398,6 +398,8 @@ class Ticket(StatusMixin, CommonModelMixin):
value = self.rel_snapshot[name]
elif isinstance(field, related.ManyToManyField):
value = ', '.join(self.rel_snapshot[name])
elif isinstance(value, list):
value = ', '.join(value)
return value
def get_local_snapshot(self):

View File

@ -44,8 +44,7 @@ class ApplyAssetSerializer(BaseApplyAssetSerializer, TicketApplySerializer):
attrs['type'] = 'apply_asset'
attrs = super().validate(attrs)
if self.is_final_approval and (
not attrs.get('apply_nodes')
and not attrs.get('apply_assets')
not attrs.get('apply_nodes') and not attrs.get('apply_assets')
):
raise serializers.ValidationError({
'apply_nodes': asset_or_node_help_text,