Skip to content

Commit

Permalink
Fix loading fields data with json.loads
Browse files Browse the repository at this point in the history
  • Loading branch information
erick-otenyo committed May 25, 2023
1 parent d64e637 commit 6d819ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 13 additions & 3 deletions wagtailmailchimp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,19 @@ def get_data(self):
"interest_categories": {}
}

merge_fields_mapping = json.loads(self.merge_fields_mapping)

interest_categories = json.loads(self.interest_categories)
merge_fields_mapping = {}
if self.merge_fields_mapping:
try:
merge_fields_mapping = json.loads(self.merge_fields_mapping)
except Exception:
pass

interest_categories = {}
if self.interest_categories:
try:
interest_categories = json.loads(self.interest_categories)
except Exception:
pass

for key, value in merge_fields_mapping.items():
if key == "EMAIL":
Expand Down
5 changes: 4 additions & 1 deletion wagtailmailchimp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ def mailchimp_integration_view(request, page_id):

initial_data = None
if form_page.merge_fields_mapping:
initial_data = json.loads(form_page.merge_fields_mapping)
try:
initial_data = json.loads(form_page.merge_fields_mapping)
except Exception:
pass

form = MailchimpIntegrationForm(merge_fields=merge_fields, form_fields=form_fields, initial=initial_data)
context.update({"form": form})
Expand Down

0 comments on commit 6d819ab

Please sign in to comment.