[damned-lies] Fix figure URLs and add test (Bug #584237)
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Subject: [damned-lies] Fix figure URLs and add test (Bug #584237)
- Date: Fri, 29 May 2009 18:05:04 -0400 (EDT)
commit 58023fcfb633cc7501c9d1e7d934821f9383a193
Author: Claude Paroz <claude 2xlibre net>
Date: Sat May 30 00:02:45 2009 +0200
Fix figure URLs and add test (Bug #584237)
---
stats/models.py | 17 ++++++++++++++++-
stats/tests/__init__.py | 8 ++++++++
stats/utils.py | 3 ++-
templates/module_images.html | 18 +++++++-----------
4 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/stats/models.py b/stats/models.py
index c6f7c51..a898e11 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -184,6 +184,14 @@ class Branch(models.Model):
else:
return -cmp(self.name, other.name)
+ @property
+ def img_url_prefix(self):
+ return self.module.vcs_type == 'git' and "plain" or ""
+
+ @property
+ def img_url_suffix(self):
+ return self.module.vcs_type == 'git' and "?h=%s" % self.name or ""
+
def is_head(self):
return self.name in BRANCH_HEAD_NAMES
@@ -727,7 +735,7 @@ class Release(models.Model):
if row[LOCALE] not in stats:
stats[row[LOCALE]] = [0] * len(releases)
stats[row[LOCALE]].insert(0, _(row[NAME])) # translated language name
- if row[LOCALE] == None: # POT stats
+ if row[LOCALE] is None: # POT stats
totals[rel_ids.index(str(row[REL_ID]))] = row[UNTRANS]
else:
stats[row[LOCALE]][rel_ids.index(str(row[REL_ID]))+1] = row[TRANS]
@@ -1037,9 +1045,16 @@ class Statistics(models.Model):
return text
def get_figures(self):
+ """ self.figures is a list of dicts:
+ [{'path':, 'hash':, 'fuzzy':, 'translated':, 'translated_file':}, ...] """
if self.figures is None and self.domain.dtype == 'doc':
self.figures = utils.get_fig_stats(self.po_path())
+ # something like: "http://git.gnome.org/cgit/vinagre / plain / help / %s / %s ?h=master"
+ url_model = utils.url_join(self.branch.get_vcs_web_url(), self.branch.img_url_prefix,
+ self.domain.directory, '%s', '%s') + self.branch.img_url_suffix
for fig in self.figures:
+ fig['orig_remote_url'] = url_model % ('C', fig['path'])
+ fig['trans_remote_url'] = url_model % (self.language.locale, fig['path'])
fig['translated_file'] = False
if self.language:
# Check if a translated figure really exists or if the English one is used
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 636cd7f..273e72d 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -126,6 +126,14 @@ class ModuleTestCase(TestCase):
self.assertEquals(ui_stat.pot_url(), u"/POT/gnome-hello.master/gnome-hello.master.pot");
self.assertEquals(doc_stat.po_url(), u"/POT/gnome-hello.master/docs/gnome-hello-help.master.fr.po");
+ def testFigureURLs(self):
+ """ Test if figure urls are properly constructed """
+ self.b.update_stats(force=True)
+ stat = Statistics.objects.get(branch=self.b, domain__dtype='doc', language__locale='fr')
+ figs = stat.get_figures()
+ self.assertEquals(figs[0]['orig_remote_url'], 'http://git.gnome.org/cgit/gnome-hello/plain/help/C/figures/gnome-hello.png?h=master')
+ self.assertEquals(figs[0]['trans_remote_url'], 'http://git.gnome.org/cgit/gnome-hello/plain/help/fr/figures/gnome-hello.png?h=master')
+
def testCreateUnexistingBranch(self):
""" Try to create a non-existing branch """
Branch.checkout_on_creation = True
diff --git a/stats/utils.py b/stats/utils.py
index 879b9c5..dc2e0e0 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -323,7 +323,8 @@ def check_lang_support(module_path, po_path, lang):
return errors
def get_fig_stats(pofile):
- """ Extract image strings from pofile and return a list of figures dict {'path':, 'fuzzy':, 'translated':} """
+ """ Extract image strings from pofile and return a list of figures dict:
+ [{'path':, 'hash':, 'fuzzy':, 'translated':}, ...] """
# Extract image strings: beforeline/msgid/msgstr/grep auto output a fourth line
command = "msgcat --no-wrap %(pofile)s| grep -A 1 -B 1 '^msgid \"@@image:'" % locals()
(status, output, errs) = run_shell_command(command)
diff --git a/templates/module_images.html b/templates/module_images.html
index 50da5ac..c9ce494 100644
--- a/templates/module_images.html
+++ b/templates/module_images.html
@@ -17,17 +17,15 @@
<thead><tr><th width="50%">{% trans "Original" %}</th><th width="50%">{% trans stat.language.name %}</th></tr></thead>
{% for fig in stat.get_figures %}
{% with stat.language.locale as locale %}
- {% with stat.vcs_web_path as vcs_web_path %}
- {% with stat.vcs_path as vcs_path %}
<tr><td valign="top">
- <a href="{{ vcs_web_path }}/C/{{ fig.path }}"><span class="path">C/{{ fig.path }}</span><br/></a>
- <a href="{{ vcs_path }}/C/{{ fig.path }}"><img class="screenshot" src="{{ vcs_path }}/C/{{ fig.path }}"/></a>
+ <a href="{{ fig.orig_remote_url }}"><span class="path">C/{{ fig.path }}</span><br/></a>
+ <a href="{{ fig.orig_remote_url }}"><img class="screenshot" src="{{ fig.orig_remote_url }}"/></a>
</td>
<td valign="top" class="{{ fig.fuzzy|yesno:"fuzzy," }}">
{% if fig.translated %}
{% if fig.translated_file %}
- <a href="{{ vcs_web_path }}/{{ locale }}/{{ fig.path }}"><span class="path">{{ locale }}/{{ fig.path }}</span></a><br/>
- <a href="{{ vcs_path }}/{{ locale }}/{{ fig.path }}"><img class="screenshot" src="{{ vcs_path }}/{{ locale }}/{{ fig.path }}"/></a>
+ <a href="{{ fig.trans_remote_url }}"><span class="path">{{ locale }}/{{ fig.path }}</span></a><br/>
+ <a href="{{ fig.trans_remote_url }}"><img class="screenshot" src="{{ fig.trans_remote_url }}"/></a>
{% else %}
<p><em>{% trans "Translated, but uses original one (maybe the figure doesn't contain any string to translate)" %}</em></p>
{% endif %}
@@ -35,21 +33,19 @@
{% if fig.fuzzy %}
<em>{% trans "Fuzzy" %}</em><br/>
{% if fig.translated_file %}
- <a href="{{ vcs_web_path }}/{{ locale }}/{{ fig.path }}"><span class="path">{{ locale }}/{{ fig.path }}</span></a><br/>
- <a href="{{ vcs_path }}/{{ locale }}/{{ fig.path }}"><img class="screenshot" src="{{ vcs_path }}/{{ locale }}/{{ fig.path }}"/></a>
+ <a href="{{ fig.trans_remote_url }}"><span class="path">{{ locale }}/{{ fig.path }}</span></a><br/>
+ <a href="{{ fig.trans_remote_url }}"><img class="screenshot" src="{{ fig.trans_remote_url }}"/></a>
{% else %}
<p><em><small>{% trans "No existing file ("Technical" fuzzy)" %}</small></em></p>
{% endif %}
{% else %}
<em>{% trans "Not translated" %}</em><br/>
- <img src="/media/img/emptyimg.png">
+ <img src="{{ MEDIA_URL }}img/emptyimg.png">
{% endif %}
{% endif %}
</td>
</tr>
{% endwith %}
- {% endwith %}
- {% endwith %}
{% endfor %}
</table>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]