feature: command for subscriptions

This commit is contained in:
Jean-Baptiste Pasquier 2020-10-15 13:54:37 +02:00
parent fc67e73701
commit f50d423690
2 changed files with 26 additions and 0 deletions

View File

@ -35,6 +35,12 @@ An object allowing a User to be notified of any change on a resource or a contai
For convenience, when you create a subscription on an object, DjangoLDP-Notification will parse the object for any one-to-many nested field relations. It will then create nested-subscriptions, i.e. a subscription on the nested field which sends an update to the same inbox, passing the parent model. If this behaviour is undesired you can delete the `Subscription` instance
You can automatically create required subscriptions based on your settings.py with this management command:
```bash
./manage.py create_subscriptions
```
# Middlewares
There is a `CurrentUserMiddleware` that catches the connected user of the last performed HTTP request and adds

View File

@ -0,0 +1,20 @@
from django.core.management.base import BaseCommand
from django.conf import settings
from djangoldp_notification.models import Subscription
class Command(BaseCommand):
help = 'Create required subscriptions'
def handle(self, *args, **options):
host = getattr(settings, 'SITE_URL')
jabber_host = getattr(settings, 'JABBER_DEFAULT_HOST')
xmpp = getattr(settings, 'PROSODY_HTTP_URL')
Subscription.objects.get_or_create(object=host+"/circles/", inbox=xmpp + "/conference." + jabber_host + "/happydev_muc_admin", field=None)
Subscription.objects.get_or_create(object=host+"/projects/", inbox=xmpp + "/conference." + jabber_host + "/happydev_muc_admin", field=None)
Subscription.objects.get_or_create(object=host+"/users/", inbox=xmpp + "/" + jabber_host + "/happydev_user_admin", field=None)
Subscription.objects.get_or_create(object=host+"/profiles/", inbox=xmpp + "/" + jabber_host + "/happydev_user_admin", field="user")
Subscription.objects.get_or_create(object=host+"/chatprofiles/", inbox=xmpp + "/" + jabber_host + "/happydev_user_admin", field="user")
Subscription.objects.get_or_create(object=host+"/accounts/", inbox=xmpp + "/" + jabber_host + "/happydev_user_admin", field="user")
self.stdout.write(self.style.SUCCESS("Successfully created subscriptions\nhost: "+host+"\nxmpp server: "+xmpp+"\njabber host: "+jabber_host))