def run_scan(request):
    site = Site.find_for_request(request)
    celery_status = get_celery_worker_status()
    if 'ERROR' not in celery_status:
        broken_link_scan(site)
    else:
        messages.warning(request, _('No celery workers are running, the scan was not conducted.'))

    return redirect('wagtaillinkchecker')
    def handle(self, *args, **kwargs):
        site = Site.objects.filter(is_default_site=True).first()
        pages = site.root_page.get_descendants(inclusive=True).live().public()
        broken_links = broken_link_scan(site)

        messages = []
        for page in pages:
            revision = PageRevision.objects.filter(page=page).latest('created_at')
            page_broken_links = []
            for link in broken_links:
                if link.page == page:
                    page_broken_links.append(link)
            email_message = render_to_string(
                'wagtaillinkchecker/emails/broken_links.html', {
                    'page_broken_links': page_broken_links,
                    'user': revision.user,
                    'page': page,
                    'base_url': site.root_url,
                    'site_name': settings.WAGTAIL_SITE_NAME,
                    })
            email = EmailMessage(
                'Broken links on page "%s"' % (page.title),
                email_message,
                settings.DEFAULT_FROM_EMAIL,
                [revision.user.email])
            email.content_subtype = 'html'
            messages.append(email)

        connection = mail.get_connection()
        connection.open()
        connection.send_messages(messages)
        connection.close()
    def handle(self, *args, **kwargs):
        site = Site.objects.filter(is_default_site=True).first()
        pages = site.root_page.get_descendants(inclusive=True).live().public()
        broken_links = broken_link_scan(site)

        messages = []
        for page in pages:
            revision = PageRevision.objects.filter(
                page=page).latest('created_at')
            page_broken_links = []
            for link in broken_links:
                if link.page == page:
                    page_broken_links.append(link)
            email_message = render_to_string(
                'wagtaillinkchecker/emails/broken_links.html', {
                    'page_broken_links': page_broken_links,
                    'user': revision.user,
                    'page': page,
                    'base_url': site.root_url,
                    'site_name': settings.WAGTAIL_SITE_NAME,
                })
            email = EmailMessage('Broken links on page "%s"' % (page.title),
                                 email_message, settings.DEFAULT_FROM_EMAIL,
                                 [revision.user.email])
            email.content_subtype = 'html'
            messages.append(email)

        connection = mail.get_connection()
        connection.open()
        connection.send_messages(messages)
        connection.close()
Beispiel #4
0
def run_scan(request):
    site = Site.find_for_request(request)

    broken_link_scan(site)

    return redirect('wagtaillinkchecker')