Skip to content

Commit 0cde440

Browse files
committed
Fix: do not replace petition text with template one when creating from template
The template text should be use as initial message in the petition creation Wizard. But when saving the petition, what the use has input in the Wizard should not be overwritten with the template text.
1 parent 2bf3fd3 commit 0cde440

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pytition/petition/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ def transfer_to(self, user=None, org=None):
235235
self.user = None
236236
self.save()
237237

238-
def prepopulate_from_template(self, template, fields=None):
238+
def prepopulate_from_template(self, template, fields=None, exclude_fields=None):
239239
if fields is None:
240240
fields = [f.name for f in self._meta.fields if f.name not in ["id", "title", "salt", "user", "org"]]
241241
for field in fields:
242+
if field in exclude_fields:
243+
continue
242244
if hasattr(self, field) and hasattr(template, field):
243245
template_value = getattr(template, field)
244246
if template_value is not None and template_value != "":

pytition/petition/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ def done(self, form_list, **kwargs):
10671067
if use_template:
10681068
template = PetitionTemplate.objects.get(pk=template_id)
10691069
if template in org.petitiontemplate_set.all():
1070-
petition.prepopulate_from_template(template)
1070+
petition.prepopulate_from_template(template, exclude_fields=['text'])
10711071
petition.save()
10721072
else:
10731073
messages.error(self.request, _("This template does not belong to your organization"))
@@ -1086,7 +1086,7 @@ def done(self, form_list, **kwargs):
10861086
if use_template:
10871087
template = PetitionTemplate.objects.get(pk=template_id)
10881088
if template in pytitionuser.petitiontemplate_set.all():
1089-
petition.prepopulate_from_template(template)
1089+
petition.prepopulate_from_template(template, exclude_fields=['text'])
10901090
petition.save()
10911091
else:
10921092
messages.error(self.request, _("This template does not belong to you"))

0 commit comments

Comments
 (0)