damned-lies r1168 - in trunk: . languages stats teams
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1168 - in trunk: . languages stats teams
- Date: Fri, 14 Nov 2008 11:12:20 +0000 (UTC)
Author: claudep
Date: Fri Nov 14 11:12:20 2008
New Revision: 1168
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1168&view=rev
Log:
2008-11-14 Claude Paroz <claude 2xlibre net>
* languages/views.py:
* stats/views.py:
* teams/views.py: Use get_object_or_404 shortcut for retrieving objects.
* stats/models.py: Get rid of warning messages from msgcat. Improve
iteration algorithm with islice.
Modified:
trunk/ChangeLog
trunk/languages/views.py
trunk/stats/models.py
trunk/stats/views.py
trunk/teams/views.py
Modified: trunk/languages/views.py
==============================================================================
--- trunk/languages/views.py (original)
+++ trunk/languages/views.py Fri Nov 14 11:12:20 2008
@@ -22,7 +22,7 @@
import os
import tarfile
from datetime import datetime
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from stats.conf import settings
from common import utils
@@ -38,8 +38,8 @@
return render_to_response('languages/language_list.html', context)
def language_release(request, locale, release_name):
- language = Language.objects.get(locale=Language.unslug_locale(locale))
- release = Release.objects.get(name=release_name)
+ language = get_object_or_404(Language, locale=Language.unslug_locale(locale))
+ release = get_object_or_404(Release, name=release_name)
stats = release.get_lang_stats(language)
context = {
'pageSection': "languages",
@@ -50,8 +50,8 @@
return render_to_response('languages/language_release.html', context)
def language_release_tar(request, locale, release_name, dtype):
- release = Release.objects.get(name=release_name)
- language = Language.objects.get(locale=locale)
+ release = get_object_or_404(Release, name=release_name)
+ language = get_object_or_404(Language, locale=locale)
last_modif, file_list = release.get_lang_files(language, dtype)
tar_filename = '%s.%s.%s.tar.gz' % (release.name, dtype, language.locale)
@@ -72,8 +72,8 @@
""" This view create the same XML output than the previous Damned-Lies, so as
apps which depend on it (like Vertimus) don't break.
This view may be suppressed when Vertimus will be integrated in D-L. """
- language = Language.objects.get(locale=Language.unslug_locale(locale))
- release = Release.objects.get(name=release_name)
+ language = get_object_or_404(Language, locale=Language.unslug_locale(locale))
+ release = get_object_or_404(Release, name=release_name)
stats = release.get_lang_stats(language)
content = "<stats language=\"%s\" release=\"%s\">\n" % (locale, release_name)
for catname, categ in stats['ui']['categs'].items():
Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py (original)
+++ trunk/stats/models.py Fri Nov 14 11:12:20 2008
@@ -21,6 +21,7 @@
import os, sys, re, commands
from datetime import datetime
from time import tzname
+from itertools import islice
from django.db import models, connection
from django.utils.translation import ungettext, ugettext as _, ugettext_noop
from stats.conf import settings
@@ -893,13 +894,14 @@
# FIXME: something should be logged here
return []
lines = output.split('\n')
+ while lines[0][0] != "#":
+ lines = lines[1:] # skip warning messages at the top of the output
re_path = re.compile('^msgid \"@@image: \'([^\']*)\'')
self.figures = []
- i = 0
- while i < len(lines):
+ for i, line in islice(enumerate(lines), 0, None, 4):
fig = {}
- fig['fuzzy'] = lines[i]=='#, fuzzy'
+ fig['fuzzy'] = line=='#, fuzzy'
path_match = re_path.match(lines[i+1])
if path_match and len(path_match.groups()):
fig['path'] = path_match.group(1)
@@ -912,7 +914,6 @@
if os.path.exists(os.path.join(self.branch.co_path(), self.domain.directory, self.language.locale, fig['path'])):
fig['translated_file'] = True
self.figures.append(fig)
- i += 4
return self.figures
def fig_count(self):
Modified: trunk/stats/views.py
==============================================================================
--- trunk/stats/views.py (original)
+++ trunk/stats/views.py Fri Nov 14 11:12:20 2008
@@ -18,7 +18,7 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from stats.models import Statistics, Module, Release
from stats.conf import settings
from djamnedlies.stats import utils
@@ -38,7 +38,7 @@
return render_to_response('module_list.html', context)
def module(request, module_name):
- mod = Module.objects.get(name = module_name)
+ mod = get_object_or_404(Module, name=module_name)
context = {
'pageSection': "module",
'module': mod,
@@ -47,7 +47,7 @@
return render_to_response('module.html', context)
def docimages(request, module_name, potbase, branch_name, langcode):
- mod = Module.objects.get(name = module_name)
+ mod = get_object_or_404(Module, name=module_name)
stat = Statistics.objects.get(branch__module=mod.id,
branch__name=branch_name,
domain__name=potbase,
@@ -72,7 +72,7 @@
return render_to_response('release_list.html', context)
def release(request, release_name):
- rel = Release.objects.get(name=release_name)
+ rel = get_object_or_404(Release, name=release_name)
context = {
'pageSection': "releases",
'release': rel
Modified: trunk/teams/views.py
==============================================================================
--- trunk/teams/views.py (original)
+++ trunk/teams/views.py Fri Nov 14 11:12:20 2008
@@ -19,7 +19,7 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from common import utils
from teams.models import Team, FakeTeam
from languages.models import Language
@@ -37,7 +37,7 @@
try:
team = Team.objects.get(name=team_slug)
except:
- lang = Language.objects.get(locale=team_slug)
+ lang = get_object_or_404(Language, locale=team_slug)
team = FakeTeam(lang)
context = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]