# HG changeset patch # User Lennard de Rijk # Date 1232886035 0 # Node ID e05b09b53486491e99c3e04a767c74fb591ff1c3 # Parent d212d5f4c41afc374a8c7b0505de0ade5e4276d6 Moved getGroupEntityFromScopePath to logic/models/role.py. Also removed a TODO that has been done :). Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r d212d5f4c41a -r e05b09b53486 app/soc/logic/models/role.py --- a/app/soc/logic/models/role.py Sun Jan 25 11:44:25 2009 +0000 +++ b/app/soc/logic/models/role.py Sun Jan 25 12:20:35 2009 +0000 @@ -41,4 +41,26 @@ scope_logic=scope_logic) + def getGroupEntityFromScopePath(self, group_logic, scope_path): + """Returns a group entity by using the given scope_path. + + Args: + group_logic: logic for the group which should be retrieved + scope_path : the scope path of the entity + """ + group_key_fields = scope_path.rsplit('/',1) + + if len(group_key_fields) == 1: + # there is only a link_id + fields = {'link_id' : group_key_fields[0]} + else: + # there is a scope_path and link_id + fields = {'scope_path' : group_key_fields[0], + 'link_id' : group_key_fields[1]} + + group = group_logic.getForFields(fields, unique=True) + + return group + + logic = Logic() diff -r d212d5f4c41a -r e05b09b53486 app/soc/views/models/role.py --- a/app/soc/views/models/role.py Sun Jan 25 11:44:25 2009 +0000 +++ b/app/soc/views/models/role.py Sun Jan 25 12:20:35 2009 +0000 @@ -60,7 +60,6 @@ """ new_params = {} - # TODO(ljvderijk) parameterize these patterns patterns = params.get('extra_django_patterns') @@ -170,7 +169,7 @@ key_name, form_fields = soc.views.helper.forms.collectCleanedFields(form) # get the group entity for which this request is via the scope_path - group = self._getGroupEntityFromScopePath(params['group_logic'], + group = self._logic.getGroupEntityFromScopePath(params['group_logic'], kwargs['scope_path']) # get the request scope path @@ -198,27 +197,6 @@ # TODO(ljvderijk) redirect to a more useful place like the group homepage return http.HttpResponseRedirect('/') - def _getGroupEntityFromScopePath(self, group_logic, scope_path): - """Returns a group entity by using the given scope_path that's in kwargs. - - Args: - group_logic: logic for the group which should be retrieved - kwargs: the Key Fields for the specified entity - """ - group_key_fields = scope_path.rsplit('/',1) - - if len(group_key_fields) == 1: - # there is only a link_id - fields = {'link_id' : group_key_fields[0]} - else: - # there is a scope_path and link_id - fields = {'scope_path' : group_key_fields[0], - 'link_id' : group_key_fields[1]} - - group = group_logic.getForFields(fields, unique=True) - - return group - def _getRequestScopePathFromGroup(self, group_entity): """Returns the scope_path that should be put in a request for a given group. @@ -410,7 +388,7 @@ form=form, params=params) # get the group entity for which this request is via the scope_path - group = self._getGroupEntityFromScopePath(params['group_logic'], + group = self._logic.getGroupEntityFromScopePath(params['group_logic'], kwargs['scope_path']) # get the request scope path