Эх сурвалжийг харах

修复newSearchTool语言下载内容格式不正确的问题

locky 4 жил өмнө
parent
commit
9298308d25
1 өөрчлөгдсөн 21 нэмэгдсэн , 24 устгасан
  1. 21 24
      controller/LangArea.py

+ 21 - 24
controller/LangArea.py

@@ -21,7 +21,7 @@ from django.utils.decorators import method_decorator
 from object.ResponseObject import ResponseObject
 from django.contrib.auth.hashers import make_password, check_password
 from model.models import UserModel, LangSetModel, LangAreaModel, LangValModel, LangKeyModel, LangKeyClassModel, \
-    SearchToolBlock, SearchToolKeyModel, LangLocationModel
+    SearchToolBlock, LangLocationModel
 import time
 from object.TokenObject import TokenObject
 from django.http import StreamingHttpResponse
@@ -315,41 +315,38 @@ class LangAreaView(TemplateView):
         content = ''
         en_result = self.get_area_language(20)
         block_qs = SearchToolBlock.objects.filter(type__contains=searchtype).values('name', 'id')
-
-        skm_qs = SearchToolBlock.objects.filter(type__contains=searchtype).values('name', 'id',
-                                                                                    "searchtoolkeymodel__lk__id")
+        # skm_qs = SearchToolBlock.objects.filter(type__contains=searchtype).values('name', 'id', "searchtoolkeymodel__lk__id")
         if block_qs:
             content += '<TS version=\"2.1\" language=\"' + self.get_avss_language(int(id)) + '\">\n'
-
-            k_list = []
-            for k in skm_qs:
-                k_list.append(k['searchtoolkeymodel__lk__id'])
-
-            key_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, id__in=k_list).values('id', 'word_key', 'langvalmodel__word_val')
-
-            loc_qs = LangLocationModel.objects.filter(lk__id__in=k_list).values('id', 'filename', 'line', 'lk__id',
-                                                                                   'lk__word_key', 'lk__updTime')
+            # k_list = []
+            # for k in skm_qs:
+            #     k_list.append(k['searchtoolkeymodel__lk__id'])
+            # key_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, id__in=k_list).values('id', 'word_key', 'langvalmodel__word_val')
+            # loc_qs = LangLocationModel.objects.filter(lk__id__in=k_list).values('id', 'filename', 'line', 'lk__id',
+            #                                                                        'lk__word_key', 'lk__updTime')
 
             for bk in block_qs:
                 content += '<context>\n<name>'
                 content += bk['name']
                 content += '</name>\n'
 
-                for lk in key_qs:
+                langKey_qs = LangKeyModel.objects.filter(word_key__startswith=bk['name']+'_').values('id', 'word_key', 'langvalmodel__word_val')
+                langKeyId_list = []
+                for langKey in langKey_qs:
+                    langKeyId_list.append(langKey['id'])
+                langLocation_qs = LangLocationModel.objects.filter(lk__id__in=langKeyId_list).values('lk__id', 'filename', 'line')
+                for langKey in langKey_qs:
                     content += '<message>\n'
-                    for loc in loc_qs:
-                        if loc['lk__id'] == lk['id'] :
-                            if loc['filename'] != '':
-                                content += '<location filename=\"' + loc['filename'] + '\" line=\"' + str(
-                                    loc['line']) + '\"/>\n'
+                    for langLocation in langLocation_qs:
+                        if langLocation['lk__id'] == langKey['id']:
+                            if langLocation['line'] != '':
+                                content += '<location filename=\"' + langLocation['filename'] + '\" line=\"' + str(
+                                    langLocation['line']) + '\"/>\n'
                     content += '<source>'
-                    content += lk['word_key']
+                    content += langKey['word_key'][(langKey['word_key'].index('_')+1):] # 截取第一个'_'后面的内容
                     content += '</source>\n'
                     content += '<translation>'
-                    translation = lk['langvalmodel__word_val']
-                    # if translation is None or translation == '':
-                    #     content += '23333'
-                    # else:
+                    translation = langKey['langvalmodel__word_val'] if langKey['langvalmodel__word_val'] is not None else ''
                     content += translation
                     content += '</translation>\n'
                     content += '</message>\n'