Ejemplo n.º 1
0
def add_comment(obj_type=None, obj_id=None, user=None, comment=None):

    if not obj_type:
        obj_type = request.form.get('obj_type')
    if not obj_id:
        obj_id = request.form.get('obj_id')
    if not user:
        user = request.form.get('user', current_user.id)
    if not comment:
        comment = request.form.get('comment')

    if obj_type and obj_id and user and comment and obj_type in (
            'report', 'requirement', 'req', 'indicator'):

        new_comment = Comments(user=user)
        new_comment.comment = comment
        if obj_type == 'report':
            new_comment.report = obj_id
        elif obj_type == 'requirement' or obj_type == 'req':
            new_comment.requirement = obj_id
        else:
            new_comment.indicator = obj_id

        add_db_entry(new_comment)
        return ('success')
    return ('Comment insert failed.')