Use key().id_or_name() instead of key().name()
This is to allow for the usage of auto-id's.
Patch by: Sverre Rabbelier
--- a/app/soc/cache/home.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/cache/home.py Sat Apr 11 22:58:19 2009 +0000
@@ -35,7 +35,7 @@
"""Returns the memcache key for the user's sidebar.
"""
- return 'homepage_for_%s_%s' % (entity.kind(), entity.key().name())
+ return 'homepage_for_%s_%s' % (entity.kind(), entity.key().id_or_name())
def get(self, *args, **kwargs):
--- a/app/soc/cache/logic.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/cache/logic.py Sat Apr 11 22:58:19 2009 +0000
@@ -35,7 +35,7 @@
new_filter = {}
for filter_key, value in filter.iteritems():
- new_value = value.key().name() if isinstance(value, db.Model) else value
+ new_value = value.key().id_or_name() if isinstance(value, db.Model) else value
new_filter[filter_key] = new_value
return 'query_for_%(kind)s_%(filter)s_%(order)s' % {
--- a/app/soc/logic/models/club.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/logic/models/club.py Sat Apr 11 22:58:19 2009 +0000
@@ -58,7 +58,7 @@
# only if there is an application send out the invites
properties = {
'scope': entity,
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'role': 'club_admin',
'role_verbose' : 'Club Admin',
'status': 'group_accepted',
--- a/app/soc/logic/models/organization.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/logic/models/organization.py Sat Apr 11 22:58:19 2009 +0000
@@ -73,7 +73,7 @@
# only if there is an application send out the invites
properties = {
'scope': entity,
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'role': 'org_admin',
'role_verbose': 'Organization Admin',
'status': 'group_accepted',
--- a/app/soc/logic/models/ranker_root.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/logic/models/ranker_root.py Sat Apr 11 22:58:19 2009 +0000
@@ -61,7 +61,7 @@
fields = {'link_id': name,
'scope': scope,
- 'scope_path': scope.key().name(),
+ 'scope_path': scope.key().id_or_name(),
'root': ranker.rootkey}
key_name = self.getKeyNameFromFields(fields)
--- a/app/soc/logic/models/student_proposal.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/logic/models/student_proposal.py Sat Apr 11 22:58:19 2009 +0000
@@ -69,7 +69,7 @@
"""
ranker = self.getRankerFor(entity)
- ranker.SetScore(entity.key().name(), [entity.score])
+ ranker.SetScore(entity.key().id_or_name(), [entity.score])
super(Logic, self)._onCreate(entity)
@@ -91,7 +91,7 @@
# update the ranker
ranker = self.getRankerFor(entity)
- ranker.SetScore(entity.key().name(), [value])
+ ranker.SetScore(entity.key().id_or_name(), [value])
if name == 'status':
@@ -101,7 +101,7 @@
ranker = self.getRankerFor(entity)
# entries in the ranker can be removed by setting the score to None
- ranker.SetScore(entity.key().name(), None)
+ ranker.SetScore(entity.key().id_or_name(), None)
return super(Logic, self)._updateField(entity, entity_properties, name)
@@ -116,7 +116,7 @@
# entries in the ranker can be removed by setting the score to None
ranker = self.getRankerFor(entity)
- ranker.SetScore(entity.key().name(), None)
+ ranker.SetScore(entity.key().id_or_name(), None)
# get all the ReviewFollwers that have this entity as it's scope
fields = {'scope': entity}
--- a/app/soc/models/seed_db.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/models/seed_db.py Sat Apr 11 22:58:19 2009 +0000
@@ -490,7 +490,7 @@
'key_name': 'google/gsoc2009/org_%d/mentor' % i,
'link_id': 'mentor',
'scope': org,
- 'scope_path': org.key().name(),
+ 'scope_path': org.key().id_or_name(),
'user': current_user,
'given_name': 'Mentor',
'surname': 'Man',
@@ -526,8 +526,8 @@
all_properties = []
for i in range(random.randint(5, 20)):
- link_id = 'proposal_%s_%d' % (org.key().name(), i)
- scope_path = current_user.key().name()
+ link_id = 'proposal_%s_%d' % (org.key().id_or_name(), i)
+ scope_path = current_user.key().id_or_name()
properties = {
'link_id': link_id,
--- a/app/soc/views/helper/access.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/helper/access.py Sat Apr 11 22:58:19 2009 +0000
@@ -816,7 +816,7 @@
for _ in range(depth):
entity = entity.scope
- django_args['scope_path'] = entity.key().name()
+ django_args['scope_path'] = entity.key().id_or_name()
self.checkHasActiveRoleForScope(django_args, logic)
@@ -1435,7 +1435,7 @@
fields = {
'link_id': django_args['link_id'],
- field_name: self.user if user else self.user.key().name()
+ field_name: self.user if user else self.user.key().id_or_name()
}
if 'scope_path' in django_args:
--- a/app/soc/views/helper/redirects.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/helper/redirects.py Sat Apr 11 22:58:19 2009 +0000
@@ -31,7 +31,7 @@
"""
result ='/%s/apply/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -40,7 +40,7 @@
"""
result ='/%s/invite/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -50,7 +50,7 @@
"""
result ='/%s/create/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -60,7 +60,7 @@
"""
return '/%s/edit/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getPublicRedirect(entity, params):
@@ -68,7 +68,7 @@
"""
return '/%s/show/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getAdminRedirect(entity, params):
@@ -76,7 +76,7 @@
"""
return '/%s/admin/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getListRedirect(entity, params):
@@ -84,7 +84,7 @@
"""
return '/%s/list/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getPublicListRedirect(entity, params):
@@ -92,7 +92,7 @@
"""
return '/%s/list_public/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getExportRedirect(entity, params):
@@ -100,7 +100,7 @@
"""
return '/%s/export/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getHomeRedirect(entity, params):
@@ -108,14 +108,14 @@
"""
return '/%s/home/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getReviewRedirect(entity, params):
"""Returns the redirect to review the specified entity.
"""
return '/%s/review/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getReviewOverviewRedirect(entity, params):
"""Returns the redirect to the review_overview using the
@@ -123,14 +123,14 @@
"""
return '/%s/review_overview/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getCreateRequestRedirect(entity, params):
"""Returns the create request redirect for the specified entity.
"""
result ='/request/create/%s/%s/%s' % (
- params['group_scope'], params['url_name'], entity.key().name())
+ params['group_scope'], params['url_name'], entity.key().id_or_name())
return result
@@ -140,7 +140,7 @@
"""
result ='/%s/request/%s' % (
- role_name, entity.key().name())
+ role_name, entity.key().id_or_name())
return result
@@ -150,7 +150,7 @@
"""
result ='/%s/invite/%s' % (
- role_name, entity.key().name())
+ role_name, entity.key().id_or_name())
return result
@@ -161,7 +161,7 @@
"""
result = '/%s/list_proposals/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -171,7 +171,7 @@
"""
result = '/%s/accepted_orgs/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -192,7 +192,7 @@
"""
result = '/%s/list_requests/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -202,7 +202,7 @@
"""
result = '/%s/list_self/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -213,7 +213,7 @@
"""
result = '/%s/list_roles/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -240,7 +240,7 @@
"""
result = '/%s/manage/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -250,7 +250,7 @@
"""
result = '/%s/manage_overview/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
return result
@@ -286,7 +286,7 @@
"""
return '/%s/applicant/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getStudentEditRedirect(entity, params):
@@ -320,7 +320,7 @@
"""
return'/%s/slots/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getAssignSlotsRedirect(entity, params):
@@ -328,21 +328,21 @@
"""
return'/%s/assign_slots/%s' % (
- params['url_name'], entity.key().name())
+ params['url_name'], entity.key().id_or_name())
def getCreateDocumentRedirect(entity, prefix):
"""Returns the redirect for new documents.
"""
- return '/document/create/%s/%s' % (prefix, entity.key().name())
+ return '/document/create/%s/%s' % (prefix, entity.key().id_or_name())
def getListDocumentsRedirect(entity, prefix):
"""Returns the redirect for listing documents.
"""
- return '/document/list/%s/%s' % (prefix, entity.key().name())
+ return '/document/list/%s/%s' % (prefix, entity.key().id_or_name())
def getToSRedirect(presence):
--- a/app/soc/views/helper/templatetags/forms_helpers.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py Sat Apr 11 22:58:19 2009 +0000
@@ -329,11 +329,11 @@
args[filter_field] = getattr(entity, filter_field)
if '__scoped__' in filter:
- args['scope_path'] = entity.key().name()
+ args['scope_path'] = entity.key().id_or_name()
# TODO: replace this hack needed to get org-scoped mentor autocompletion on student proposals
if '__org__' in filter:
- args['scope_path'] = entity.org.key().name()
+ args['scope_path'] = entity.org.key().id_or_name()
params['args'] = '&'.join(['%s=%s' % item for item in args.iteritems()])
--- a/app/soc/views/models/base.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/base.py Sat Apr 11 22:58:19 2009 +0000
@@ -433,7 +433,7 @@
edit_form: The edit_form is used as form if there is an existing
entity. The existing entity is passed as instance to it on
construction. If key_name is part of it's fields it will be
- set to the entity's key().name() value. It is also passed as
+ set to the entity's key().id_or_name() value. It is also passed as
argument to the _editGet method. See the docstring for
_editGet on how it uses it.
create_form: The create_form is used as form if there was no
@@ -474,7 +474,7 @@
form = params['edit_form'](instance=entity)
if 'key_name' in form.fields:
- form.fields['key_name'].initial = entity.key().name()
+ form.fields['key_name'].initial = entity.key().id_or_name()
self._editGet(request, entity, form)
else:
@@ -613,7 +613,7 @@
if not logic.isDeletable(entity):
page_params = params['cannot_delete_params']
- params['suffix'] = entity.key().name()
+ params['suffix'] = entity.key().id_or_name()
request.path = params['edit_redirect'] % params
# redirect to the edit page
--- a/app/soc/views/models/document.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/document.py Sat Apr 11 22:58:19 2009 +0000
@@ -144,7 +144,7 @@
form.fields['created_by'].initial = entity.author.name
form.fields['last_modified_by'].initial = entity.modified_by.name
- form.fields['doc_key_name'].initial = entity.key().name()
+ form.fields['doc_key_name'].initial = entity.key().id_or_name()
super(View, self)._editGet(request, entity, form)
@@ -160,7 +160,7 @@
filter = {
'prefix' : params['url_name'],
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'is_featured': True,
}
--- a/app/soc/views/models/group.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/group.py Sat Apr 11 22:58:19 2009 +0000
@@ -417,7 +417,7 @@
roles = role_logic.getForFields(fields)
for role in roles:
- group_key_name = role.scope.key().name()
+ group_key_name = role.scope.key().id_or_name()
existing_role_descriptions = role_descriptions.get(group_key_name)
if existing_role_descriptions:
--- a/app/soc/views/models/org_app.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/org_app.py Sat Apr 11 22:58:19 2009 +0000
@@ -305,7 +305,7 @@
'application_type' : params['name_plural'],
'applications': org_apps,
'link' : '/%s/review/%s/(link_id)?status=%s' %(
- params['url_name'] ,program_entity.key().name(), to_status),
+ params['url_name'] ,program_entity.key().id_or_name(), to_status),
}
json = simplejson.dumps(to_json)
--- a/app/soc/views/models/program.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/program.py Sat Apr 11 22:58:19 2009 +0000
@@ -408,7 +408,7 @@
# store result in the datastore
fields = {'link_id': program_entity.link_id,
'scope': program_entity,
- 'scope_path': program_entity.key().name(),
+ 'scope_path': program_entity.key().id_or_name(),
'json_representation' : request.POST['result']
}
key_name = duplicates_logic.getKeyNameFromFields(fields)
@@ -432,7 +432,7 @@
to_json = {
'nr_of_orgs': query.count(),
- 'program_key': program_entity.key().name()}
+ 'program_key': program_entity.key().id_or_name()}
json = simplejson.dumps(to_json)
context['info'] = json
context['offset_length'] = 10
@@ -520,7 +520,7 @@
continue
# store information about the org
- orgs_data[org.key().name()] = org_data
+ orgs_data[org.key().id_or_name()] = org_data
fields = {'org': org,
'mentor !=': None,
@@ -536,12 +536,12 @@
student_entity = proposal.scope
proposals_data.append(
- {'key_name': proposal.key().name(),
+ {'key_name': proposal.key().id_or_name(),
'proposal_title': proposal.title,
- 'student_key': student_entity.key().name(),
+ 'student_key': student_entity.key().id_or_name(),
'student_name': student_entity.name(),
'student_contact': student_entity.email,
- 'org_key': org.key().name()
+ 'org_key': org.key().id_or_name()
})
# return all the data in JSON format
@@ -710,7 +710,7 @@
if user and not (student_entity or mentor_entity or org_admin_entity):
if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
# this user does not have a role yet for this program
- items += [('/student/apply/%s' % (program_entity.key().name()),
+ items += [('/student/apply/%s' % (program_entity.key().id_or_name()),
"Register as a Student", 'any_access')]
deadline = 'accepted_organization_announced_deadline'
@@ -722,7 +722,7 @@
if not student_entity:
# add apply to become a mentor link
- items += [('/org/apply_mentor/%s' % (program_entity.key().name()),
+ items += [('/org/apply_mentor/%s' % (program_entity.key().id_or_name()),
"Apply to become a Mentor", 'any_access')]
return items
@@ -738,7 +738,7 @@
if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
items += [('/student_proposal/list_orgs/%s' % (
- student_entity.key().name()),
+ student_entity.key().id_or_name()),
"Submit your Student Proposal", 'any_access')]
if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'):
--- a/app/soc/views/models/student_proposal.py Sat Apr 11 22:57:23 2009 +0000
+++ b/app/soc/views/models/student_proposal.py Sat Apr 11 22:58:19 2009 +0000
@@ -397,7 +397,7 @@
# create the fields that should be in the ReviewFollower entity
fields = {'link_id': user_entity.link_id,
'scope': entity,
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'user': user_entity
}
# get the keyname for the ReviewFollower entity
@@ -548,7 +548,7 @@
list_params['list_description'] = ('List of %(name_plural)s you can send '
'your proposal to.') % list_params
list_params['list_action'] = (redirects.getStudentProposalRedirect,
- {'student_key': student_entity.key().name(),
+ {'student_key': student_entity.key().id_or_name(),
'url_name': params['url_name']})
return self.list(request, access_type=access_type, page_name=page_name,
@@ -795,7 +795,7 @@
# create the fields that should be in the ReviewFollower entity
fields = {'link_id': user_entity.link_id,
'scope': entity,
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'user': user_entity
}
# get the keyname for the ReviewFollower entity
@@ -895,8 +895,8 @@
mentor_names = []
for mentor_key in possible_mentors:
- possible_mentor = mentor_logic.logic.getFromKeyName(mentor_key.name())
- mentor_names.append(possible_mentor.name())
+ possible_mentor = mentor_logic.logic.getFromKeyName(mentor_key.id_or_name())
+ mentor_names.append(possible_mentor.id_or_name())
context['possible_mentors'] = ', '.join(mentor_names)
@@ -1015,7 +1015,7 @@
# create the fields for the review entity
fields = {'link_id': 't%i' % (int(time.time()*100)),
'scope': entity,
- 'scope_path': entity.key().name(),
+ 'scope_path': entity.key().id_or_name(),
'author': user_logic.logic.getForCurrentAccount(),
'content': comment,
'is_public': is_public,