Webmention support for any Django model.
Project description
Mentions
Mentions lets you add Webmention functionality to any Django model with minimal setup. Code for an example implementation is available here.
Migration warning for existing users
1.x.x releases have not included Django migration files, requiring users to run makemigrations themselves. This may result in problems for those users when models defined in django-wm change. 1.3.1 is the last release affected by this.
Migration files will be included from version 2.0.0 onwards, as they should have been from the beginning. Unfortunately this will require some manual intervention for existing users who need to update. Full instructions for that upgrade will be provided (thanks to @GriceTurrble).
I apologise to any existing users affected by this change.
Installation
PyPI: django-wm
pip install django-wm
Setup
Celery
Mentions uses Celery and RabbitMQ for running tasks asynchronously. If you do not use them already you will need to set them up first.
System:
sudo apt install rabbitmq-server # Create user for celery service and make sure it can access your database # e.g: sudo useradd -N -M --system -s /bin/bash celery sudo usermod -a -G www-data celery # Run celery sudo -u celery env/bin/celery -A projectname worker &
Project:
Add
celery.py
to your root project. For an example implementation see celery.py from the example project.
Project code
Root project
settings.py
:Set
DOMAIN_NAME
:DOMAIN_NAME = "your.url.here" # e.g. "beatonma.org"
Add “mentions” to
INSTALLED_APPS
:INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.flatpages", "django.contrib.sites", ... "mentions", ]
Add :code:”mentions.middleware.WebmentionHeadMiddleware” to
MIDDLEWARE
:MIDDLEWARE = [ ... "mentions.middleware.WebmentionHeadMiddleware", ]
Root project
urls.py
urlpatterns = [ ... path("webmentions/", include("mentions.urls")), ]
Include
MentionableMixin
in the model(s) you want to support webmention functionality.IMPORTANT: Any models that include the mixin must also implement
all_text
andget_absolute_url
methods:from mentions.models.mixins.mentionable import MentionableMixin ... class MyModel(MentionableMixin, models.Model): ... def all_text(self) -> str: return f"{self.introduction} {self.content}" def get_absolute_url() -> str: return reverse("app.views.name", kwargs={"slug": self.slug})
Update database tables:
python manage.py makemigrations python manage.py migrate
Optional Settings
Add these keys to your project settings.py
to alter default behaviour.
WEBMENTIONS_AUTO_APPROVE
=bool
(default:False
)
True
: Received webmentions are automatically approved and may be publicly visible.
False
: Received webmentions require manual approval before they can be made public.
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
Hashes for django_wm-1.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20871056c01550d0587b4778fc3ff2fdca1a3590a1bfd18598f16a939dc8e196 |
|
MD5 | fe6e21a2146873cde04d012f8171a8b0 |
|
BLAKE2b-256 | db4126a4e5620d1a95c3089a62ad6710781c4b2256973dce2566e592ca843fc7 |