app/soc/logic/models/base.py
changeset 402 021e86368600
parent 399 b82852e6963e
child 403 d3e545a8bd26
--- a/app/soc/logic/models/base.py	Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/logic/models/base.py	Tue Oct 21 01:22:36 2008 +0000
@@ -26,6 +26,8 @@
 
 from google.appengine.ext import db
 
+from django.utils.translation import ugettext_lazy
+
 from soc.logic import out_of_band
 
 
@@ -98,15 +100,17 @@
 
     fields = []
 
-    msg = 'There is no %s where ' % self._name
+    format_text = ugettext_lazy('"%(key)s" is "%(value)s"')
+
+    msg_pairs = [format_text % {'key': key, 'value': value}
+      for key, value in kwargs.iteritems()]
 
-    for index, pair in enumerate(kwargs.iteritems()):
-      if index != 0:
-        msg += ' and '
+    joined_pairs = ' and '.join(msg_pairs)
 
-      msg += '"%s" is "%s"' % pair
+    msg = ugettext_lazy(
+      'There is no "%(name)s" where %(pairs)s.') % {
+        'name': self._name, 'pairs': joined_pairs}
 
-    msg += '.'
 
     # else: fields were supplied, but there is no Entity that has it
     raise out_of_band.ErrorResponse(msg, status=404)
@@ -136,16 +140,12 @@
           of this entity.
     """
 
-    suffix = ''
+    suffix = []
 
-    for field in self._model.key_fields:
-      suffix += fields[field]
-      suffix += '/'
+    for field in self._model.KEY_FIELDS:
+      suffix.append(fields[field])
 
-    if suffix.endswith('/'):
-      suffix = suffix[:-1]
-
-    return suffix
+    return '/'.join(suffix)
 
   def getEmptyKeyFields(self):
     """Returns an dict with all the entities key_fields set to None
@@ -153,7 +153,7 @@
 
     kwargs = {}
 
-    for field in self._model.key_fields:
+    for field in self._model.KEY_FIELDS:
       kwargs[field] = None
 
     return kwargs
@@ -168,7 +168,7 @@
     key_fields = {}
 
     for key, value in fields.iteritems():
-      if key in self._model.key_fields:
+      if key in self._model.KEY_FIELDS:
         key_fields[key] = value
 
     return key_fields