Beispiel #1
0
def create_message(instance, **kwargs):
    client = Client()
    client.publish(instance.chat.get_channel_name(),
                   MessageSerializer(instance).data)
    response = client.send()
    print('sent to channel {}, got response from centrifugo: {}'.format(
        instance.chat.get_channel_name(), response))
Beispiel #2
0
    def dispatch(self, request, *args, **kwargs):
        self.comment_form = CommentForm(
            request.POST
            or None)  # create filled (POST) or empty form (initial GET)
        if request.method == 'POST':
            self.comment_form.instance.article_id = self.get_object().id

            if self.comment_form.is_valid():
                comment = self.comment_form.save(commit=True)
                client = Client()
                client.publish(
                    self.get_object().get_cent_comments_channel_name(),
                    comment.as_compact_dict())
                cent_response = client.send()
                print('sent to channel {}, got response from centrifugo: {}'.
                      format(
                          self.get_object().get_cent_comments_channel_name(),
                          cent_response))
                return HttpResponse()
                # return HttpResponseRedirect(reverse('news:detail', args=[self.get_object().pk,]))
            else:
                return super().get(request, *args, **kwargs)
                # context = self.get_context_data()
                # return render('news/article.html', context)

        return super().dispatch(request, *args, **kwargs)
Beispiel #3
0
 def handle(self, *args, **options):
     client = Client()
     client.publish(
         'public:map', {
             "lat": options.get("lat"),
             "long": options.get("long"),
             "content": options.get("content")
         })
     resp = client.send()
     print resp
Beispiel #4
0
def comment_post_save(sender, instance, created, **kwargs):
    from adjacent import Client
    if created:
        client = Client()
        client.publish(instance.parent_post.get_cent_answers_channel_name(), instance.as_compact_dict())
        response = client.send()
        print(
            'sent to channel {}, got response from centrifugo: {}'.format(
                instance.parent_post.get_cent_answers_channel_name(),
                response))
Beispiel #5
0
def on_answer_creation(sender, instance, *args, **kwargs):
    if kwargs.get('created'):
        comment = instance
        from .tasks import send_email_notification
        send_email_notification.delay(
            '*****@*****.**',
            'New answer to question "{}"'.format(comment.post.title),
            'You got answer with the text: "{}"'.format(comment.text))

        client = Client()
        client.publish(comment.post.get_cent_answers_channel_name(),
                       comment.as_compact_dict())
        response = client.send()
        print('sent to channel {}, got response from centrifugo: {}'.format(
            comment.post.get_cent_answers_channel_name(), response))
Beispiel #6
0
    def dispatch(self, request, *args, **kwargs):
        self.comment_form = CommentForm(request.POST or None) # create filled (POST) or empty form (initial GET)
        if request.method == 'POST':
            self.comment_form.instance.article_id = self.get_object().id

            if self.comment_form.is_valid():
                comment = self.comment_form.save(commit=True)
                client = Client()
                client.publish(self.get_object().get_cent_comments_channel_name(), comment.as_compact_dict())
                cent_response = client.send()
                print('sent to channel {}, got response from centrifugo: {}'.format(self.get_object().get_cent_comments_channel_name(),
                                                                                    cent_response))
                return HttpResponse()
                # return HttpResponseRedirect(reverse('news:detail', args=[self.get_object().pk,]))
            else:
                return super().get(request, *args, **kwargs)
                # context = self.get_context_data()
                # return render('news/article.html', context)

        return super().dispatch(request, *args, **kwargs)
Beispiel #7
0
def send_data_to_client(channel, message, message_key=None):
    client = Client()
    if message_key is None:
        client.publish(channel, message)
    else:
        data = {}
        data[message_key] = message 
        client.publish(channel, ujson.dumps(data))
    return client.send()
Beispiel #8
0
def create_friends_on_friendship_approved(instance, *args, **kwargs):
    from adjacent import Client

    client = Client()

    # add some messages to publish
    client.publish("news", {"msg": u"Вам предложил дружить {}!".format(instance.author.username)})

    # actually send request with 2 publish messages added above to Centrifuge
    response = client.send()

    if isinstance(instance, Friendship):
        user1 = instance.author
        user2 = instance.recipient
        if instance.approved:
            if user2 not in user1.friends.all():
                Friend.objects.create(user1=user1, user2=user2)
            if user1 not in user2.friends.all():
                Friend.objects.create(user1=user2, user2=user1)
        else:
            if Friend.objects.filter(user1=user1, user2=user2):
                Friend.objects.get(user1=user1, user2=user2).delete()
            if Friend.objects.filter(user1=user2, user2=user1):
                Friend.objects.get(user1=user2, user2=user1).delete()
def built_notify(instance, created, **kwargs):
    # print("IN MSG SEND")
    # print(instance.is_successful)
    if instance.is_successful:
        client = Client()
        client.publish("news", {"msg": "Приложение {} собрано".format(instance.title), "url": "{}".format(instance.url),
                                "value": {
                                    "id": instance.id,
                                    "url": instance.url,
                                    "is_successful": instance.is_successful,
                                }})
        client.send()
def watchable_postsave(instance, created=False, **kwargs):
    if (created):
        client = Client()
        client.publish('posts', PostSerializer(instance).data)
        client.send()
Beispiel #11
0
 def handle(self, *args, **options):
     client = Client()
     client.publish(
         "map", {"lat": options.get("lat"), "long": options.get("long"), "content": options.get("content")}
     )
     client.send()
Beispiel #12
0
from adjacent import Client
from product import *

client = Client()
client.publish(Comments.product.get_cent_answers_channel_name(), product .as_compact_dict())
response = client.send()
print('sent to channel {}, got response from centrifugo: {}'.format(answer.question.get_cent_answers_channel_name(),
                                                                    response))