Bladeren bron

Merge remote-tracking branch 'origin/master'

tanghongbin 4 jaren geleden
bovenliggende
commit
d66b3fb2ac
4 gewijzigde bestanden met toevoegingen van 135 en 53 verwijderingen
  1. 75 39
      controller/LangArea.py
  2. 1 1
      web/login.html
  3. 29 6
      web/new_searchTool.html
  4. 30 7
      web/old_searchTool.html

+ 75 - 39
controller/LangArea.py

@@ -125,14 +125,15 @@ class LangAreaView(TemplateView):
         elif type == 'link_ios' or type == 'link_android':
             langType = (4, 5, 6, 7)
 
-        en_qs = LangKeyModel.objects.filter(langvalmodel__la__id=20, type__in=langType).values('word_key', 'langvalmodel__word_val')
+        en_qs = LangKeyModel.objects.filter(langvalmodel__la__id=20, type__in=langType).values('word_key',
+                                                                                               'langvalmodel__word_val')
         en_kv = {}
         for e in en_qs:
             en_kv[e['word_key']] = e['langvalmodel__word_val']
 
         content = ''
         if type == 'ios' or type == 'link_ios':
-            res_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=langType).\
+            res_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=langType). \
                 values('word_key', 'langvalmodel__word_val')
             res = {}
             for r in res_qs:
@@ -145,7 +146,7 @@ class LangAreaView(TemplateView):
                 content_val = res[l].replace('"', '\'')
                 content = content + '"' + l + '"="' + content_val + '";\n'
         elif type == 'android' or type == 'link_android':
-            res_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=langType).\
+            res_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=langType). \
                 values('word_key', 'langvalmodel__word_val').order_by('addTime')
             res = {}
             for r in res_qs:
@@ -186,16 +187,15 @@ class LangAreaView(TemplateView):
         elif type == 'avss':
             content = self.do_download_avss(id)
         elif type == 'new_searchTool':
-            content = self.do_download_SearchTool(id,0)
+            content = self.do_download_SearchTool(id, 0)
         elif type == 'old_searchTool':
-            content = self.do_download_SearchTool(id,1)
+            content = self.do_download_SearchTool(id, 1)
         response = StreamingHttpResponse(content)
         response['Content-Type'] = 'application/octet-stream'
         response['Content-Disposition'] = 'attachment;filename="lang.txt"'
         return response
         return response.json(0, res)
 
-
     def do_download_avss(self, id):
         content = ''
         en_result = self.get_area_language(20)
@@ -238,7 +238,8 @@ class LangAreaView(TemplateView):
                     print(message)
                     for location in locations:
                         if location['filename'] != '':
-                            content += '<location filename=\"' + location['filename'] + '\" line=\"' + str(location['line']) + '\"/>\n'
+                            content += '<location filename=\"' + location['filename'] + '\" line=\"' + str(
+                                location['line']) + '\"/>\n'
                     content += '</message>\n'
                 content += '</context>\n'
             content += '</TS>'
@@ -248,15 +249,13 @@ class LangAreaView(TemplateView):
 
         return content
 
-
-
     def get_area_language(self, id):
         result = {}
         lkc_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=(2, 3, 6, 7)).values('word_key',
-                                                                                                 'langkeyclassmodel__clazz__name',
-                                                                                                 'langvalmodel__word_val',
-                                                                                                 'langlocationmodel__filename',
-                                                                                                 'langlocationmodel__line')
+                                                                                                    'langkeyclassmodel__clazz__name',
+                                                                                                    'langvalmodel__word_val',
+                                                                                                    'langlocationmodel__filename',
+                                                                                                    'langlocationmodel__line')
         for lkc in lkc_qs:
             # print(lkc)
             name = lkc['langkeyclassmodel__clazz__name']
@@ -279,6 +278,35 @@ class LangAreaView(TemplateView):
         print(result)
         return result
 
+    def get_area_language_search(self, id):
+        result = {}
+        lkc_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, project__id=4).values('word_key',
+                                                                             'searchtoolkeymodel__bk__name',
+                                                                             'langvalmodel__word_val',
+                                                                             'langlocationmodel__filename',
+                                                                             'langlocationmodel__line')
+        for lkc in lkc_qs:
+            # print(lkc)
+            name = lkc['searchtoolkeymodel__bk__name']
+            hasClass = result.__contains__(name)
+            if hasClass is False:
+                result[name] = {}
+
+            source = lkc['word_key']
+            if not result[name].__contains__(source):
+                result[name][source] = {}
+            message = result[name][source]
+
+            message['source'] = source[(len(name) + 1):]
+            message['translation'] = lkc['langvalmodel__word_val']
+
+            # location
+            locations = []
+            locations.append({'filename': lkc['langlocationmodel__filename'], 'line': lkc['langlocationmodel__line']})
+            message['locations'] = locations
+        print(result)
+        return result
+
     def get_avss_language(self, id):
         if id == 18:  # 简体中文
             return 'zh_CN'
@@ -313,42 +341,49 @@ class LangAreaView(TemplateView):
 
     def do_download_SearchTool(self, id, searchtype):
         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")
-        if block_qs:
+        en_result = self.get_area_language_search(20)
+        print(en_result)
+        target_result = self.get_area_language_search(id)
+        if target_result:
             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')
-
-            for bk in block_qs:
+            # keys = result.keys()
+            keys = en_result.keys()
+            for key in keys:
                 content += '<context>\n<name>'
-                content += bk['name']
+                content += key
                 content += '</name>\n'
 
-                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:
+                messages = None
+                if target_result.__contains__(key):
+                    messages = target_result[key]
+                else:
+                    messages = en_result[key]
+                messageKeys = en_result[key].keys()
+                for messageKey in messageKeys:
+                    message = None
+                    if messages.__contains__(messageKey):
+                        message = messages[messageKey]
+                    else:
+                        message = en_result[key][messageKey]
+
+                    # message = messages[messageKey]
                     content += '<message>\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 += langKey['word_key'][(langKey['word_key'].index('_')+1):] # 截取第一个'_'后面的内容
+                    content += message['source']
                     content += '</source>\n'
                     content += '<translation>'
-                    translation = langKey['langvalmodel__word_val'] if langKey['langvalmodel__word_val'] is not None else ''
+                    translation = message['translation']
+                    # if translation is None or translation == '':
+                    #     content += '23333'
+                    # else:
                     content += translation
                     content += '</translation>\n'
+                    locations = message['locations']
+                    print(message)
+                    for location in locations:
+                        if location['filename'] != '':
+                            content += '<location filename=\"' + location['filename'] + '\" line=\"' + str(
+                                location['line']) + '\"/>\n'
                     content += '</message>\n'
                 content += '</context>\n'
             content += '</TS>'
@@ -358,6 +393,7 @@ class LangAreaView(TemplateView):
 
         return content
 
+
 class exportLangView(TemplateView):
     def post(self, request, *args, **kwargs):
         request.encoding = 'utf-8'

+ 1 - 1
web/login.html

@@ -197,7 +197,7 @@
                     setCookie('access_token', data['res']['access_token'], data['res']['access_expire'])
                     setCookie('refresh_token', data['res']['refresh_token'], data['res']['refresh_expire'])
                     setCookie('role', data['res']['role_type'], data['res']['access_expire'])
-
+                    setCookie('username',username);
                     if(data['res']['project_perm']) {
                         setCookie('project_perm', JSON.stringify(data['res']['project_perm']), data['res']['access_expire']);
                     }

+ 29 - 6
web/new_searchTool.html

@@ -109,15 +109,15 @@
     <div class="tab-content" style="overflow: auto">
         <section class="tab-item-1" style="height: 100%;width: 100%;display: block">
             <ul id="myTab" class="nav nav-tabs">
-                <li class="active">
+                <li  id="li1">
                     <a href="#context" data-toggle="tab">context</a>
                 </li>
-                <li><a href="#key" data-toggle="tab">key</a></li>
-                <li><a href="#location" data-toggle="tab">location</a></li>
-                <li><a href="#translation" data-toggle="tab">translation</a></li>
+                <li id="li2"><a href="#key" data-toggle="tab">key</a></li>
+                <li id="li3"><a href="#location" data-toggle="tab">location</a></li>
+                <li id="li4"><a href="#translation" data-toggle="tab">translation</a></li>
             </ul>
 
-            <div class="tab-pane fade in active" id="context">
+            <div class="tab-pane fade" id="context">
                 <div class="container-fluid">
                     <div class="row">
                         <div id="contextsearchCheckBox" class="col-md-8"></div>
@@ -399,11 +399,34 @@
     var project_id = 4 ;
     $(function(){
 
+        var username = $.cookie("username");
+
+         $("li").hide();
+        if(username =="admin"){
+
+           $("li").show();
+           $("#li1").addClass("active");
+           $("#context").addClass(" in active");
+        }else {
+
+            $("#li4").show();
+             $("#li4").addClass("active");
+            $("#translation").tab("show");
+            var $tabs = $('#myTab').children( 'li' );
+            $tabs.removeClass("active");
+            $tabs.each( function(i, n) {
+                var $tab = $( this );
+               if($tab[0].innerText=="translation"){
+                   $tab.addClass("active");
+                   $("#translation").addClass(" in active");
+               }
+            });
+        }
+
         initQueryUrl();
         initTagTable();
 
 
-
         $("#myTab a").click(function(e){
             e.preventDefault();
             $(this).tab("show");

+ 30 - 7
web/old_searchTool.html

@@ -69,7 +69,7 @@
     <span>Zosi Link</span><i class="fa fa-language"></i>
     </div>
 
-     <div class="menu">
+      <div class="menu">
         <input type="radio" class="tab-7" name="tab" onclick="location.href='new_searchTool.html'" >
         <span> New Search Tool</span><i class="fa fa-language"></i>
      </div>
@@ -109,15 +109,15 @@
     <div class="tab-content" style="overflow: auto">
         <section class="tab-item-1" style="height: 100%;width: 100%;display: block">
             <ul id="myTab" class="nav nav-tabs">
-                <li class="active">
+                <li  id="li1">
                     <a href="#context" data-toggle="tab">context</a>
                 </li>
-                <li><a href="#key" data-toggle="tab">key</a></li>
-                <li><a href="#location" data-toggle="tab">location</a></li>
-                <li><a href="#translation" data-toggle="tab">translation</a></li>
+                <li id="li2"><a href="#key" data-toggle="tab">key</a></li>
+                <li id="li3"><a href="#location" data-toggle="tab">location</a></li>
+                <li id="li4"><a href="#translation" data-toggle="tab">translation</a></li>
             </ul>
 
-            <div class="tab-pane fade in active" id="context">
+            <div class="tab-pane fade" id="context">
                 <div class="container-fluid">
                     <div class="row">
                         <div id="contextsearchCheckBox" class="col-md-8"></div>
@@ -399,11 +399,34 @@
     var project_id = 4 ;
     $(function(){
 
+        var username = $.cookie("username");
+
+         $("li").hide();
+        if(username =="admin"){
+
+           $("li").show();
+           $("#li1").addClass("active");
+           $("#context").addClass(" in active");
+        }else {
+
+            $("#li4").show();
+             $("#li4").addClass("active");
+            $("#translation").tab("show");
+            var $tabs = $('#myTab').children( 'li' );
+            $tabs.removeClass("active");
+            $tabs.each( function(i, n) {
+                var $tab = $( this );
+               if($tab[0].innerText=="translation"){
+                   $tab.addClass("active");
+                   $("#translation").addClass(" in active");
+               }
+            });
+        }
+
         initQueryUrl();
         initTagTable();
 
 
-
         $("#myTab a").click(function(e){
             e.preventDefault();
             $(this).tab("show");