Esempio n. 1
0
    def post(self, request):
        message = self.request.POST.get("messagetext", None)
        if message:
            message_inst = models.MessageTask.objects.create(
                c_dest=models.MessageTask.C_DEST_INCOMING,
                c_status=models.MessageTask.C_STATUS_NOT_DONE,
                message=message,
                user=self.request.user,
            )
            process_message.apply_async(args=[message_inst.pk])

        return jsonResp({}, 204)
Esempio n. 2
0
    def get(self, request):
        try:
            last_id = int(self.request.GET.get("last_id", 0))
        except OSError:
            last_id = 0

        qs = models.MessageTask.objects.filter(user=self.request.user)

        qs = qs.filter(pk__gt=last_id)

        new_last_id = qs.aggregate(max_pk=Max('pk'))['max_pk'] if qs.count() else last_id

        return jsonResp({
            'last_id': new_last_id or 0,
            'messages': [message.render() for message in qs]
        })