Ejemplo n.º 1
0
 def PreviewArticle(self, req, context):
     self._logger.info('Recieved a new article to Preview.')
     html_body = md_to_html(self._md_stub, req.body)
     na = article_pb2.NewArticle(author_id=req.author_id,
                                 title=req.title,
                                 body=html_body,
                                 creation_datetime=req.creation_datetime)
     resp = article_pb2.PreviewResponse(
         preview=na, result_type=general_pb2.ResultType.OK)
     return resp
Ejemplo n.º 2
0
    def send_create_activity_request(self, req, global_id):
        html_body = md_to_html(self._md_stub, req.body)
        ad = create_pb2.ArticleDetails(
            author_id=req.author_id,
            title=req.title,
            body=html_body,
            md_body=req.body,
            creation_datetime=req.creation_datetime,
            global_id=global_id,
            summary=req.summary,
        )
        create_resp = self._create_stub.SendCreate(ad)

        return create_resp.result_type
Ejemplo n.º 3
0
 def _update_locally(self, article, req):
     self._logger.info("Sending update request to DB")
     html_body = md_to_html(self._md, req.body)
     resp = self._db.Posts(dbpb.PostsRequest(
         request_type=dbpb.RequestType.UPDATE,
         match=dbpb.PostsEntry(global_id=article.global_id),
         entry=dbpb.PostsEntry(
             title=req.title,
             body=html_body,
             md_body=req.body,
             tags=convert_to_tags_string(req.tags),
             summary=req.summary,
         ),
     ))
     if resp.result_type != general_pb2.ResultType.OK:
         self._logger.error("Could not update article: %s", resp.error)
         return False
     return True
Ejemplo n.º 4
0
 def ReceiveUpdateActivity(self, req, ctx):
     self._logger.info("Received edit for article '%s'", req.title)
     html_body = md_to_html(self._md, req.body)
     resp = self._db.Posts(
         dbpb.PostsRequest(
             request_type=dbpb.PostsRequest.UPDATE,
             match=dbpb.PostsEntry(ap_id=req.ap_id),
             entry=dbpb.PostsEntry(
                 title=req.title,
                 body=html_body,
                 md_body=req.body,
                 summary=req.summary,
             ),
         ))
     if resp.result_type != dbpb.PostsResponse.OK:
         self._logger.error("Could not update article: %s", resp.error)
         return upb.UpdateResponse(
             result_type=upb.UpdateRespones.ERROR,
             error="Error updating article in DB",
         )
     return upb.UpdateResponse(result_type=upb.UpdateResponse.OK)
Ejemplo n.º 5
0
    def send_insert_request(self, req):
        global_id = req.author_id
        author = self._users_util.get_user_from_db(global_id=global_id)
        if author is None:
            self._logger.error(
                'Could not find user id in db: ' + str(global_id))
            return database_pb2.PostsResponse.error, None
        global_id = author.global_id

        html_body = md_to_html(self._md_stub, req.body)
        tags_string = convert_to_tags_string(req.tags)
        pe = database_pb2.PostsEntry(
            author_id=global_id,
            title=req.title,
            body=html_body,
            md_body=req.body,
            creation_datetime=req.creation_datetime,
            ap_id=req.ap_id,
            tags=tags_string,
            summary=req.summary,
        )
        pr = database_pb2.PostsRequest(
            request_type=database_pb2.PostsRequest.INSERT,
            entry=pe
        )
        posts_resp = self._db_stub.Posts(pr)
        if posts_resp.result_type == database_pb2.PostsResponse.ERROR:
            self._logger.error(
                'Could not insert into db: %s', posts_resp.error)

        pe.global_id = posts_resp.global_id
        self.index(pe)

        # If post_recommender is on, send new post to post_recommender
        if self._post_recommendation_stub is not None:
            self._add_post_to_recommender(pe)

        return posts_resp.result_type, posts_resp.global_id