Skip to content

Commit

Permalink
Merge pull request #189 from collective/python3
Browse files Browse the repository at this point in the history
Fix dict iteration for Python 3
  • Loading branch information
sgeulette authored May 29, 2024
2 parents 8732386 + 75f927a commit f3af2a1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/collective/z3cform/datagridfield/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _serializer(self, field_type):
def __call__(self, value, filestore, extra=None):
"""Create a new dict with all the contents serialized"""
rv = {}
for field_name, field_type in getFields(self.field.schema).items():
for field_name, field_type in list(getFields(self.field.schema).items()):
rv[field_name] = self._serializer(field_type)(
value.get(field_name), filestore, field_name
)
Expand Down
6 changes: 3 additions & 3 deletions src/collective/z3cform/datagridfield/datagridfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def value(self):
return self.extract()
except MultipleErrors:
value = {}
active_names = self.fields.keys()
active_names = list(self.fields.keys())
for name in getFieldNames(self.schema):
if name not in active_names:
continue
Expand All @@ -246,7 +246,7 @@ def value(self, value):
return

# ensure that we apply our new values to the widgets
active_names = self.fields.keys()
active_names = list(self.fields.keys())
for name, fieldset_field in self.schema.namesAndDescriptions():
if fieldset_field.readonly:
continue
Expand Down Expand Up @@ -341,7 +341,7 @@ def validate(self, value, force=False):
# ignore auto appended and template widgets
continue
# check each column
for col in row.widgets.values():
for col in list(row.widgets.values()):
if hasattr(col, "error") and col.error:
raise ValueError(col.label)
return None
4 changes: 2 additions & 2 deletions src/collective/z3cform/datagridfield/demo/editform_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def handleSave(self, action):
return

context = self.getContent()
for k, v in data.items():
for k, v in list(data.items()):
setattr(context, k, v)

def updateActions(self):
Expand Down Expand Up @@ -277,5 +277,5 @@ def updateWidgets(self):
super().updateWidgets()
self.widgets["address"].mode = DISPLAY_MODE
for row in self.widgets["address"].widgets:
for widget in row.subform.widgets.values():
for widget in list(row.subform.widgets.values()):
widget.mode = DISPLAY_MODE
4 changes: 2 additions & 2 deletions src/collective/z3cform/datagridfield/demo/editform_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def dumpOutput(self, data):
print(entry)

print("Dumping out raw HTTP POST form data")
for k, v in self.request.form.items():
for k, v in list(self.request.form.items()):
print(f"{k}: {v}")

@button.buttonAndHandler("Save", name="save")
Expand All @@ -129,7 +129,7 @@ def handleSave(self, action):
self.dumpOutput(data)

context = self.getContent()
for k, v in data.items():
for k, v in list(data.items()):
context[k] = v

def updateActions(self):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/z3cform/datagridfield/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DatagridRowDeserializer(DefaultFieldDeserializer):
def __call__(self, row):
row_data = {}

for name, field in getFields(self.field.schema).items():
for name, field in list(getFields(self.field.schema).items()):
if field.readonly:
continue

Expand Down
6 changes: 3 additions & 3 deletions src/collective/z3cform/datagridfield/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ def _validate(self, value):
if value is NO_VALUE:
return
# Treat readonly fields
for field_name in getFields(self.schema).keys():
for field_name in list(getFields(self.schema).keys()):
field = self.schema[field_name]
if field.readonly:
value[field_name] = field.default
errors = []
for field_name in getFields(self.schema).keys():
for field_name in list(getFields(self.schema).keys()):
if field_name not in value:
errors.append(AttributeNotFoundError(field_name, self.schema))

if errors:
raise WrongContainedType(errors, self.__name__)

# Pass 2 - Ensure fields are valid
for field_name, field_type in getFields(self.schema).items():
for field_name, field_type in list(getFields(self.schema).items()):
if IChoice.providedBy(field_type):
# Choice must be bound before validation otherwise
# IContextSourceBinder is not iterable in validation
Expand Down

0 comments on commit f3af2a1

Please sign in to comment.