Skip to main content

Webmention support for any Django model.

Project description

Mentions

https://travis-ci.org/beatonma/django-wm.svg?branch=master

Mentions lets you add Webmention functionality to any Django model with minimal setup. There is an implementation running at https://django-wm.dev/ with source code available here.

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

  1. Root project settings.py:

    • Set DOMAIN_NAME:

      DOMAIN_NAME = 'your.url.here'  # e.g. 'django-wm.dev'
    • 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',
      ]
  2. Root project urls.py

    urlpatterns = [
        ...
        path('webmentions/', include('mentions.urls')),
    ]
  3. Include MentionableMixin in the model(s) you want to support webmention functionality.

    IMPORTANT: Any models that include the mixin must also implement all_text and get_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})
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-wm-1.0.3.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

django_wm-1.0.3-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file django-wm-1.0.3.tar.gz.

File metadata

  • Download URL: django-wm-1.0.3.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for django-wm-1.0.3.tar.gz
Algorithm Hash digest
SHA256 bd361e8e8f1f72cddc078dd75d1148da5af32a3c3120b244f708134f95d92239
MD5 82a01d97f8b843fd1a00f7b28ed14fa3
BLAKE2b-256 585349c2ad1e0793d75988fce1d3a1844af49e9ee9891b1a94cef161a3152bd2

See more details on using hashes here.

File details

Details for the file django_wm-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_wm-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for django_wm-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 64f593a00415909010a41a280627cfdbd73bb3f7f1d683ab907aea896c25fcbe
MD5 a9975f86d75938d952b5f8727a4c87e0
BLAKE2b-256 9e0e342c6bfc607c1ac898d1ffa755e626cc5bbbbcaed8ea14f6abbe4ec6ed5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page