Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
syn
committed
Sep 12, 2016
1 parent
5fe8db9
commit 9ebfa46
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
recursive-include instant/static * | ||
recursive-include instant/migrations * | ||
recursive-include instant/templates * | ||
recursive-include instant/templatetags * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from string import lower | ||
from cent.core import Client | ||
from instant.utils import format_event_class | ||
from instant.conf import SITE_NAME, CENTRIFUGO_HOST, CENTRIFUGO_PORT, SECRET_KEY, SITE_SLUG | ||
|
||
|
||
def broadcast(message, event_class="default", data={}, channel=None, site=SITE_NAME, message_label=None, target=None): | ||
cent_url = CENTRIFUGO_HOST+":"+str(CENTRIFUGO_PORT) | ||
client = Client(cent_url, SECRET_KEY, timeout=1) | ||
if channel is None: | ||
if target is not None: | ||
if target == "superuser": | ||
channel = "$"+SITE_SLUG+'_admin' | ||
if target == "staff": | ||
channel = "$"+SITE_SLUG+'_staff' | ||
if target == "users": | ||
channel = "$"+SITE_SLUG+'_users' | ||
else: | ||
return False, None | ||
else: | ||
_get_public_channel() | ||
if message_label is None: | ||
message_label = format_event_class(obj=None, event_class=event_class) | ||
payload = {"message": message, "channel":channel, 'message_label':message_label, 'event_class':event_class, "data":data , "site":site} | ||
client.publish(channel, payload) | ||
if lower(event_class) == "debug": | ||
print "[DEBUG] "+str(json.dumps(payload)) | ||
return True, channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from setuptools import setup, find_packages | ||
|
||
|
||
version = __import__('instant').__version__ | ||
|
||
setup( | ||
name = 'django-instant', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
version = version, | ||
description = 'Websockets for Django with Centrifugo ', | ||
author = 'synw', | ||
author_email = 'synwe@yahoo.com', | ||
url = 'https://github.com/synw/django-instant', | ||
download_url = 'https://github.com/synw/django-instant/releases/tag/'+version, | ||
keywords = ['django', 'websockets', 'centrifugo'], | ||
classifiers = [ | ||
'Development Status :: 3 - Alpha', | ||
'Framework :: Django :: 1.9', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 2.7', | ||
], | ||
install_requires=[ | ||
'cent', | ||
], | ||
zip_safe=False | ||
) |