From 24b1c87121c22159eb9fd83f0a2b6c26fa27e814 Mon Sep 17 00:00:00 2001 From: Bai Date: Sat, 2 Jan 2021 07:47:43 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tickets/api/assignee.py | 6 +++--- apps/tickets/api/comment.py | 2 +- apps/tickets/api/ticket/ticket.py | 10 +++++----- apps/tickets/migrations/0007_auto_20201224_1821.py | 7 ++++++- apps/tickets/models/ticket/model.py | 2 +- apps/tickets/permissions/ticket.py | 1 - 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/tickets/api/assignee.py b/apps/tickets/api/assignee.py index eb835c522..faf02860b 100644 --- a/apps/tickets/api/assignee.py +++ b/apps/tickets/api/assignee.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- # - from rest_framework import viewsets -from users.models import User from common.permissions import IsValidUser from common.exceptions import JMSException +from users.models import User from orgs.utils import get_org_by_id from .. import serializers @@ -20,7 +19,8 @@ class AssigneeViewSet(viewsets.ReadOnlyModelViewSet): org_id = self.request.query_params.get('org_id') org = get_org_by_id(org_id) if not org: - raise JMSException('The organization `{}` does not exist'.format(org_id)) + error = ('The organization `{}` does not exist'.format(org_id)) + raise JMSException(error) return org def get_queryset(self): diff --git a/apps/tickets/api/comment.py b/apps/tickets/api/comment.py index e96176580..a9f79e5f3 100644 --- a/apps/tickets/api/comment.py +++ b/apps/tickets/api/comment.py @@ -15,7 +15,7 @@ __all__ = ['CommentViewSet'] class CommentViewSet(mixins.CreateModelMixin, viewsets.ReadOnlyModelViewSet): serializer_class = serializers.CommentSerializer - permission_classes = (IsSwagger| IsAssignee | IsApplicant,) + permission_classes = (IsSwagger | IsAssignee | IsApplicant,) @lazyproperty def ticket(self): diff --git a/apps/tickets/api/ticket/ticket.py b/apps/tickets/api/ticket/ticket.py index 658939d0d..db5a8850d 100644 --- a/apps/tickets/api/ticket/ticket.py +++ b/apps/tickets/api/ticket/ticket.py @@ -5,12 +5,13 @@ from rest_framework import viewsets from rest_framework.decorators import action from rest_framework.exceptions import MethodNotAllowed +from common.const.http import POST, PUT from common.mixins.api import CommonApiMixin from common.permissions import IsValidUser, IsOrgAdmin -from common.const.http import POST, PUT -from tickets import serializers, const -from tickets.permissions.ticket import IsAssignee, NotClosed + +from tickets import serializers from tickets.models import Ticket +from tickets.permissions.ticket import IsAssignee, NotClosed __all__ = ['TicketViewSet'] @@ -67,7 +68,6 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet): def get_dynamic_mapping_fields_mapping_rule(self): from tickets.serializers.ticket.meta import get_meta_field_mapping_rule_by_view meta_field_mapping_rule = get_meta_field_mapping_rule_by_view(self) - fields_mapping_rule = { + return { 'meta': meta_field_mapping_rule, } - return fields_mapping_rule diff --git a/apps/tickets/migrations/0007_auto_20201224_1821.py b/apps/tickets/migrations/0007_auto_20201224_1821.py index daa771fa4..cb55b2fd1 100644 --- a/apps/tickets/migrations/0007_auto_20201224_1821.py +++ b/apps/tickets/migrations/0007_auto_20201224_1821.py @@ -76,7 +76,12 @@ def migrate_tickets_fields_name(apps, schema_editor): ticket.type = migrate_field_type(ticket.type) ticket.meta = migrate_field_meta(ticket.type, ticket.meta) ticket.meta['body'] = ticket.body - ticket.save() + + fields = [ + 'applicant', 'applicant_display', 'processor', 'processor_display', + 'assignees_display_new', 'action', 'type', 'meta' + ] + ticket_model.origin_objects.bulk_update(tickets, fields) class Migration(migrations.Migration): diff --git a/apps/tickets/models/ticket/model.py b/apps/tickets/models/ticket/model.py index f211959b2..2defd41ee 100644 --- a/apps/tickets/models/ticket/model.py +++ b/apps/tickets/models/ticket/model.py @@ -135,7 +135,7 @@ class Ticket(TicketModelMixin, CommonModelMixin, OrgModelMixin): self.set_action_close() self.save() - # + # ticket def has_assignee(self, assignee): return self.assignees.filter(id=assignee.id).exists() diff --git a/apps/tickets/permissions/ticket.py b/apps/tickets/permissions/ticket.py index 1ad00b8a5..c16db9fe6 100644 --- a/apps/tickets/permissions/ticket.py +++ b/apps/tickets/permissions/ticket.py @@ -9,5 +9,4 @@ class IsAssignee(permissions.BasePermission): class NotClosed(permissions.BasePermission): def has_object_permission(self, request, view, obj): - return True return not obj.status_closed