Ejemplo n.º 1
0
def add_comment(id_user, id_article, email_of_non_registerd_user,
                name_of_non_registered_user, comment_text):
    import sequencer
    pid = sequencer.seq('comments', sequencer.mock_seq)

    if not id_user:
        import socket
        ip_user = socket.gethostbyname(socket.gethostname())
        id_comment = pid

        try:
            ip_2_comment = db.ip_2_Comm(ip_user, id_comment,
                                        email_of_non_registerd_user,
                                        name_of_non_registered_user)
            db.session.add(ip_2_comment)
            print(ip_2_comment)
        except:
            db.session.rollback()
            raise Exception

    try:

        comment = db.Comment(pid, id_user, id_article, comment_text)
        db.session.add(comment)
        db.session.commit()

    except sqlalchemy.exc.IntegrityError:
        db.session.rollback()
        raise ArticleAlreadyExistsException

    return pid
Ejemplo n.º 2
0
    def get(self):
        """Returns one or more comments.
        
        Parameters:
        
        count (optional): The number of results to return. Default is 100.
        page (optional): The page of results. Default is 1.
        user (optional): The email address of the comment submitter.
        
        Errors:
        
        400 Bad Request
        """
        result = {}
        count = self.request.get("count")
        if (count):
            count = int(count)
        else:
            count = 100
        page = self.request.get("page")
        if (page):
            page = int(page)
        else:
            page = 1
        user = google.appengine.api.users.User(self.request.get("user"))
        if (user):
            comments = db.Comment().fetchByUser(user, page, count)
            if (comments):
                result = [comment.toDictionary() for comment in comments]

        # Return the result
        self.respondWithDictionaryAsJSON({"result": result})
Ejemplo n.º 3
0
async def create_review(review: ReviewCreate,
                        db: Session = Depends(deps.get_db)):
    if db.query(models.Post).get(review.post_id):
        review_obj = models.Comment(**review.dict())
        db.add(review_obj)
        db.commit()
        db.refresh(review_obj)
        return Response200(data={"review": review_obj})
    return Response404(msg="评论失败,文章不存在")
Ejemplo n.º 4
0
 def get(self):
     """Returns the number of comments.
     
     Parameters:
     
     Errors:
     
     400 Bad Request
     """
     result = db.Comment().fetchCount()
     # Return the result
     self.respondWithDictionaryAsJSON({"result": result})
Ejemplo n.º 5
0
def add_comment(id_user, id_article, content):
    #we need to test is correct content of commentar
    return True
    try:
        aid = randomword(10, 'id')

        comment = db.Comment(aid, id_user, id_article, content)
        db.session.add(comment)
        db.session.commit()

    except sqlalchemy.exc.IntegrityError:
        db.session.rollback()
        raise CommentAlreadyExistsException
Ejemplo n.º 6
0
def save_comment():
    if not request.form['content'].strip():     # empty
        return redirect(request.form['path'])

    s_id = int(request.form['s_id'])
    new_cmt = db.Comment(
        s_id = None if s_id == -1 else s_id,
        author = session['u_id'],
        time = datetime.today(),
        content = request.form['content'],
    )
    g.db_session.add(new_cmt)
    g.db_session.commit()
    return redirect(request.form['path'])
Ejemplo n.º 7
0
def comment_datarequest(context, data_dict):
    '''
    Action to create a comment in a data request. Access rights will be checked
    before creating the comment and a NotAuthorized exception will be risen if
    the user is not allowed to create the comment

    :param datarequest_id: The ID of the datarequest to be commented
    :type id: string

    :param comment: The comment to be added to the data request
    :type comment: string

    :returns: A dict with the data request comment (id, user_id, datarequest_id,
       time and comment)
    :rtype: dict

    '''

    model = context['model']
    session = context['session']
    datarequest_id = data_dict.get('datarequest_id', '')

    # Check id
    if not datarequest_id:
        raise tk.ValidationError(
            [tk._('Data Request ID has not been included')])

    # Init the data base
    db.init_db(model)

    # Check access
    tk.check_access(constants.COMMENT_DATAREQUEST, context, data_dict)

    # Validate comment
    datarequest_dict = validator.validate_comment(context, data_dict)

    # Store the data
    comment = db.Comment()
    _undictize_comment_basic(comment, data_dict)
    comment.user_id = context['auth_user_obj'].id
    comment.time = datetime.datetime.utcnow()

    session.add(comment)
    session.commit()

    # Mailing
    users = _get_datarequest_involved_users(context, datarequest_dict)
    _send_mail(users, 'new_comment', datarequest_dict)

    return _dictize_comment(comment)
Ejemplo n.º 8
0
def comment_add():
    comment = request.get_json()
    print("评论:", comment)

    # 评论添加到数据库
    c = db.Comment(comment=comment["comment"],
                   circle_messages_id=comment["id"],
                   comment_name=comment["comment_name"])
    db.session.add(c)
    db.session.commit()

    s = {
        'status': 200,
    }
    return jsonify(s)
Ejemplo n.º 9
0
from faker import Faker

import db
fake = Faker('en_US')


user_autor = db.User.create(name="Bruno")

for _ in range(200):
    fake_news = db.News()
    fake_news.user = user_autor
    fake_news.title = fake.text(max_nb_chars=100)
    fake_news.content = fake.text(max_nb_chars=1000)
    fake_news.date_published = fake.date_this_decade()
    fake_news.save()

    for _ in range(1000):
        fake_comment = db.Comment()
        fake_comment.user = user_autor
        fake_comment.date_published = fake_news.date_published = fake.date_this_decade()
        fake_comment.content = fake.text(max_nb_chars=100)
        fake_comment.news = fake_news
        fake_comment.save()