lib.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:dbas 作者: hhucn 项目源码 文件源码
def delete_row(table_name, uids, nickname, _tn):
    """
    Deletes a row in a table

    :param table_name: Name of the table
    :param uids: Array with uids
    :param nickname: Current nickname of the user
    :param _tn: Translator
    :return: Empty string or error message
    """
    logger('AdminLib', 'delete_row', table_name + ' ' + str(uids) + ' ' + nickname)
    if not is_user_admin(nickname):
        return _tn.get(_.noRights)

    if not table_name.lower() in table_mapper:
        return _tn.get(_.internalKeyError)

    table = table_mapper[table_name.lower()]['table']
    try:
        # check if there is a table, where uid is not the PK!
        if table_name.lower() == 'settings':
            uid = DBDiscussionSession.query(User).filter_by(nickname=uids[0]).first().uid
            DBDiscussionSession.query(table).filter_by(author_uid=uid).delete()
        elif table_name.lower() == 'premise':
            DBDiscussionSession.query(table).filter(Premise.premisesgroup_uid == uids[0],
                                                    Premise.statement_uid == uids[1]).delete()
        else:
            DBDiscussionSession.query(table).filter_by(uid=uids[0]).delete()

    except IntegrityError as e:
        logger('AdminLib', 'delete_row IntegrityError', str(e))
        return 'SQLAlchemy IntegrityError: ' + str(e)
    except ProgrammingError as e:
        logger('AdminLib', 'delete_row ProgrammingError', str(e))
        return 'SQLAlchemy ProgrammingError: ' + str(e)

    DBDiscussionSession.flush()
    transaction.commit()
    return ''
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号