Incorperated suggestions by Todd
Patch by: Sverre Rabbelier
Reviewed by: to-be-reviewed
--- 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
--- a/app/soc/models/group.py Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/models/group.py Tue Oct 21 01:22:36 2008 +0000
@@ -38,7 +38,7 @@
"""
#: Defines which fields are uses as the key_name
- key_fields = ['link_name']
+ KEY_FIELDS = ['link_name']
#: Required field storing name of the group.
name = db.StringProperty(required=True,
--- a/app/soc/models/work.py Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/models/work.py Tue Oct 21 01:22:36 2008 +0000
@@ -42,7 +42,7 @@
back-reference Query of the Review model 'reviewed' reference.
"""
- key_fields = ['partial_path', 'link_name']
+ KEY_FIELDS = ['partial_path', 'link_name']
#: Required 1:1 relationship indicating the User who initially authored the
#: Work (this relationship is needed to keep track of lifetime document
--- a/app/soc/views/models/base.py Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/views/models/base.py Tue Oct 21 01:22:36 2008 +0000
@@ -158,7 +158,7 @@
entity = self._logic.getIfFields(**kwargs)
except soc.logic.out_of_band.ErrorResponse, error:
template = self._params['public_template']
- error.message = error.message + View.DEF_CREATE_NEW_ENTITY_MSG % {
+ error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
'entity_type_lower' : self._params['name'].lower(),
'entity_type' : self._params['name'],
'create' : self._params['create_redirect']
@@ -210,14 +210,14 @@
# Remove the params from the request, this is relevant only if
# someone bookmarked a POST page.
is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix)
- if request.GET.get(View.DEF_SUBMIT_MSG_PARAM_NAME):
+ if request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME):
if (not entity) or (not is_self_referrer):
return http.HttpResponseRedirect(request.path)
if entity:
# Note: no message will be displayed if parameter is not present
context['notice'] = helper.requests.getSingleIndexedParamValue(
- request, View.DEF_SUBMIT_MSG_PARAM_NAME,
+ request, self.DEF_SUBMIT_MSG_PARAM_NAME,
values=self._params['save_message'])
# populate form with the existing entity
@@ -289,7 +289,7 @@
entity = self._logic.getIfFields(**kwargs)
except soc.logic.out_of_band.ErrorResponse, error:
template = self._params['create_template']
- error.message = error.message + View.DEF_CREATE_NEW_ENTITY_MSG % {
+ error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
'entity_type_lower' : self._params['name'].lower(),
'entity_type' : self._params['name'],
'create' : self._params['create_redirect']
@@ -315,7 +315,7 @@
Args:
request: the django request object
- entity: the entity to post
+ entity: the entity to create or update from POST contents
fields: the new field values
"""
--- a/app/soc/views/models/docs.py Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/views/models/docs.py Tue Oct 21 01:22:36 2008 +0000
@@ -116,7 +116,7 @@
params['save_message'] = [ugettext_lazy('Profile saved.')]
params['edit_params'] = {
- base.View.DEF_SUBMIT_MSG_PARAM_NAME: base.View.DEF_SUBMIT_MSG_PROFILE_SAVED,
+ self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
}
rights['list'] = [helper.access.checkIsDeveloper]
@@ -128,7 +128,7 @@
base.View.__init__(self, rights=rights, params=params)
def _editPost(self, request, entity, fields):
- """
+ """See base.View._editPost().
"""
id = users.get_current_user()
@@ -136,7 +136,7 @@
fields['author'] = user
def _editGet(self, request, entity, form):
- """
+ """See base.View._editGet().
"""
form.fields['created_by'].initial = entity.author.link_name
--- a/app/soc/views/models/sponsor.py Mon Oct 20 23:24:41 2008 +0000
+++ b/app/soc/views/models/sponsor.py Tue Oct 21 01:22:36 2008 +0000
@@ -121,7 +121,7 @@
params['save_message'] = [ugettext_lazy('Profile saved.')]
params['edit_params'] = {
- base.View.DEF_SUBMIT_MSG_PARAM_NAME: base.View.DEF_SUBMIT_MSG_PROFILE_SAVED,
+ self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
}
rights['list'] = [helper.access.checkIsDeveloper]
@@ -133,7 +133,7 @@
base.View.__init__(self, rights=rights, params=params)
def _editPost(self, request, entity, fields):
- """
+ """See base.View._editPost().
"""
id = users.get_current_user()