Beispiel #1
0
    def collect_data(cls, device_id, metadata):
        target_device = DeviceShadowModel.find_by_device_id(device_id)
        if not target_device:
            cls.logger.exception(
                "Tried to add a stamp of a device that doesn't exist")
            return "Invalid Request", 400
        try:
            new_stamp = DeviceDataModel(device_id, metadata)
            new_stamp.save_to_db()
        except:
            cls.logger.exception(
                "Error while creating a new stamp in the Device Data Model")
            return "Internal Server Error", 500

        if target_device.date_updated < new_stamp.date_created:
            try:
                target_device.shadow_metadata = new_stamp.device_metadata
                target_device.date_updated = new_stamp.date_created
                target_device.save_to_db()
                if float(new_stamp.device_metadata['percent']
                         ) < target_device.alert_level:
                    # move that niche thing to list
                    # if the same name is in the listtocart, delete that item
                    make = True
                    already = ListToCartModel.get_fam_list(
                        target_device.fam_id)
                    for each in already:
                        if each.alias == target_device.alias:
                            each.from_niche = True
                            each.in_store = target_device.auto_order_store
                            each.save_to_db()
                            make = False

                    if make:
                        try:
                            new_list_to_cart = ListToCartModel(
                                target_device.alias,
                                target_device.auto_order_store,
                                target_device.fam_id, "Niche")
                            new_list_to_cart.from_niche = True
                            new_list_to_cart.save_to_db()
                        except:
                            cls.logger.exception(
                                "Error while moving niche into listtocart")
                            return "Internal Server Error", 500

            except:
                cls.logger.exception("Error while saving most recent")
                return "Internal Server Error", 500

        return "", 201
Beispiel #2
0
    def register_list(cls, member_id, fam_id, alias, in_store):
        # make list_to_cart object
        member = MemberModel.find_by_id(member_id)
        already = ListToCartModel.get_fam_list(fam_id)
        for each in already:
            if each.alias == alias:
                return "Duplicate item in list", 400
        try:
            new_list_to_cart = ListToCartModel(
                alias, in_store, fam_id,
                member.first_name + " " + member.last_name)
            new_list_to_cart.save_to_db()
        except:
            cls.logger.exception("Error making a new ListToCart object")
            return "Internal Server Error", 500

        return "", 201