11# coding=utf-8
22"""
3- @project: MaxKB
4- @Author:虎虎
5- @file: application_version.py
6- @date:2025/6/3 16:25
7- @desc:
3+ @project: MaxKB
4+ @Author:虎虎
5+ @file: application_version.py
6+ @date:2025/6/3 16:25
7+ @desc:
88"""
9+
910from typing import Dict
1011
1112from django .db .models import QuerySet
1920
2021class ApplicationVersionQuerySerializer (serializers .Serializer ):
2122 application_id = serializers .UUIDField (required = True , label = _ ("Application ID" ))
22- name = serializers .CharField (required = False , allow_null = True , allow_blank = True ,
23- label = _ ("summary" ))
23+ name = serializers .CharField (required = False , allow_null = True , allow_blank = True , label = _ ("summary" ))
2424
2525
2626class ApplicationVersionModelSerializer (serializers .ModelSerializer ):
2727 class Meta :
2828 model = ApplicationVersion
29- fields = ['id' , 'name' , 'workspace_id' , 'application_id' , 'work_flow' , 'publish_user_id' , 'publish_user_name' ,
30- 'create_time' ,
31- 'update_time' ]
29+ fields = [
30+ "id" ,
31+ "name" ,
32+ "publish_desc" ,
33+ "workspace_id" ,
34+ "application_id" ,
35+ "work_flow" ,
36+ "publish_user_id" ,
37+ "publish_user_name" ,
38+ "create_time" ,
39+ "update_time" ,
40+ ]
3241
3342
3443class ApplicationVersionEditSerializer (serializers .Serializer ):
35- name = serializers .CharField (required = False , max_length = 128 , allow_null = True , allow_blank = True ,
36- label = _ ("Version Name" ))
44+ name = serializers .CharField (
45+ required = False , max_length = 128 , allow_null = True , allow_blank = True , label = _ ("Version Name" )
46+ )
47+ publish_desc = serializers .CharField (
48+ required = False , max_length = 1024 , allow_null = True , allow_blank = True , label = _ ("Publish Description" )
49+ )
3750
3851
3952class ApplicationVersionSerializer (serializers .Serializer ):
@@ -43,11 +56,11 @@ class Query(serializers.Serializer):
4356 workspace_id = serializers .CharField (required = False , allow_null = True , allow_blank = True , label = _ ("Workspace ID" ))
4457
4558 def get_query_set (self , query ):
46- query_set = QuerySet (ApplicationVersion ).filter (application_id = query .get (' application_id' ))
47- if ' name' in query and query .get (' name' ) is not None :
48- query_set = query_set .filter (name__contains = query .get (' name' ))
49- if ' workspace_id' in self .data and self .data .get (' workspace_id' ) is not None :
50- query_set = query_set .filter (workspace_id = self .data .get (' workspace_id' ))
59+ query_set = QuerySet (ApplicationVersion ).filter (application_id = query .get (" application_id" ))
60+ if " name" in query and query .get (" name" ) is not None :
61+ query_set = query_set .filter (name__contains = query .get (" name" ))
62+ if " workspace_id" in self .data and self .data .get (" workspace_id" ) is not None :
63+ query_set = query_set .filter (workspace_id = self .data .get (" workspace_id" ))
5164 return query_set .order_by ("-create_time" )
5265
5366 def list (self , query , with_valid = True ):
@@ -60,48 +73,57 @@ def list(self, query, with_valid=True):
6073 def page (self , query , current_page , page_size , with_valid = True ):
6174 if with_valid :
6275 self .is_valid (raise_exception = True )
63- return page_search (current_page , page_size ,
64- self .get_query_set (query ),
65- post_records_handler = lambda v : ApplicationVersionModelSerializer (v ).data )
76+ return page_search (
77+ current_page ,
78+ page_size ,
79+ self .get_query_set (query ),
80+ post_records_handler = lambda v : ApplicationVersionModelSerializer (v ).data ,
81+ )
6682
6783 class Operate (serializers .Serializer ):
6884 workspace_id = serializers .CharField (required = False , allow_null = True , allow_blank = True , label = _ ("Workspace ID" ))
6985 application_id = serializers .UUIDField (required = True , label = _ ("Application ID" ))
70- application_version_id = serializers .UUIDField (required = True ,
71- label = _ ("Application version ID" ))
86+ application_version_id = serializers .UUIDField (required = True , label = _ ("Application version ID" ))
7287
7388 def is_valid (self , * , raise_exception = False ):
7489 super ().is_valid (raise_exception = True )
75- workspace_id = self .data .get (' workspace_id' )
76- query_set = QuerySet (Application ).filter (id = self .data .get (' application_id' ))
90+ workspace_id = self .data .get (" workspace_id" )
91+ query_set = QuerySet (Application ).filter (id = self .data .get (" application_id" ))
7792 if workspace_id :
7893 query_set = query_set .filter (workspace_id = workspace_id )
7994 if not query_set .exists ():
80- raise AppApiException (500 , _ (' Application id does not exist' ))
95+ raise AppApiException (500 , _ (" Application id does not exist" ))
8196
8297 def one (self , with_valid = True ):
8398 if with_valid :
8499 self .is_valid (raise_exception = True )
85- application_version = QuerySet (ApplicationVersion ).filter (application_id = self .data .get ('application_id' ),
86- id = self .data .get (
87- 'application_version_id' )).first ()
100+ application_version = (
101+ QuerySet (ApplicationVersion )
102+ .filter (application_id = self .data .get ("application_id" ), id = self .data .get ("application_version_id" ))
103+ .first ()
104+ )
88105 if application_version is not None :
89106 return ApplicationVersionModelSerializer (application_version ).data
90107 else :
91- raise AppApiException (500 , _ (' Workflow version does not exist' ))
108+ raise AppApiException (500 , _ (" Workflow version does not exist" ))
92109
93110 def edit (self , instance : Dict , with_valid = True ):
94111 if with_valid :
95112 self .is_valid (raise_exception = True )
96113 ApplicationVersionEditSerializer (data = instance ).is_valid (raise_exception = True )
97- application_version = QuerySet (ApplicationVersion ).filter (application_id = self .data .get ('application_id' ),
98- id = self .data .get (
99- 'application_version_id' )).first ()
114+ application_version = (
115+ QuerySet (ApplicationVersion )
116+ .filter (application_id = self .data .get ("application_id" ), id = self .data .get ("application_version_id" ))
117+ .first ()
118+ )
100119 if application_version is not None :
101- name = instance .get ('name' , None )
120+ name = instance .get ("name" , None )
121+ publish_desc = instance .get ("publish_desc" , None )
102122 if name is not None and len (name ) > 0 :
103123 application_version .name = name
124+ if publish_desc is not None and len (publish_desc ) > 0 :
125+ application_version .publish_desc = publish_desc
104126 application_version .save ()
105127 return ApplicationVersionModelSerializer (application_version ).data
106128 else :
107- raise AppApiException (500 , _ (' Workflow version does not exist' ))
129+ raise AppApiException (500 , _ (" Workflow version does not exist" ))
0 commit comments