Commit 916234fa authored by Michal Čihař's avatar Michal Čihař

Import errors for not supported file formats are now shown in admin page

This prevents these errors will go without noticing.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 236c24a3
......@@ -32,8 +32,31 @@
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% if errors %}
<h1>{% trans "Configuration errors" %}</h1>
<div id="changelist" class="module filtered">
<div class="results">
<table id="result_list" class="orderable-initalized">
<thead>
<tr>
<th>{% trans "Name" %}</th>
<th>{% trans "Message" %}</th>
</tr>
</thead>
<tbody>
{% for error in errors %}
<tr class="row{% cycle 1,2 %} {{ check.3 }}">
<td>{{ error.name }}</td>
<td><pre>{{ error.message }}</pre></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>
{% endblock %}
......@@ -29,6 +29,7 @@ from weblate import settings_example
from weblate import appsettings
from weblate.accounts.avatar import HAS_LIBRAVATAR
from weblate.accounts.forms import HAS_ICU
from weblate.trans.util import get_configuration_errors
import weblate
import django
......@@ -172,11 +173,13 @@ def performance(request):
'production-admin-files',
'order-cell',
))
return render(
request,
"admin/performance.html",
{
'checks': checks,
'errors': get_configuration_errors()
}
)
......
......@@ -30,13 +30,14 @@ from translate.storage.ts2 import tsunit
from translate.storage.jsonl10n import JsonUnit
from translate.storage import mo
from translate.storage import factory
from weblate.trans.util import get_string, join_plural
from weblate.trans.util import get_string, join_plural, add_configuration_error
from translate.misc import quote
import weblate
import subprocess
import os.path
import re
import hashlib
import traceback
import importlib
import __builtin__
......@@ -54,7 +55,10 @@ def register_fileformat(fileformat):
fileformat.get_class()
FILE_FORMATS[fileformat.format_id] = fileformat
except (AttributeError, ImportError):
pass
add_configuration_error(
'File format: {0}'.format(fileformat.format_id),
traceback.format_exc()
)
return fileformat
......
......@@ -24,6 +24,7 @@ from django.test import TestCase
from django.core.urlresolvers import reverse
from django.utils.unittest import SkipTest
from weblate.trans.tests.test_util import get_test_file
from weblate.trans.util import add_configuration_error
import tempfile
import shutil
import os
......@@ -100,6 +101,11 @@ class AdminTest(ViewTestCase):
response = self.client.get(reverse('admin-performance'))
self.assertContains(response, 'Django caching')
def test_error(self):
add_configuration_error('Test error', 'FOOOOOOOOOOOOOO')
response = self.client.get(reverse('admin-performance'))
self.assertContains(response, 'FOOOOOOOOOOOOOO')
def test_report(self):
response = self.client.get(reverse('admin-report'))
self.assertContains(response, 'On branch master')
......
......@@ -20,6 +20,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.contrib.sites.models import Site
from django.core.cache import cache
from importlib import import_module
import time
import random
......@@ -124,3 +125,22 @@ def translation_percent(translated, total):
Returns translation percentage.
'''
return (1000 * translated / total) / 10.0
def add_configuration_error(name, message):
"""
Logs configuration error.
"""
errors = cache.get('configuration-errors', [])
errors.append({
'name': name,
'message': message,
})
cache.set('configuration-errors', errors)
def get_configuration_errors():
"""
Returns all configuration errors.
"""
return cache.get('configuration-errors', [])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment