Skip to content
Snippets Groups Projects
Commit d5cc6253 authored by Štěpán Farka's avatar Štěpán Farka Committed by jan.bednarik
Browse files

[FIX] copy page with calendar

parent 921e1d6a
No related branches found
No related tags found
2 merge requests!496Release,!493[FIX] copy page with calendar
Pipeline #8037 passed
from wagtail.core import hooks
from district.models import DistrictCenterPage, DistrictHomePage
# import re
#
# from wagtail.core import hooks
......@@ -44,3 +48,21 @@
#
# web_pages_id_list = root_page.get_descendants().live().values_list("id", flat=True)
# return pages.filter(id__in=web_pages_id_list)
@hooks.register("after_copy_page")
def handle_copy_calendar(request, origin_page, copied_page):
if (
isinstance(copied_page, DistrictHomePage)
or isinstance(copied_page, DistrictCenterPage)
) and origin_page.specific.calendar_id:
# get current calendar from origin page
calendar = origin_page.specific.calendar
# create copy of calendar
calendar.pk = None
calendar.save()
# set new copy of calendar
copied_page.calendar_id = calendar.id
copied_page.save()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment