[damned-lies] Add xmltags quality check for vertimus uploaded doc po files



commit c7ea9e865f3295d6c4487baf39af9bdfe93a4f4d
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue Mar 6 14:39:14 2018 +0100

    Add xmltags quality check for vertimus uploaded doc po files

 common/static/img/qa-icon.svg           |    3 +++
 requirements.txt                        |    2 +-
 templates/about.html                    |    2 ++
 templates/base_modal.html               |    1 +
 templates/vertimus/quality-check.html   |   14 ++++++++++++++
 templates/vertimus/vertimus_detail.html |    5 ++++-
 vertimus/models.py                      |   11 ++++++++++-
 vertimus/tests/tests.py                 |   18 ++++++++++++++++++
 vertimus/tests/xml_error.po             |   30 ++++++++++++++++++++++++++++++
 vertimus/urls.py                        |    1 +
 vertimus/views.py                       |   17 ++++++++++++++++-
 11 files changed, 100 insertions(+), 4 deletions(-)
---
diff --git a/common/static/img/qa-icon.svg b/common/static/img/qa-icon.svg
new file mode 100644
index 0000000..3c93478
--- /dev/null
+++ b/common/static/img/qa-icon.svg
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";>
+<svg width="200" height="200" fill="#000000" xmlns="http://www.w3.org/2000/svg"; data-name="Layer 1" 
viewBox="0 0 100 100" x="0px" y="0px"><title>Artboard 10</title><path 
d="M26,96.86,1,76.41,15.33,62.29a27.61,27.61,0,0,1,29.69-6H62.66a6.62,6.62,0,1,1,0,13.24H49a2.19,2.19,0,0,0,0,4.38H64.48a7.8,7.8,0,0,0,5.83-2.62L87,52.26a6.87,6.87,0,0,1,10.31,9.08L76.47,85.59a16.35,16.35,0,0,1-12.32,5.6H31.62Zm63.16-85.3A2.14,2.14,0,0,0,87,9.43H65.53a2.14,2.14,0,0,0-2.14,2.14V16a2.14,2.14,0,0,0,2.14,2.14H87A2.14,2.14,0,0,0,89.12,16ZM87,42.91a2.14,2.14,0,0,0,2.14-2.14V36.29A2.14,2.14,0,0,0,87,34.16H65.53a2.14,2.14,0,0,0-2.14,2.14v4.48a2.14,2.14,0,0,0,2.14,2.14H87ZM56.18,5.85,53.73,3.4a2.18,2.18,0,0,0-3-.09l-10.15,9L35.89,8.58A2.17,2.17,0,0,0,33,8.76l-2.45,2.45a2.18,2.18,0,0,0-.11,3L39,24.09a2.17,2.17,0,0,0,3.25,0L56.25,8.85h0A2.17,2.17,0,0,0,56.18,5.85ZM53.73,28.13a2.18,2.18,0,0,0-3-.09L40.61,37l-4.72-3.69a2.17,2.17,0,0,0-2.88.18l-2.45,2.45a2.18,2.18,0,0,0-.11,3L39,48.82a2.17,2.17,0,0,0,3.25
 ,0L56.25,33.58a2.17,2.17,0,0,0-.07-3Z"></path></svg>
diff --git a/requirements.txt b/requirements.txt
index 60566cf..43704da 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,4 +3,4 @@ mysqlclient
 django-debug-toolbar
 markdown
 pyicu
-translate-toolkit>=1.9
+translate-toolkit>=2.2.0
diff --git a/templates/about.html b/templates/about.html
index 2e4e779..ad47108 100644
--- a/templates/about.html
+++ b/templates/about.html
@@ -16,6 +16,8 @@
 
 <p>{% blocktrans with link='https://www.getsentry.com/' %}Many thanks to <a href="{{ link 
}}">GetSentry.com</a> for freely providing us an account on their online logging platform.{% endblocktrans 
%}</p>
 
+<p>{% blocktrans with link='http://iconix.si/' %}Quality check icon by <a href="{{ link }}">Gregor 
Cresnar</a>.{% endblocktrans %}</p>
+
 {% if translator_credits %}
   <p>
     {% trans "This Web site has been translated in your language by:" %}
diff --git a/templates/base_modal.html b/templates/base_modal.html
index 80b0ace..991fab8 100644
--- a/templates/base_modal.html
+++ b/templates/base_modal.html
@@ -8,5 +8,6 @@
     {% block content %}{% endblock %}
 </div>
 <div class="modal-footer">
+    {% block footer %}{% endblock %}
     <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
 </div>
diff --git a/templates/vertimus/quality-check.html b/templates/vertimus/quality-check.html
new file mode 100644
index 0000000..5e42f4e
--- /dev/null
+++ b/templates/vertimus/quality-check.html
@@ -0,0 +1,14 @@
+{% extends base %}
+{% load i18n %}
+
+{% block title %}{% trans "Quality check results" %}{% endblock %}
+
+{% block content-title %}{% trans "Quality check results" %}{% endblock %}
+
+{% block content %}
+{{ results }}
+{% endblock %}
+
+{% block footer %}
+<small><i>{% blocktrans with 
url='http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pofilter.html' 
checks=checks|join:", " %}Checks ({{ checks }}) by <a href="{{ url }}" target="_blank">pofilter</a>{% 
endblocktrans %}</i></small>
+{% endblock %}
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 83858e3..ef48821 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -188,7 +188,10 @@ $(document).ready(function() {
         <a role="button" data-toggle="collapse" href="#{{ action.created|date:"Y_g_i_s" }}" 
class="visible-xs-inline" aria-expanded="false" aria-controls="collapseExample2">
                  <img alt="icon for action time" class="action_icons" src="{{ STATIC_URL }}img/clock.png">
                </a>
-        {% if action.sent_to_ml%}
+        {% if domain.dtype == 'doc' and action.has_po_file %}
+        <a href="{% url 'quality-check' action.pk %}" data-target="#modal-container" role="button" 
data-toggle="modal" title="{% trans 'Quality checks' %}"><img class="action_icons" src="{{ STATIC_URL 
}}img/qa-icon.svg" alt="help icon"></a>
+        {% endif %}
+        {% if action.sent_to_ml %}
                  <img alt="mail icon sent" class="action_icons" src="{{ STATIC_URL }}img/mail.png" title="{% 
trans 'This message was sent to the mailing list' %}">
         {% endif %}
         <div class="collapse" id="{{ action.created|date:"Y_g_i_s" }}">
diff --git a/vertimus/models.py b/vertimus/models.py
index 02b618e..b4a520c 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -13,7 +13,7 @@ from django.utils.translation import override, ugettext, ugettext_noop, ugettext
 from common.utils import send_mail
 from stats.models import Branch, Domain, Statistics, PoFile
 from stats.signals import pot_has_changed
-from stats.utils import run_shell_command, is_po_reduced, po_grep
+from stats.utils import STATUS_OK, run_shell_command, is_po_reduced, po_grep
 from languages.models import Language
 from people.models import Person
 
@@ -374,6 +374,15 @@ class ActionAbstract(models.Model):
         except:
             return False
 
+    def check_po_file(self, filters=('xmltags',)):
+        status, out, errs = run_shell_command(
+            ['pofilter', '--progress=none', '-t'] + list(filters) + [self.most_uptodate_file.path]
+        )
+        if status == STATUS_OK:
+            return out
+        else:
+            return "Error running pofilter: %s" % errs
+
     @classmethod
     def get_action_history(cls, state=None, sequence=None):
         """
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 95a93c6..8e1b706 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -688,6 +688,24 @@ class VertimusTest(TeamsAndRolesTests):
         response = self.client.get(reverse("activity_by_language", args=[self.l.locale]))
         self.assertContains(response, self.m.description)
 
+    def test_check_po_file(self):
+        valid_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "valid_po.po")
+        state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
+        state.save()
+        with open(valid_path, 'r') as test_file:
+            action = Action.new_by_name('UT', person=self.pt, file=File(test_file))
+            action.state_db = state
+            action.file.save(action.file.name, action.file, save=False)
+        self.assertEqual(action.check_po_file(), '')
+
+        error_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "xml_error.po")
+        with open(error_path, 'r') as test_file:
+            action = Action.new_by_name('UT', person=self.pt, file=File(test_file))
+            action.state_db = state
+            action.file.save(action.file.name, action.file, save=False)
+        result = action.check_po_file()
+        self.assertIn('xmltags: Different XML tags', result)
+
     def test_mysql(self):
         # Copied from test_action_undo() with minor changes
         state = StateNone(branch=self.b, domain=self.d, language=self.l)
diff --git a/vertimus/tests/xml_error.po b/vertimus/tests/xml_error.po
new file mode 100644
index 0000000..d8a8bb1
--- /dev/null
+++ b/vertimus/tests/xml_error.po
@@ -0,0 +1,30 @@
+# French translation of gnome-hello documentation.
+# Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# This file is distributed under the same license as the gnome-hello documentation package.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: GNOME Hello 2.0\n"
+"POT-Creation-Date: 2012-12-27 21:29+0000\n"
+"PO-Revision-Date: 2013-02-26 16:33+0100\n"
+"Last-Translator: Someone <someone gmail com>\n"
+"Language-Team: GNOME French Team <gnomefr traduc org>\n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+"X-Generator: Gtranslator 2.91.5\n"
+
+#: C/index.page:6(info/desc)
+msgid "Help for GNOME Hello."
+msgstr "Aide de GNOME Hello."
+
+#: C/index.page:8(info/title)
+msgctxt "text"
+msgid "GNOME Hello"
+msgstr "GNOME Hello"
+
+#: C/compiling.page:21(page/title)
+msgid "Get <app>GNOME Hello</app>"
+msgstr "Obtenir <app>GNOME Hello</xapp>"
diff --git a/vertimus/urls.py b/vertimus/urls.py
index 8e8de04..387f8c7 100644
--- a/vertimus/urls.py
+++ b/vertimus/urls.py
@@ -26,4 +26,5 @@ urlpatterns = [
     url(r'^(?P<locale>[\w\-@]+)/activity_summary/$',
         views.activity_by_language,
         name='activity_by_language'),
+    url(r'^action/(?P<pk>\d+)/qcheck/', views.quality_check, name='quality-check'),
 ]
diff --git a/vertimus/views.py b/vertimus/views.py
index 160e548..626cd87 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -4,7 +4,7 @@ import os
 from django.conf import settings
 from django.contrib import messages
 from django.db import IntegrityError
-from django.http import HttpResponseRedirect, Http404
+from django.http import HttpResponse, HttpResponseRedirect, Http404
 from django.shortcuts import render, get_object_or_404
 from django.urls import reverse
 from django.utils.translation import ugettext as _
@@ -240,3 +240,18 @@ def activity_by_language(request, locale):
         'activities':  states,
     }
     return render(request, 'vertimus/activity_summary.html', context)
+
+
+def quality_check(request, pk):
+    action = get_object_or_404(Action, pk=pk)
+    context = {'base': 'base_modal.html'}
+    if not action.has_po_file():
+        context['results'] = _('No po file to check')
+    else:
+        context['checks'] = ['xmltags']
+        results = action.check_po_file(context['checks'])
+        if results:
+            context['results'] = results
+        else:
+            context['results'] = _('The po file looks good!')
+    return render(request, 'vertimus/quality-check.html', context)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]