Do not rely on dicts.merge to change target
Also make dicts.merge actually not touch target. This is much cleaner
than modifying in place, especially since we assign the result of the
dicts.merge call to target most of the time anyway.
Patch by: Sverre Rabbelier
--- a/app/soc/logic/dicts.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/logic/dicts.py Mon Apr 13 15:31:39 2009 +0000
@@ -53,11 +53,10 @@
recursive: Determines whether merge_subdicts is recursive
Returns:
- the target dict, with any missing values from updates merged in, in-place.
+ a new dict, with any missing values from updates merged into target
"""
- if not target:
- target = {}
+ target = target.copy() if target else {}
for key, value in updates.iteritems():
if key not in target:
--- a/app/soc/views/helper/dynaform.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/helper/dynaform.py Mon Apr 13 15:31:39 2009 +0000
@@ -137,10 +137,7 @@
# The most interesting parameter, the 'extra fields' dictionary
dynaconf = getattr(meta, 'dynaconf', {})
- if not dynaproperties:
- dynaproperties = dynaconf
- else:
- dicts.merge(dynaproperties, dynaconf)
+ dynaproperties = dicts.merge(dynaproperties, dynaconf)
# Create a new DynaForm, using the properties we extracted
return newDynaForm(
--- a/app/soc/views/models/club.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/club.py Mon Apr 13 15:31:39 2009 +0000
@@ -124,7 +124,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['applicant_create_form'] = applicant_create_form
+ self._params['applicant_create_form'] = applicant_create_form
@decorators.merge_params
@decorators.check_access
--- a/app/soc/views/models/club_admin.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/club_admin.py Mon Apr 13 15:31:39 2009 +0000
@@ -85,7 +85,7 @@
super(View, self).__init__(params=params)
# register the role with the group_view
- params['group_view'].registerRole(params['module_name'], self)
+ self._params['group_view'].registerRole(self._params['module_name'], self)
# create and store the special form for invited users
updated_fields = {
@@ -96,7 +96,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['invited_create_form'] = invited_create_form
+ self._params['invited_create_form'] = invited_create_form
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
--- a/app/soc/views/models/club_member.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/club_member.py Mon Apr 13 15:31:39 2009 +0000
@@ -88,7 +88,7 @@
super(View, self).__init__(params=params)
# register the role with the group_view
- params['group_view'].registerRole(params['module_name'], self)
+ self._params['group_view'].registerRole(self._params['module_name'], self)
# create and store the special form for invited users
updated_fields = {
@@ -99,7 +99,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['invited_create_form'] = invited_create_form
+ self._params['invited_create_form'] = invited_create_form
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
--- a/app/soc/views/models/host.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/host.py Mon Apr 13 15:31:39 2009 +0000
@@ -97,7 +97,7 @@
super(View, self).__init__(params=params)
# register the role with the group_view
- params['group_view'].registerRole(params['module_name'], self)
+ self._params['group_view'].registerRole(self._params['module_name'], self)
# create and store the special form for invited users
updated_fields = {
@@ -108,7 +108,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['invited_create_form'] = invited_create_form
+ self._params['invited_create_form'] = invited_create_form
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
--- a/app/soc/views/models/mentor.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/mentor.py Mon Apr 13 15:31:39 2009 +0000
@@ -117,7 +117,7 @@
super(View, self).__init__(params=params)
# register the role with the group_view
- params['group_view'].registerRole(params['module_name'], self)
+ self._params['group_view'].registerRole(self._params['module_name'], self)
# create and store the special form for invited users
dynafields = [
@@ -140,7 +140,7 @@
dynaform=self._params['create_form'],
dynaproperties=dynaproperties)
- params['invited_create_form'] = invited_create_form
+ self._params['invited_create_form'] = invited_create_form
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
--- a/app/soc/views/models/org_admin.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/org_admin.py Mon Apr 13 15:31:39 2009 +0000
@@ -117,7 +117,7 @@
super(View, self).__init__(params=params)
# register the role with the group_view
- params['group_view'].registerRole(params['module_name'], self)
+ self._params['group_view'].registerRole(self._params['module_name'], self)
# create and store the special form for invited users
dynafields = [
@@ -140,7 +140,7 @@
dynaform = self._params['create_form'],
dynaproperties = dynaproperties)
- params['invited_create_form'] = invited_create_form
+ self._params['invited_create_form'] = invited_create_form
def _editPost(self, request, entity, fields):
"""See base.View._editPost().
--- a/app/soc/views/models/organization.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/organization.py Mon Apr 13 15:31:39 2009 +0000
@@ -171,7 +171,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['applicant_create_form'] = applicant_create_form
+ self._params['applicant_create_form'] = applicant_create_form
@decorators.merge_params
@decorators.check_access
@@ -367,14 +367,12 @@
except out_of_band.Error:
is_host = False
- new_params = {}
+ params = params.copy()
if is_host:
- new_params['list_action'] = (redirects.getAdminRedirect, params)
+ params['list_action'] = (redirects.getAdminRedirect, params)
else:
- new_params['list_action'] = (redirects.getPublicRedirect, params)
- # safe to merge them the wrong way around because of @merge_params
- params = dicts.merge(new_params, params)
+ params['list_action'] = (redirects.getPublicRedirect, params)
new_filter = {}
--- a/app/soc/views/models/request.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/request.py Mon Apr 13 15:31:39 2009 +0000
@@ -110,7 +110,7 @@
super(View, self).__init__(params=params)
# create and store the special forms for invite and requests
- params['invite_form'] = params['create_form']
+ self._params['invite_form'] = self._params['create_form']
updated_fields = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
@@ -122,7 +122,7 @@
dynaform = self._params['create_form'],
dynaproperties = updated_fields)
- params['request_form'] = request_form
+ self._params['request_form'] = request_form
@decorators.merge_params
--- a/app/soc/views/models/role.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/role.py Mon Apr 13 15:31:39 2009 +0000
@@ -161,9 +161,10 @@
super(View, self).__init__(params=params)
# add manage template
- params['manage_template'] = 'soc/%(module_name)s/manage.html' % params
+ template = 'soc/%(module_name)s/manage.html' % self._params
+ self._params['manage_template'] = template
- if params.get('show_in_roles_overview'):
+ if self._params.get('show_in_roles_overview'):
# add to roles overview
addRole(self)
--- a/app/soc/views/models/student_project.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/student_project.py Mon Apr 13 15:31:39 2009 +0000
@@ -147,13 +147,13 @@
}
student_edit_form = dynaform.newDynaForm(
- dynabase = params['dynabase'],
- dynamodel = params['logic'].getModel(),
- dynaexclude = params['create_dynaexclude'],
+ dynabase = self._params['dynabase'],
+ dynamodel = self._params['logic'].getModel(),
+ dynaexclude = self._params['create_dynaexclude'],
dynaproperties = dynaproperties,
)
- params['student_edit_form'] = student_edit_form
+ self._params['student_edit_form'] = student_edit_form
def _editGet(self, request, entity, form):
--- a/app/soc/views/models/student_proposal.py Mon Apr 13 15:30:48 2009 +0000
+++ b/app/soc/views/models/student_proposal.py Mon Apr 13 15:31:39 2009 +0000
@@ -165,7 +165,7 @@
dynaform=self._params['create_form'],
dynaproperties=dynaproperties)
- params['student_create_form'] = student_create_form
+ self._params['student_create_form'] = student_create_form
# create the special form for public review
dynafields = [
@@ -184,7 +184,7 @@
public_review_form = dynaform.newDynaForm(dynamodel=None,
dynabase=helper.forms.BaseForm, dynainclude=None,
dynaexclude=None, dynaproperties=dynaproperties)
- params['public_review_form'] = public_review_form
+ self._params['public_review_form'] = public_review_form
# create the special form for mentors
dynafields = [
@@ -229,7 +229,7 @@
mentor_review_form = dynaform.newDynaForm(dynamodel=None,
dynabase=helper.forms.BaseForm, dynainclude=None,
dynaexclude=None, dynaproperties=dynaproperties)
- params['mentor_review_form'] = mentor_review_form
+ self._params['mentor_review_form'] = mentor_review_form
dynafields = [
{'name': 'rank',
@@ -262,7 +262,7 @@
admin_review_form = dynaform.extendDynaForm(dynaform=mentor_review_form,
dynaproperties=dynaproperties)
- params['admin_review_form'] = admin_review_form
+ self._params['admin_review_form'] = admin_review_form
def _editGet(self, request, entity, form):
"""See base.View._editGet().