Beispiel #1
0
def getAllOrders(admin_user):
    all_orders = Order.query.all()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return jsonify([order.toPublicDict() for order in all_orders])
Beispiel #2
0
def getMarketProducts(admin_user):
    market_products = MarketProduct.getAllProducts()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return jsonify(market_products)
Beispiel #3
0
def getEmailListInfo(admin_user):
	email_list_id = request.json.get(Labels.EmailListId)
	email_list_info = EmailList.getEmailListInfo(email_list_id)
	if not email_list_info:
		AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = False)
		return JsonUtil.failure()
	AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True)
	return JsonUtil.successWithOutput({Labels.EmailList : email_list_info.toPublicDict()})
Beispiel #4
0
def getProductRequests():
	jwt = request.json.get(Labels.Jwt)
	decoded_jwt = JwtUtil.decodeAdminJwt(jwt)
	if not decoded_jwt:
		AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False)
		return JsonUtil.jwt_failure()

	all_requests = Request.query.all()
	AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = True)
	return jsonify([req.toPublicDict() for req in all_requests])
Beispiel #5
0
def addNewEmailList(admin_user):
	new_email_list_name = request.json.get(Labels.NewEmailListName)

	matching_list = EmailList.query.filter_by(email_list_name = new_email_list_name).first()
	if matching_list:
		AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = False)
		return JsonUtil.failure(ErrorMessages.EmailListNameTaken)
	EmailList.addNewEmailList(new_email_list_name)
	AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True)
	return JsonUtil.successWithOutput()
Beispiel #6
0
 def wrapper():
     jwt = request.json.get(Labels.Jwt)
     admin_user = JwtUtil.decodeAdminJwt(jwt)
     if not admin_user:
         AdminAction.addAdminAction(admin_user,
                                    request.path,
                                    request.remote_addr,
                                    success=False)
         return JsonUtil.failure(ErrorMessages.InvalidCredentials)
     return func(admin_user)
Beispiel #7
0
def getHomeImages(admin_user):
    home_images = HomeImage.query.filter_by().all()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.successWithOutput({
        Labels.Images:
        [home_image.toPublicDict() for home_image in home_images]
    })
Beispiel #8
0
def updateProductInfo(admin_user):

    product_id = request.json.get(Labels.ProductId)
    product = request.json.get(Labels.Product)
    sale_end_date = product.get('sale_end_date')
    print(sale_end_date)

    name = request.json.get(Labels.Name)
    tags = request.json.get(Labels.Tags)

    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("There was no input")
    if this_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Error retrieving product information")

    for key in product.keys():
        try:
            if key in MarketProduct.INTEGER_INPUTS:
                if product.get(key):
                    value = int(product.get(key))
                else:
                    value = None
            else:
                value = product.get(key)

            if key == Labels.ProductListingTags:
                tag_list = value.split(',')
                print(tag_list)
                this_product.updateProductListingTags(tag_list)
            if key == Labels.ProductSearchTags:
                tag_list = value.split(',')
                this_product.updateProductSearchTags(tag_list)
            if key == Labels.RelatedProductTags:
                tag_list = value.split(',')
                this_product.updateRelatedProductTags(tag_list)

            elif value != None:
                setattr(this_product, key, value)
        except:
            AdminAction.addAdminAction(admin_user,
                                       request.path,
                                       request.remote_addr,
                                       success=False)
            return JsonUtil.failure(key + " input is invalid")

    db.session.commit()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success(Labels.Product, this_product.toPublicDict())
Beispiel #9
0
def updateVariant(admin_user):
    product_id = request.json.get(Labels.ProductId)
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if this_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Invalid submission")

    variant = request.json.get(Labels.Variant)
    if not variant:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Invalid variant")

    this_variant = ProductVariant.query.filter_by(
        variant_id=variant[Labels.VariantId]).first()
    if not this_variant:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Invalid variant")

    this_variant.updateVariant(variant)
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()
Beispiel #10
0
def uploadHomeImage(admin_user):
    image_data = request.json.get(Labels.ImageData)
    if image_data == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("No image has been uploaded!")
    image_bytes = image_data.encode('utf-8')
    image_decoded = base64.decodestring(image_bytes)
    HomeImage.addHomeImage(image_decoded)
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()
Beispiel #11
0
def activateProduct(admin_user):
    product_id = request.json.get(Labels.ProductId)
    product = MarketProduct.query.filter_by(product_id=product_id).first()
    if product:
        product.activateProduct()
    else:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("product doesn't exist")
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success("Successfully activated \'" + product.name)
Beispiel #12
0
def getAdminMarketProductInfo(admin_user):
    product_id = request.json.get(Labels.ProductId)
    market_product = MarketProduct.query.filter_by(
        product_id=product_id).first()
    if market_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Error retrieving product information")
    else:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=True)
        return JsonUtil.success(Labels.Product, market_product.toPublicDict())
Beispiel #13
0
def addMarketProduct(admin_user):
    market_product = request.json.get(Labels.MarketProduct)
    if market_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Invalid submission")

    name = market_product.get(Labels.Name)
    new_product = MarketProduct(name)
    db.session.add(new_product)
    db.session.commit()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.successWithOutput(
        {Labels.Product: new_product.toPublicDict()})
Beispiel #14
0
def addProductVariant(admin_user):
    product_id = request.json.get(Labels.ProductId)
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if this_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Invalid submission")

    variant_type = request.json.get(Labels.VariantType)
    inventory = request.json.get(Labels.Inventory)
    price = request.json.get(Labels.Price)
    this_product.addProductVariant(variant_type, price, inventory)

    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.successWithOutput(
        {Labels.Product: this_product.toPublicDict()})
Beispiel #15
0
def toggleProductHasVariants(admin_user):
    product_id = request.json.get(Labels.ProductId)
    has_variants = request.json.get(Labels.HasVariants)
    if not product_id:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.falure("No product ID")
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if not this_product:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.falure("Product doesn't exist")

    this_product.has_variants = has_variants
    this_product.active = False
    db.session.commit()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()
Beispiel #16
0
def setMainProductPhoto(admin_user):
    product_id = request.json.get(Labels.ProductId)
    image_id = request.json.get(Labels.ImageId)
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if this_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Error retrieving product information")

    this_image = ProductImage.query.filter_by(image_id=image_id).first()
    if this_image == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Error retrieving image")

    this_product.main_image = image_id
    db.session.commit()
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success(Labels.Product, this_product.toPublicDict())
Beispiel #17
0
def updateHomeImage(admin_user):
    image_id = request.json.get(Labels.ImageId)
    live = request.json.get(Labels.Live)
    image_text = request.json.get(Labels.ImageText)
    if not image_id:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Bad home image input")

    home_image = HomeImage.query.filter_by(image_id=image_id).first()
    if not home_image:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Bad home image input")

    home_image.updateHomeImage(live, image_text)
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()
Beispiel #18
0
def softDeleteProductRequestByRequestId():
	jwt = request.json.get(Labels.Jwt)
	decoded_jwt = JwtUtil.decodeAdminJwt(jwt)
	if not decoded_jwt:
		AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False)
		return JsonUtil.jwt_failure()

	request_id = request.json.get(Labels.RequestId)
	if request_id == None:
		AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False)
		return JsonUtil.failure("Bad input")
	this_request = Request.query.filter_by(request_id = request_id).first()
	if this_request == None:
		AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False)
		return JsonUtil.failure("This request id doesn't exist")
	this_request.soft_deleted = True
	db.session.commit()
	AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = True)
	return JsonUtil.success()
Beispiel #19
0
def uploadManufacturerLogo(admin_user):
    product_id = request.json.get(Labels.ProductId)
    image_data = request.json.get(Labels.ImageData)
    if image_data == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("No image has been uploaded!")
    image_bytes = image_data.encode('utf-8')
    image_decoded = base64.decodestring(image_bytes)
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    if this_product == None:
        AdminAction.addAdminAction(admin_user,
                                   request.path,
                                   request.remote_addr,
                                   success=False)
        return JsonUtil.failure("Product doesn't exist")
    this_product.addManufacturerLogo(image_decoded)
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()
Beispiel #20
0
def getAllEmailListData(admin_user):
	email_list_data = EmailList.getAllEmailListData()
	AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True)
	return JsonUtil.successWithOutput({Labels.EmailListData : email_list_data})
Beispiel #21
0
def checkAdminJwt(admin_user):
    AdminAction.addAdminAction(admin_user,
                               request.path,
                               request.remote_addr,
                               success=True)
    return JsonUtil.success()