Beispiel #1
0
def DeleteMetaData():

    intFavID = request.form['intFavID']
    intMetaDataID = request.form['intMetaDataID']

    objFavorite = Favorite.query.filter_by(id=intFavID).first()
    if objFavorite:
        objMetaData = Meta_Data.query.filter_by(id=intMetaDataID).first()
        if objMetaData:
            db.session.delete(objMetaData)
            objFavorite.modified_date = datetime.now()
            db.session.commit()
            response = success()

            objLogs = Audit_Log(
                description="Delete MetaData (%s) from (%s) Favorite" %
                (objMetaData.key, objFavorite.title),
                log_date=datetime.now())
            db.session.add(objLogs)
            db.session.commit()

        else:
            response = failure("This Meta Data is not exists")
    else:
        response = failure("This Favorite is not exists")

    return jsonify(response)
def UpdateFavorite():

    intFavID = request.form['intFavID']
    strTitle = request.form['strTitle']
    strDescription = request.form['strDescription']
    intRank = request.form['intRank']

    objFavorite = Favorite.query.filter_by(id=intFavID).first()
    if not objFavorite is None:
        if strTitle != objFavorite.title and Favorite.query.filter_by(
                title=strTitle).first():
            response = failure("Favorite Name Must be Unique")

        objFavorite.title = strTitle
        objFavorite.description = strDescription
        objFavorite.ranking = intRank
        objFavorite.modified_date = datetime.now()
        db.session.commit()
        response = success(objFavorite.as_dict())

        objLogs = Audit_Log(description="Update Favorite (%s)" % strTitle,
                            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Favorite is not Exists")

    return jsonify(response)
def DeleteCategory():
    intCatID = request.form['id']
    objCategory = Categories_Lookup.query.filter_by(id=intCatID).first()

    if not objCategory is None:
        lstFavorites = Favorite.query.filter_by(
            category_id=objCategory.id).all()
        if len(lstFavorites) > 0:
            for objFavorite in lstFavorites:
                lstMetadata = Meta_Data.query.filter_by(
                    favorite_id=objFavorite.id).all()
                if len(lstMetadata) > 0:
                    Meta_Data.query.filter_by(
                        favorite_id=objFavorite.id).delete()
            Favorite.query.filter_by(category_id=objCategory.id).delete()

        db.session.delete(objCategory)
        db.session.commit()
        response = success()

        objLogs = Audit_Log(description="Delete Category (%s)" %
                            objCategory.title,
                            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Category is not exists")

    return jsonify(response)
Beispiel #4
0
def GetLogs():
    
    lstLogs = Audit_Log.query.all()
    response = []
    for objLog in lstLogs:
        response.append(objLog.as_dict())

    return jsonify(success(response))
def GetAllCategories():

    objLogs = Audit_Log(description="Getting all Categories",
                        log_date=datetime.now())
    db.session.add(objLogs)
    db.session.commit()

    lstCategories = Categories_Lookup.query.all()
    response = [objCategory.as_dict() for objCategory in lstCategories]
    # response = []
    # for objCategory in lstCategories:
    #     response.append(objCategory.as_dict())
    return jsonify(success(response))
def AddFavByCatID():
    intCatID = request.form['intCatID']
    strFavoriteTitle = request.form['strFavoriteTitle']
    strDescription = request.form['strDescription']
    intRanking = request.form['intRanking']
    objCategory = Categories_Lookup.query.filter_by(id=intCatID).first()

    if not objCategory is None:
        objFavorite = Favorite.query.filter(
            Favorite.category_id == intCatID,
            Favorite.title == strFavoriteTitle).first()

        if objFavorite is None:
            objSameRankItem = Favorite.query.filter_by(
                category_id=intCatID, ranking=intRanking).first()
            if objSameRankItem:
                rankReorder(intCatID, intRanking)
            fav = Favorite(title=strFavoriteTitle,
                           description=strDescription,
                           ranking=intRanking,
                           cteated_date=datetime.now(),
                           modified_date=datetime.now(),
                           Category=objCategory)
            db.session.add(fav)
            db.session.commit()
            response = success(fav.as_dict())

            objLogs = Audit_Log(
                description="Add New Favorite (%s) for (%s) Category" %
                (strFavoriteTitle, objCategory.title),
                log_date=datetime.now())
            db.session.add(objLogs)
            db.session.commit()

        else:
            response = failure("Favorite Name Must be Unique")
    else:
        response = failure("This Category is not exists")

    return jsonify(response)
Beispiel #7
0
def GetMetaDataByFavID():

    intFavoriteID = request.args['intFavoriteID']
    objFavorite = Favorite.query.filter_by(id=intFavoriteID).first()
    if objFavorite:
        lstMetaData = Meta_Data.query.filter_by(favorite_id=intFavoriteID)
        response = []
        for objMetaData in lstMetaData:
            response.append(objMetaData.as_dict())
        response = success(response)

        objLogs = Audit_Log(
            description="Getting all Meta Data from (%s) Favorite" %
            objFavorite.title,
            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Favorite is not exists")

    return jsonify(response)
def GetFavByCatID():
    intCategoryID = request.args['intCategoryID']
    objCategory = Categories_Lookup.query.filter_by(id=intCategoryID).first()

    if not objCategory is None:
        lstFavorites = Favorite.query.filter_by(category_id=objCategory.id)
        response = []
        for objFavorite in lstFavorites:
            response.append(objFavorite.as_dict())
        response = success(response)

        objLogs = Audit_Log(
            description="Getting all Favorites for (%s) Category" %
            objCategory.title,
            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Category is not exists")

    return jsonify(response)
def AddCategory():
    strCategoryTitle = request.form["strCategoryTitle"]
    objCategory = Categories_Lookup.query.filter_by(
        title=strCategoryTitle).first()

    if objCategory is None:
        category = Categories_Lookup(title=strCategoryTitle,
                                     cteated_date=datetime.now(),
                                     modified_date=datetime.now())
        db.session.add(category)
        db.session.commit()
        response = success(category.as_dict())

        objLogs = Audit_Log(description="Add New Category (%s)" %
                            strCategoryTitle,
                            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Category is already exists")

    return jsonify(response)
Beispiel #10
0
def AddMetaData():

    intFavID = request.form['intFavID']
    key = request.form['key']
    value = request.form['value']
    objFavorite = Favorite.query.filter_by(id=intFavID).first()
    if objFavorite:
        objMetaData = Meta_Data(key=key, value=value, FavoriteItem=objFavorite)
        db.session.add(objMetaData)
        objFavorite.modified_date = datetime.now()
        db.session.commit()
        response = success(objMetaData.as_dict())

        objLogs = Audit_Log(
            description="Add New MetaData (%s) for (%s) Favorite" %
            (key, objFavorite.title),
            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Favorite is not exists")

    return jsonify(response)
Beispiel #11
0
def DeleteFavorite():

    intFavID = request.form['intFavID']
    objFavorite = Favorite.query.filter_by(id=intFavID).first()

    if not objFavorite is None:

        lstMetaData = Meta_Data.query.filter_by(favorite_id=intFavID).all()
        if len(lstMetaData) > 0:
            Meta_Data.query.filter_by(favorite_id=intFavID).delete()
        db.session.delete(objFavorite)
        db.session.commit()
        response = success()

        objLogs = Audit_Log(description="Delete Favorite (%s)" %
                            objFavorite.title,
                            log_date=datetime.now())
        db.session.add(objLogs)
        db.session.commit()

    else:
        response = failure("This Favorite is not Exists")

    return jsonify(response)
Beispiel #12
0
def ClearLogs():
    
    Audit_Log.query.delete()
    db.session.commit()
    return jsonify(success())