Example #1
0
    def get_all_items_by_category():

        categories = Category._get_categories()
        print(categories)

        items_object = item_collection.find({}, {
            '_id': 0,
            'RowId': 1,
            'Title': 1
        })

        items = []
        for item in items_object:
            items.append(item)

        if len(items) == 0:
            return Tools.Result(False, Tools.errors('INF'))

        items_by_category = {}
        for category in categories:
            items_by_category[category['Title']] = []

        for item in items:
            for category in categories:
                if int(item['RowId']) == int(category['RowId']):
                    items_by_category[category['Title']].append(item['Title'])

        return Tools.Result(True, items_by_category)
Example #2
0
def add_category():
    try:
        data = request.get_json()
        return Category.add_category(data['RowId'], data['Title'],
                                     data['IconUrl'], data['ImageUrl'])
    except Exception as ex:
        return Tools.Result(False, ex.args)
Example #3
0
def get_categories():
    try:
        return Category.get_categories()
    except Exception as ex:
        import traceback
        traceback.print_exc()
        return Tools.Result(False, ex.args)
Example #4
0
def modify_category():
    try:
        data = request.get_json()
        return Category.modify_category(
            data['CategoryId'], data['RowId'] if 'RowId' in data else None,
            data['Title'] if 'Title' in data else None,
            data['IconUrl'] if 'IconUrl' in data else None,
            data['ImageUrl'] if 'ImageUrl' in data else None)
    except Exception as ex:
        return Tools.Result(False, ex.args)
Example #5
0
def delete_category():
    try:
        data = request.get_json()
        return Category.delete_category(data['RowId'])
    except Exception as ex:
        return Tools.Result(False, ex.args)
Example #6
0
def get_category_image(image_id):
    try:
        return Category.get_category_image(image_id)
    except Exception as ex:
        return Tools.Result(False, ex.args)