def serve_preview(self, request, mode_name):
    token = request.COOKIES.get('used-token')
    is_realtime = request.GET.get('realtime_preview')
    if (token and is_realtime):
        (page_preview, existed) = self.update_page_preview(token)
        PagePreview.garbage_collect()
        preview_update.send(sender=GrapplePageMixin, token=token)
    else:
        page_preview = self.create_page_preview()
        page_preview.save()
        PagePreview.garbage_collect()
    response = render(request, 'grapple/preview.html', {'preview_url': self.get_preview_url(page_preview.token)})
    response.set_cookie(key='used-token', value=page_preview.token)
    return response
def serve_preview(self, request, mode_name):
    token = request.COOKIES.get('used-token')
    is_realtime = request.GET.get('realtime_preview')
    if (token and is_realtime):
        (page_preview, existed) = self.update_page_preview(token)
        PagePreview.garbage_collect()
        preview_update.send(sender=GrapplePageMixin, token=token)
    else:
        page_preview = self.create_page_preview()
        page_preview.save()
        PagePreview.garbage_collect()
    response = render(request, 'grapple/preview.html', {'preview_url': self.get_preview_url(page_preview.token)})
    response.set_cookie(key='used-token', value=page_preview.token)
    return response