Exemplo n.º 1
0
    def form_valid(self, form):
        print(form.cleaned_data)

        msg = form.cleaned_data['message']
        event_class = "default"
        if "event_class" in form.cleaned_data:
            event_class = form.cleaned_data['event_class']
        channel = form.cleaned_data['channel']
        default_channel = form.cleaned_data['default_channel']
        err = None
        if channel or default_channel:
            if default_channel:
                err = publish(message=msg,
                              event_class=event_class,
                              channel=default_channel)
            if channel:
                err = publish(message=msg,
                              event_class=event_class,
                              channel=channel)
            if err is not None:
                messages.warning(self.request,
                                 _(u"Error publishing the message: " + err))
            else:
                messages.success(
                    self.request,
                    _(u"Message published to the channel " + channel))
        else:
            messages.warning(self.request,
                             _(u"Please provide a valid channel"))
        return super(FrontendView, self).form_valid(form)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        exit_msg = "\nPresence worker stopped"
        verbosity = options["verbosity"]
        if verbosity > 0:
            print("Starting presence worker: watching channels",
                  ",".join(WATCH_CHANNELS))
            print("Sending presence info every", FREQUENCY, "seconds")
        while True:
            try:
                cent_url = CENTRIFUGO_HOST + ":" + str(CENTRIFUGO_PORT)
                client = Client(cent_url, SECRET_KEY, timeout=1)
                for chan in WATCH_CHANNELS:
                    data = client.presence(chan)
                    datapack = package(data, chan)
                    num_users = len(datapack["users"])
                    usr = "******"
                    if num_users > 1:
                        usr = "******"
                    msg = "Channel " + chan + ": " + str(num_users) + \
                        " " + usr + " and " + str(datapack["anonymous"]) + " anonymous" + \
                        " online"
                    now = datetime.now().strftime('%H:%M:%S')
                    if verbosity > 0:
                        print(now, msg)

                publish("", "__presence__", datapack, PUBLISH_CHANNEL)
                time.sleep(FREQUENCY)
            except KeyboardInterrupt:
                if verbosity > 0:
                    print(exit_msg)
                return
            except:
                if verbosity > 0:
                    print(exit_msg)
                return
Exemplo n.º 3
0
def rprint(*args):
    msg = ""
    for output in args:
        msg = msg + " " + str(output)
    if settings.DEBUG is True:
        print("[Remote terminal]", strip_tags(msg))
    try:
        publish(msg, event_class="__command__", channel=COMMAND_CHANNEL)
    except Exception as e:
        err.new(e, rprint, "Can not publish message for remote print")
        err.throw()
Exemplo n.º 4
0
def save(event, conf):
    data = {}
    if event.data:
        data = event.data
    user = "******"
    if event.user:
        user = event.user.username
    url = ""
    if event.url:
        url = event.url
    bucket = ""
    if event.bucket:
        bucket = event.bucket
    admin_url = ""
    if event.admin_url:
        admin_url = event.admin_url
    data["user"] = user
    data["url"] = url
    data["admin_url"] = admin_url
    data["bucket"] = bucket
    site = SITE_SLUG
    if "site" in event.data:
        site = event.data["site"]
    err = publish(
        message=event.name,
        event_class=event.event_class,
        channel=conf["channel"],
        data=data,
        site=site,
    )
    if err is not None:
        if settings.DEBUG:
            print("Error in Centrifugo mqueue hook:", err)
Exemplo n.º 5
0
def save(event, conf):
    data = {}
    if event.data:
        data = event.data
    user = "******"
    if event.user:
        user = event.user.username
    url = ""
    if event.url:
        url = event.url
    bucket = ""
    if event.bucket:
        bucket = event.bucket
    admin_url = ""
    if event.admin_url:
        admin_url = event.admin_url
    data["user"] = user
    data["url"] = url
    data["admin_url"] = admin_url
    data["bucket"] = bucket
    err = publish(message=event.name,
                  event_class=event.event_class,
                  channel=conf["channel"],
                  data=data)
    if err is not None:
        if settings.DEBUG:
            print("Error in Centrifugo mqueue hook:", err)
Exemplo n.º 6
0
 def post(self, request, *args, **kwargs):
     if not request.user.is_superuser:
         return JsonResponse({"ok": 0})
     data = json.loads(self.request.body.decode('utf-8'))
     msg = data["msg"]
     channel = data["channel"]
     event_class = "default"
     if "event_class" in data:
         event_class = data['event_class']
     err = publish(message=msg, event_class=event_class, channel=channel)
     if err is not None:
         errmsg = _(u"Error publishing the message: " + err)
         return JsonResponse({"ok": 0, "err": errmsg})
     return JsonResponse({"ok": 1})
Exemplo n.º 7
0
def cmderr(exc):
    publish(exc, event_class="__command_error__", channel=COMMAND_CHANNEL)
    if err.exists:
        err.report()
Exemplo n.º 8
0
 def end(self):
     publish("COMMAND_END",
             event_class="__command_end__",
             channel=COMMAND_CHANNEL)
Exemplo n.º 9
0
 def process_IN_MODIFY(self, event):
     print("Change in", event.pathname)
     publish("reload", event_class="reload", channel="$autoreload")