Skip to content

Commit

Permalink
Fix: do not replace petition text with template one when creating fro…
Browse files Browse the repository at this point in the history
…m 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.
  • Loading branch information
fallen committed Jan 6, 2023
1 parent 2bf3fd3 commit 0cde440
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pytition/petition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ def transfer_to(self, user=None, org=None):
self.user = None
self.save()

def prepopulate_from_template(self, template, fields=None):
def prepopulate_from_template(self, template, fields=None, exclude_fields=None):
if fields is None:
fields = [f.name for f in self._meta.fields if f.name not in ["id", "title", "salt", "user", "org"]]
for field in fields:
if field in exclude_fields:
continue
if hasattr(self, field) and hasattr(template, field):
template_value = getattr(template, field)
if template_value is not None and template_value != "":
Expand Down
4 changes: 2 additions & 2 deletions pytition/petition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ def done(self, form_list, **kwargs):
if use_template:
template = PetitionTemplate.objects.get(pk=template_id)
if template in org.petitiontemplate_set.all():
petition.prepopulate_from_template(template)
petition.prepopulate_from_template(template, exclude_fields=['text'])
petition.save()
else:
messages.error(self.request, _("This template does not belong to your organization"))
Expand All @@ -1086,7 +1086,7 @@ def done(self, form_list, **kwargs):
if use_template:
template = PetitionTemplate.objects.get(pk=template_id)
if template in pytitionuser.petitiontemplate_set.all():
petition.prepopulate_from_template(template)
petition.prepopulate_from_template(template, exclude_fields=['text'])
petition.save()
else:
messages.error(self.request, _("This template does not belong to you"))
Expand Down

0 comments on commit 0cde440

Please sign in to comment.