예제 #1
0
    def notify(self):
        try:
            pusher_cluster = settings.PUSHER_CLUSTER
        except AttributeError:
            pusher_cluster = 'mt1'

        pusher = Pusher(app_id=settings.PUSHER_APP_ID,
                        key=settings.PUSHER_KEY,
                        secret=settings.PUSHER_SECRET,
                        cluster=pusher_cluster)

        #first, see if there are any users (if not, don't bother notifying)
        if not pusher.channel_info(self.channel(), ['occupied'])['occupied']:
            return

        pusher.trigger(
            [
                self.channel(),
            ],
            "update",
            {
                'object': self.get_state(),  #implemented in child class
            })