This package adds a report to your wagtail app that lists all external urls you have used on your pages.
Project description
Wagtail external links report
This package adds a report to your wagtail app that lists all external urls you have used on your page. This is useful for moderators to keep track of other websites you are referring to.
Features
- Report View: Adds a report in your wagtail admin that lists all external urls you have used on your page.
- Customizable: You can include or exclude specific page fields and block values with custom handlers.
Installation
You can install the library with the following command:
pip install wagtail-external-links-report
Add the app in your settings/base.py. Optionally define your custom report-view class:
INSTALLED_APPS = [
...
"wagtail_external_links_report",
...
]
...
EXTERNAL_LINKS_REPORT_CLASS = "home.views.CustomExternalLinksReportView"
By default, this app extracts all external urls (by a-tag) that are used in the body field of a page.
It doesn't matter which type the body field is of (can be plain-text, RichText or a StreamField).
When your field is a StreamField, the app will automatically look up all subblocks and subfields for a-tags with external urls.
You can add additional fields for look up. Moreover, you can add your own handlers for extracting urls from custom blocks.
To do this, you need to create a custom class that extends ExternalLinksReportView
and refer to this class in your settings/base.py with EXTERNAL_LINKS_REPORT_CLASS.
# home/views.py
from wagtail_external_links_report.utils import LinkExtractor
from wagtail_external_links_report.views import ExternalLinksReportView
from home.blocks import Button
class CustomExternalLinksReportView(ExternalLinksReportView):
page_title = "used URLS" # you can customize the view name in you wagtail admin too
def get_extractor(self):
return LinkExtractor(
allowed_fields=["title", "body", "footer"], # use your custom fields
custom_handlers={
Button: self.extract_from_button
}
)
def extract_from_button(self, value):
"""Example handler for a custom Button block."""
if value["button_page"] is None and value["button_url"]:
return [{
"text": value["button_text"],
"url": value["button_url"],
}]
return []
In the above example, a custom handler is registered for a custom Block type Button.
This example Button-block can either point to an internal page or to an external page.
With the custom handler you can lookup block-values without searching for a-tags and also exclude specific block-fields.
class Button(blocks.StructBlock):
""" A simple button which can either be an internal page or an external url """
button_text = blocks.CharBlock(required=True, default="more", max_length=40, label="Text")
button_page = blocks.PageChooserBlock(required=False, label="internal page")
button_url = blocks.URLBlock(required=False, label="external URL")
class Meta:
template = "layouts/button.html"
icon = "link"
label = "Button"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_external_links_report-0.1.0.tar.gz.
File metadata
- Download URL: wagtail_external_links_report-0.1.0.tar.gz
- Upload date:
- Size: 330.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5309f64b82d42d8f7f6ae3c0d28dc4dfbf9149603343ded689d8102fc0fa2b85
|
|
| MD5 |
6ed6ac12249ba0c6217b002063c3d301
|
|
| BLAKE2b-256 |
84aa418488aaf83354d0aeb856b40771157760718dd538236f381d6103e56aa7
|
File details
Details for the file wagtail_external_links_report-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wagtail_external_links_report-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bd1d4e092d495192137cfe0255b2ab88a3bb49342a2460258c6cf4ea7fac762
|
|
| MD5 |
ec9c02c5e697353a132f300ce2092820
|
|
| BLAKE2b-256 |
eeae846802672ddd515e946a4faca06e95445ec3a9df73893a9fe62bce0d6310
|