예제 #1
0
    def create(self, serializer):
        # TODO Зарефатороить или вынести в отдельный модуль
        # методы создания постов и комментариев
        tx = self.request.data.get('tx')
        updater = BaseUpdater(self.request.data.get('blockchain'))

        rpc = Steem(updater.blockchain.wss)

        try:
            r = rpc.broadcast(tx)
        except RPCError as e:
            operation = tx['operations'][0][1]
            operation['body'] = operation['body'][:100]

            logger.warning('%s: %s' % (e, pprint.pformat(operation)))

            return Response(str(e), status.HTTP_400_BAD_REQUEST)

        operation = r['operations'][0][1]

        p = rpc.get_content({
            'permlink': operation['permlink'],
            'author': operation['author']
        })

        post = updater.upgrade_post(p)

        return Response(self.serializer_action_classes['list'](post).data)
예제 #2
0
    def create(self, serializer):
        tx = self.request.data.get('tx')
        updater = BaseUpdater(self.request.data.get('blockchain'))

        rpc = Steem(updater.blockchain.wss)

        try:
            r = rpc.broadcast(tx)
        except RPCError as e:
            logger.warning('%s: %s' %
                           (e, pprint.pformat(tx['operations'][0][1])))
            return Response(str(e), status.HTTP_400_BAD_REQUEST)

        operation = r['operations'][0][1]

        comm = rpc.get_content({
            'permlink': operation['permlink'],
            'author': operation['author']
        })

        page = None

        author = updater.get_author(comm.parent_author)

        if Page.objects.filter(permlink=comm.parent_permlink).exists():
            # Если это коммект к посту
            page = Page.objects.get(author=author,
                                    permlink=comm.parent_permlink)
        else:
            parent_comm = Comment.objects.get(author=author,
                                              permlink=comm.parent_permlink)

        if page is not None:
            comment = updater.get_comment_ins(comm, page, parent=None)
        else:
            comment = updater.get_comment_ins(comm,
                                              parent_comm.page,
                                              parent=parent_comm)

        comment.save()

        return Response(self.serializer_class(comment).data)