Resolve bug in event copy signals of pdf output and badges

This commit is contained in:
Raphael Michel
2018-10-29 11:31:20 +01:00
parent d08cc12240
commit 4d4b498636
2 changed files with 13 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import copy
import json
from django.dispatch import receiver
from django.template.loader import get_template
@@ -62,13 +63,21 @@ def copy_item(sender, source, target, **kwargs):
@receiver(signal=event_copy_data, dispatch_uid="badges_copy_data")
def event_copy_data_receiver(sender, other, item_map, **kwargs):
def event_copy_data_receiver(sender, other, question_map, item_map, **kwargs):
layout_map = {}
for bl in other.badge_layouts.all():
oldid = bl.pk
bl = copy.copy(bl)
bl.pk = None
bl.event = sender
layout = json.loads(bl.layout)
for o in layout:
if o['type'] == 'textarea':
if o['content'].startswith('question_'):
newq = question_map.get(int(o['content'][9:]))
if newq:
o['content'] = 'question_{}'.format(newq.pk)
bl.save()
if bl.background and bl.background.name:

View File

@@ -97,7 +97,9 @@ def pdf_event_copy_data_receiver(sender, other, item_map, question_map, **kwargs
for o in layout:
if o['type'] == 'textarea':
if o['content'].startswith('question_'):
o['content'] = 'question_{}'.format(question_map.get(int(o['content'][9:]), 0).pk)
newq = question_map.get(int(o['content'][9:]))
if newq:
o['content'] = 'question_{}'.format(newq.pk)
bl.layout = json.dumps(layout)
bl.save()