Browse Source

feat: 修改command filter数据结构

pull/4092/head
ibuler 5 years ago
parent
commit
1a6597b572
  1. 8
      apps/assets/api/asset.py
  2. 12
      apps/assets/serializers/cmd_filter.py
  3. 1
      apps/common/drf/renders/csv.py

8
apps/assets/api/asset.py

@ -77,9 +77,13 @@ class AssetPlatformViewSet(ModelViewSet):
filter_fields = ['name', 'base']
search_fields = ['name']
def get_permissions(self):
if self.request.method.lower() in ['get', 'options']:
self.permission_classes = (IsOrgAdmin,)
return super().get_permissions()
def check_object_permissions(self, request, obj):
if request.method.lower() in ['delete', 'put', 'patch'] and \
obj.internal:
if request.method.lower() in ['delete', 'put', 'patch'] and obj.internal:
self.permission_denied(
request, message={"detail": "Internal platform"}
)

12
apps/assets/serializers/cmd_filter.py

@ -2,7 +2,6 @@
#
import re
from rest_framework import serializers
from django.utils.translation import ugettext_lazy as _
from common.fields import ChoiceDisplayField
from common.serializers import AdaptedBulkListSerializer
@ -27,11 +26,20 @@ class CommandFilterSerializer(BulkOrgResourceModelSerializer):
class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer):
serializer_choice_field = ChoiceDisplayField
# serializer_choice_field = ChoiceDisplayField
invalid_pattern = re.compile(r'[\.\*\+\[\\\?\{\}\^\$\|\(\)\#\<\>]')
type_display = serializers.ReadOnlyField(source='get_type_display')
action_display = serializers.ReadOnlyField(source='get_action_display')
class Meta:
model = CommandFilterRule
fields_mini = ['id']
fields_small = fields_mini + [
'type', 'type_display', 'content', 'priority',
'action', 'action_display',
'comment', 'created_by', 'date_created', 'date_updated'
]
fields_fk = ['filter']
fields = '__all__'
list_serializer_class = AdaptedBulkListSerializer

1
apps/common/drf/renders/csv.py

@ -30,6 +30,7 @@ class JMSCSVRender(BaseRenderer):
@staticmethod
def _gen_table(data, fields):
data = data[:100]
yield ['*{}'.format(f.label) if f.required else f.label for f in fields]
for item in data:

Loading…
Cancel
Save