Cleaned up getKeyNameFromFields in Logic base.
You can now pass it a dictionary that can contain other fields next to the keyfields.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/models/base.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/logic/models/base.py Thu Feb 05 20:19:17 2009 +0000
@@ -132,23 +132,19 @@
pass
def getKeyNameFromFields(self, fields):
- """Returns the KeyName constructed from kwargs for this type of entity.
+ """Returns the KeyName constructed from fields dict for this type of entity.
The KeyName is in the following format:
- <key_value1>:<key_value2>:...:<key_valueN>
+ <key_value1>/<key_value2>/.../<key_valueN>
"""
key_field_names = self.getKeyFieldNames()
- # check if all given KeyFieldNames are valid for this entity
- if not all(key in key_field_names for key in fields.keys()):
- raise Error("Some of the provided arguments are not key fields")
-
# check if all key_field_names for this entity are present in fields
if not all(field in fields.keys() for field in key_field_names):
raise Error("Not all the required key fields are present")
- if not all(fields.values()):
+ if not all(fields.get(field) for field in key_field_names):
raise Error("Not all KeyValues are non-false")
# construct the KeyValues in the order given by getKeyFieldNames()
--- a/app/soc/views/helper/access.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/helper/access.py Thu Feb 05 20:19:17 2009 +0000
@@ -661,14 +661,13 @@
raise out_of_band.AccessViolation(message_fmt=DEF_SCOPE_INACTIVE_MSG)
+ @allowDeveloper
@denySidebar
- @allowDeveloper
def checkIsHostForProgram(self, django_args):
"""Checks if the user is a host for the specified program.
"""
- key_fields = program_logic.getKeyFieldsFromFields(django_args)
- program = program_logic.getFromKeyFields(key_fields)
+ program = program_logic.getFromKeyFields(django_args)
if not program or program.status == 'invalid':
self.deny(django_args)
@@ -877,8 +876,7 @@
django_args: a dictionary with django's arguments
"""
- key_fields = document_logic.getKeyFieldsFromFields(django_args)
- document = document_logic.getFromKeyFields(key_fields)
+ document = document_logic.getFromKeyFields(django_args)
self.checkMembership('write', document.prefix,
document.write_access, django_args)
--- a/app/soc/views/models/base.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/base.py Thu Feb 05 20:19:17 2009 +0000
@@ -109,8 +109,7 @@
return http.HttpResponseRedirect('/')
try:
- key_fields = self._logic.getKeyFieldsFromFields(kwargs)
- entity = self._logic.getFromKeyFieldsOr404(key_fields)
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
return helper.responses.errorResponse(
error, request, template=params['error_public'], context=context)
@@ -168,8 +167,7 @@
return http.HttpResponseRedirect('/')
try:
- key_fields = self._logic.getKeyFieldsFromFields(kwargs)
- entity = self._logic.getFromKeyFieldsOr404(key_fields)
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
return helper.responses.errorResponse(
error, request, template=params['error_export'], context=context)
@@ -260,8 +258,7 @@
try:
if all(kwargs.values()):
- key_fields = self._logic.getKeyFieldsFromFields(kwargs)
- entity = self._logic.getFromKeyFieldsOr404(key_fields)
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
if not seed:
error.message_fmt = (
@@ -320,8 +317,7 @@
self._editPost(request, entity, fields)
if not key_name:
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- key_name = self._logic.getKeyNameFromFields(key_fields)
+ key_name = self._logic.getKeyNameFromFields(fields)
entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
@@ -490,8 +486,7 @@
entity = None
try:
- key_fields = self._logic.getKeyFieldsFromFields(kwargs)
- entity = self._logic.getFromKeyFieldsOr404(key_fields)
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
error.message_fmt = (
error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
--- a/app/soc/views/models/group.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/group.py Thu Feb 05 20:19:17 2009 +0000
@@ -154,8 +154,7 @@
# find the application
application_logic = params['application_logic']
- key_fields = application_logic.logic.getKeyFieldsFromFields(kwargs)
- application = application_logic.logic.getFromKeyFields(key_fields)
+ application = application_logic.logic.getFromKeyFields(kwargs)
# extract the application fields
field_names = application.properties().keys()
@@ -194,8 +193,7 @@
self._applicantPost(request, context, fields)
if not key_name:
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- key_name = self._logic.getKeyNameFromFields(key_fields)
+ key_name = self._logic.getKeyNameFromFields(fields)
# create the group entity
entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
--- a/app/soc/views/models/group_app.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/group_app.py Thu Feb 05 20:19:17 2009 +0000
@@ -245,8 +245,7 @@
entity = None
try:
- key_fields = self._logic.getKeyFieldsFromFields(kwargs)
- entity = self._logic.getFromKeyFieldsOr404(key_fields)
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
return helper.responses.errorResponse(
error, request, template=params['error_public'], context=context)
--- a/app/soc/views/models/presence.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/presence.py Thu Feb 05 20:19:17 2009 +0000
@@ -136,8 +136,7 @@
"""See base.View._editPost().
"""
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- scope_path = self._logic.getKeyNameFromFields(key_fields)
+ scope_path = self._logic.getKeyNameFromFields(fields)
key_fields = {
'scope_path': scope_path,
--- a/app/soc/views/models/presence_with_tos.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/presence_with_tos.py Thu Feb 05 20:19:17 2009 +0000
@@ -76,8 +76,7 @@
"""See base.View._editPost().
"""
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- scope_path = self._logic.getKeyNameFromFields(key_fields)
+ scope_path = self._logic.getKeyNameFromFields(fields)
key_fields = {
'scope_path': scope_path,
--- a/app/soc/views/models/program.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/program.py Thu Feb 05 20:19:17 2009 +0000
@@ -115,8 +115,7 @@
timeline_logic = program_logic.logic.TIMELINE_LOGIC[workflow]
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- key_name = self._logic.getKeyNameFromFields(key_fields)
+ key_name = self._logic.getKeyNameFromFields(fields)
properties = {'scope_path': key_name}
--- a/app/soc/views/models/role.py Thu Feb 05 19:30:43 2009 +0000
+++ b/app/soc/views/models/role.py Thu Feb 05 20:19:17 2009 +0000
@@ -233,8 +233,7 @@
return self.inviteGet(request, context, params, **kwargs)
# extract the key_name for the new request entity
- key_fields = request_logic.logic.getKeyFieldsFromFields(request_fields)
- key_name = request_logic.logic.getKeyNameFromFields(key_fields)
+ key_name = request_logic.logic.getKeyNameFromFields(request_fields)
# create the request entity
entity = request_logic.logic.updateOrCreateFromKeyName(request_fields,
@@ -347,8 +346,7 @@
fields ['status'] = 'active'
# get the key_name for the new entity
- key_fields = self._logic.getKeyFieldsFromFields(fields)
- key_name = self._logic.getKeyNameFromFields(key_fields)
+ key_name = self._logic.getKeyNameFromFields(fields)
# create new Role entity
entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
@@ -519,8 +517,7 @@
return self.requestGet(request, context, params, **kwargs)
# extract the key_name for the new request entity
- key_fields = request_logic.logic.getKeyFieldsFromFields(request_fields)
- key_name = request_logic.logic.getKeyNameFromFields(key_fields)
+ key_name = request_logic.logic.getKeyNameFromFields(request_fields)
# create the request entity
entity = request_logic.logic.updateOrCreateFromKeyName(request_fields, key_name)