wagtail-personalisation icon indicating copy to clipboard operation
wagtail-personalisation copied to clipboard

Varient faild Type Error when has GenericRelation

Open suxilog opened this issue 4 years ago • 0 comments

https://github.com/wagtail/wagtail-personalisation/blob/a81c5b35604ec6bfdab7a36474f9f4687a14f2e7/src/wagtail_personalisation/models.py#L273

Wagtail page model has exclude_fields_in_copy, but when personalisation create varient page, it does'n use this. We use hit count as GenericRelation model, This through type error. Our team use this way for temp:

def copy_for_segment(self, segment, exclude_fields=None):
        exclude_fields_in_copy = ["hit_count_generic"]
        default_exclude_fields_in_copy = ['id', 'path', 'depth', 'numchild', 'url_path', 'path', 'index_entries', 'comments']
        exclude_fields = default_exclude_fields_in_copy + exclude_fields_in_copy +(exclude_fields or [])
        page = self.canonical_page
        slug = "{}-{}".format(page.slug, segment.encoded_name())
        title = "{} ({})".format(page.title, segment.name)
        update_attrs = {
            'title': title,
            'slug': slug,
            'live': False,
        }

        with transaction.atomic():
            new_page = self.canonical_page.copy(
                update_attrs=update_attrs, copy_revisions=False, exclude_fields=exclude_fields)

            PersonalisablePageMetadata.objects.create(
                canonical_page=page,
                variant=new_page,
                segment=segment)
        return new_page

Same as page copy methord. Will sent a PR later.

suxilog avatar Nov 12 '21 01:11 suxilog