예제 #1
0
def suggest_comment(context, data_dict):
    model = context['model']
    session = context['session']
    suggest_id = data_dict.get('suggest_id', '')

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

    # Init the data base
    db.init_db(model)

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

    # Validate comment
    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.now()

    session.add(comment)
    session.commit()

    return _dictize_comment(comment)
예제 #2
0
def suggest_comment_update(context, data_dict):
    model = context['model']
    session = context['session']
    suggest_id = data_dict.get('suggest_id', '')
    comment_id = data_dict.get('id', '')
    suggest_comment = data_dict.get('comment', '')
    log.info('suggest_comment_update1: %s' % comment_id)
    log.info('suggest_comment_update2: %s' % suggest_id)

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



    


        # Init the data base
    db.init_db(model)

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

    # Validate comment
    validator.validate_comment(context, data_dict)

    engine = model.meta.engine
    sql = "UPDATE suggests_comments set comment='%s',time='%s' where id='%s' " % (suggest_comment,datetime.datetime.now(),comment_id)
    log.info('suggest_comment_update3: %s' % text(sql))
    engine.execute(text(sql).execution_options(autocommit=True))
    # Store the data
    result = db.Comment.get(id=comment_id)
    comment = db.Comment()

        
    
    
    _undictize_comment_basic(comment, data_dict)
    comment.user_id = context['auth_user_obj'].id
    comment.time = datetime.datetime.now()
    comment.id = comment_id
    #log.info('suggest_comment_update3: %s' % type(comment))
    log.info('suggest_comment_update4: %s' % comment.id)

    #session.query(comment).filter(comment.id=='71c29998-8b1c-4ff5-9f97-15f5da2c5ff4').update({comment.comment:suggest_comment})
    #comment_record=session.query(comment).filter(comment.id=='71c29998-8b1c-4ff5-9f97-15f5da2c5ff4')
    #log.info('suggest_comment_update3: %s' % comment_record.id)
    #session.commit()

    return _dictize_comment(comment)
예제 #3
0
def datarequest_comment_update(context, data_dict):
    '''
    Action to update a comment of a data request. Access rights will be checked before
    updating the comment and a NotAuthorized exception will be risen if the user is not
    allowed to update the comment

    :param id: The ID of the comment to be updated
    :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']
    comment_id = data_dict.get('id', '')

    if not comment_id:
        raise tk.ValidationError(['Comment ID has not been included'])

    # Init the data base
    db.init_db(model)

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

    # Get the data request
    result = db.Comment.get(id=comment_id)
    if not result:
        raise tk.ObjectNotFound('Comment %s not found in the data base' %
                                comment_id)

    comment = result[0]

    # Validate data
    validator.validate_comment(context, data_dict)

    # Set the data provided by the user in the data_red
    _undictize_comment_basic(comment, data_dict)

    session.add(comment)
    session.commit()

    return _dictize_comment(comment)
예제 #4
0
def datarequest_comment_update(context, data_dict):
    '''
    Action to update a comment of a data request. Access rights will be checked before
    updating the comment and a NotAuthorized exception will be risen if the user is not
    allowed to update the comment

    :param id: The ID of the comment to be updated
    :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']
    comment_id = data_dict.get('id', '')

    if not comment_id:
        raise tk.ValidationError(['Comment ID has not been included'])

    # Init the data base
    db.init_db(model)

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

    # Get the data request
    result = db.Comment.get(id=comment_id)
    if not result:
        raise tk.ObjectNotFound('Comment %s not found in the data base' % comment_id)

    comment = result[0]

    # Validate data
    validator.validate_comment(context, data_dict)

    # Set the data provided by the user in the data_red
    _undictize_comment_basic(comment, data_dict)

    session.add(comment)
    session.commit()

    return _dictize_comment(comment)
예제 #5
0
def datarequest_comment(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.DATAREQUEST_COMMENT, context, data_dict)

    # Validate comment
    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.now()

    session.add(comment)
    session.commit()

    return _dictize_comment(comment)
예제 #6
0
def datarequest_comment(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(['Data Request ID has not been included'])

    # Init the data base
    db.init_db(model)

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

    # Validate comment
    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.now()

    session.add(comment)
    session.commit()

    return _dictize_comment(comment)