Browse Source

perf: 修改 labels 搜索 (#12379)

* perf: 修改标签的搜索

* perf: 修改 labels 搜索

---------

Co-authored-by: ibuler <ibuler@qq.com>
pull/12382/head
fit2bot 11 months ago committed by GitHub
parent
commit
6544f8ade8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      apps/common/serializers/fields.py
  2. 7
      apps/tickets/serializers/ticket/ticket.py

11
apps/common/serializers/fields.py

@ -57,19 +57,10 @@ class EncryptedField(serializers.CharField):
class LabeledChoiceField(ChoiceField):
def __init__(self, *args, **kwargs):
super(LabeledChoiceField, self).__init__(*args, **kwargs)
@property
def choice_mapper(self):
return {
key: value for key, value in self.choices.items()
}
def to_representation(self, key):
if key is None:
return key
label = self.choice_mapper.get(key, key)
label = self.choices.get(key, key)
return {"value": key, "label": label}
def to_internal_value(self, data):

7
apps/tickets/serializers/ticket/ticket.py

@ -39,10 +39,9 @@ class TicketSerializer(OrgResourceModelSerializerMixin):
tp = self.fields.get('type')
if not tp:
return
excluded_value = TicketType.general
self.fields['type'].choices = [
(value, label) for value, label in tp.choices.items() if value != excluded_value
]
choices = tp.choices
choices.pop(TicketType.general, None)
tp.choices = choices.items()
@classmethod
def setup_eager_loading(cls, queryset):

Loading…
Cancel
Save