def unpublish(request, page_id): page = get_object_or_404(Page, id=page_id).specific user_perms = UserPagePermissionsProxy(request.user) if not user_perms.for_page(page).can_unpublish(): raise PermissionDenied next_url = get_valid_next_url_from_request(request) if request.method == 'POST': include_descendants = request.POST.get("include_descendants", False) page.unpublish() if include_descendants: live_descendant_pages = page.get_descendants().live().specific() for live_descendant_page in live_descendant_pages: if user_perms.for_page(live_descendant_page).can_unpublish(): live_descendant_page.unpublish() messages.success(request, _("Page '{0}' unpublished.").format(page.title), buttons=[ messages.button(reverse('wagtailadmin_pages:edit', args=(page.id,)), _('Edit')) ]) if next_url: return redirect(next_url) return redirect('wagtailadmin_explore', page.get_parent().id) return render(request, 'wagtailadmin/pages/confirm_unpublish.html', { 'page': page, 'next': next_url, 'live_descendant_count': page.get_descendants().live().count(), })
def unpublish(request, page_id): page = get_object_or_404(Page, id=page_id).specific user_perms = UserPagePermissionsProxy(request.user) if not user_perms.for_page(page).can_unpublish(): raise PermissionDenied next_url = get_valid_next_url_from_request(request) if request.method == 'POST': include_descendants = request.POST.get("include_descendants", False) page.unpublish() if include_descendants: live_descendant_pages = page.get_descendants().live().specific() for live_descendant_page in live_descendant_pages: if user_perms.for_page(live_descendant_page).can_unpublish(): live_descendant_page.unpublish() messages.success(request, _("Page '{0}' unpublished.").format(page.get_admin_display_title()), buttons=[ messages.button(reverse('wagtailadmin_pages:edit', args=(page.id,)), _('Edit')) ]) if next_url: return redirect(next_url) return redirect('wagtailadmin_explore', page.get_parent().id) return render(request, 'wagtailadmin/pages/confirm_unpublish.html', { 'page': page, 'next': next_url, 'live_descendant_count': page.get_descendants().live().count(), })
def unpublish(request, page_id): page = get_object_or_404(Page, id=page_id).specific user_perms = UserPagePermissionsProxy(request.user) if not user_perms.for_page(page).can_unpublish(): raise PermissionDenied next_url = get_valid_next_url_from_request(request) if request.method == "POST": include_descendants = request.POST.get("include_descendants", False) page.unpublish() if include_descendants: live_descendant_pages = page.get_descendants().live().specific() for live_descendant_page in live_descendant_pages: if user_perms.for_page(live_descendant_page).can_unpublish(): live_descendant_page.unpublish() messages.success( request, _("Page '{0}' unpublished.").format(page.get_admin_display_title()), buttons=[messages.button(reverse("wagtailadmin_pages:edit", args=(page.id,)), _("Edit"))], ) if next_url: return redirect(next_url) return redirect("wagtailadmin_explore", page.get_parent().id) return render( request, "wagtailadmin/pages/confirm_unpublish.html", {"page": page, "next": next_url, "live_descendant_count": page.get_descendants().live().count()}, )
def register_unplanned_events(request, events): permissions = UserPagePermissionsProxy(request.user) # Only get the last revision of never published and unplanned pages queryset = ( PageRevision.objects.filter( page__first_published_at__isnull=True).order_by( 'page', '-created_at') # .distinct('page') # Doesn't work with sqlite ) pages = [] ids = set() for page in queryset: page = page.as_page_object() if page.go_live_at is not None: continue if page.pk in ids: continue # Avoid duplicated event ids.add(page.pk) pages.append({ 'id': page.pk, 'title': page.title, 'url': page.full_url, 'editable': permissions.for_page(page).can_publish(), 'color': '#e9b04d', 'stick': True, 'data': get_page_event_data(page), }) return events + pages
def find_student_index_page(user): """Look for the student index page: a page of type StandardIndex with slug "students" where this user can add pages""" user_perms = UserPagePermissionsProxy(user) for page in StandardIndex.objects.filter(slug='students'): if user_perms.for_page(page).can_add_subpage(): return page raise Exception('No usable student index found (using the StandardIndex page type and with add permission for students)')
def find_rca_now_index_page(user): """Look for the RCA Now index page: a page of type RcaNowIndex where this user can add pages""" user_perms = UserPagePermissionsProxy(user) for page in RcaNowIndex.objects.all(): if user_perms.for_page(page).can_add_subpage(): return page raise Exception('No usable RCA Now section found (using the RcaNowIndex page type and with add permission for students)')
def find_student_index_page(user): """Look for the student index page: a page of type StandardIndex with slug "students" where this user can add pages""" user_perms = UserPagePermissionsProxy(user) for page in StandardIndex.objects.filter(slug='students'): if user_perms.for_page(page).can_add_subpage(): return page raise Exception( 'No usable student index found (using the StandardIndex page type and with add permission for students)' )
def find_rca_now_index_page(user): """Look for the RCA Now index page: a page of type RcaNowIndex where this user can add pages""" user_perms = UserPagePermissionsProxy(user) for page in RcaNowIndex.objects.all(): if user_perms.for_page(page).can_add_subpage(): return page raise Exception( 'No usable RCA Now section found (using the RcaNowIndex page type and with add permission for students)' )
def register_published_events(request, start, end, events): permissions = UserPagePermissionsProxy(request.user) queryset = Page.objects.filter(first_published_at__isnull=False) if start is not None: queryset = queryset.filter(first_published_at__gte=start) if end is not None: queryset = queryset.filter(first_published_at__lte=end) queryset = queryset.specific() return events + [{ 'id': page.pk, 'title': page.title, 'start': page.first_published_at.isoformat(), 'url': page.full_url, 'editable': permissions.for_page(page).can_unpublish(), 'color': '#333', 'data': get_page_event_data(page), } for page in queryset]
def register_planned_events(request, start, end, events): permissions = UserPagePermissionsProxy(request.user) # Only get the last revision of never published and planned pages queryset = ( PageRevision.objects.filter( page__first_published_at__isnull=True).order_by( 'page', '-created_at') # .distinct('page') # Doesn't work with sqlite ) if start is not None: start = parse_datetime(start) if end is not None: end = parse_datetime(end) pages = [] ids = set() for page in queryset: page = page.as_page_object() if page.go_live_at is None: continue if start is not None and start > page.go_live_at: continue if end is not None and end < page.go_live_at: continue if page.pk in ids: continue # Avoid duplicated event # Determine event color color = '#e9b04d' if page.expired: color = '#f37e77' elif page.approved_schedule: color = '#358c8b' ids.add(page.pk) pages.append({ 'id': page.pk, 'title': page.title, 'start': page.go_live_at.isoformat(), 'url': page.get_url(request), 'editable': permissions.for_page(page).can_publish(), 'color': color, 'data': get_page_event_data(page), }) return events + pages
def push_to_intranet(request, page_id): # Get page page = get_object_or_404(Page, id=page_id) # User must have publish permission user_perms = UserPagePermissionsProxy(request.user) page_perms = user_perms.for_page(page) if not page_perms.can_publish(): raise PermissionDenied if request.method == "POST": # Perform request url = settings.INTRANET_PUSH_URL.format( type=page._meta.app_label + '.' + page.__class__.__name__, id=page.id, ) response = requests.post(url) if response.status_code == 200: intranet_url = response.json()['public_url'] # Success message message = "Successfully pushed '{0}' to the intranet.".format( page.title) messages.success(request, message, buttons=[ messages.button(intranet_url, 'View on intranet'), ]) else: # Error message message = "Error received while pushing '{0}' to the intranet. (status code: {1})".format( page.title, request.status_code) messages.error(request, message) return redirect('wagtailadmin_explore', page.get_parent().id) return render(request, 'rca/admin/push_to_intranet.html', { 'page': page, })
def push_to_intranet(request, page_id): # Get page page = get_object_or_404(Page, id=page_id) # User must have publish permission user_perms = UserPagePermissionsProxy(request.user) page_perms = user_perms.for_page(page) if not page_perms.can_publish(): raise PermissionDenied if request.method == "POST": # Perform request url = settings.INTRANET_PUSH_URL.format( type=page._meta.app_label + '.' + page.__class__.__name__, id=page.id, ) response = requests.post(url) if response.status_code == 200: intranet_url = response.json()['public_url'] # Success message message = "Successfully pushed '{0}' to the intranet.".format(page.title) messages.success(request, message, buttons=[ messages.button( intranet_url, 'View on intranet' ), ]) else: # Error message message = "Error received while pushing '{0}' to the intranet. (status code: {1})".format(page.title, request.status_code) messages.error(request, message) return redirect('wagtailadmin_explore', page.get_parent().id) return render(request, 'rca/admin/push_to_intranet.html', { 'page': page, })