Esempio n. 1
0
    def get_one(self, id):
        """Get the price by id."""
        price = pecan.request.dbapi.price_get_by_id(id)
        if not price:
            msg = _("Price %s not found.") % str(id)
            raise exception.PriceNotFound(msg)

        return price
Esempio n. 2
0
    def delete(self, id):
        """Delete the price by id."""
        price = pecan.request.dbapi.price_get_by_id(id)
        if not price:
            msg = _("Price %s not found.") % str(id)
            raise exception.PriceNotFound(msg)

        pecan.request.dbapi.price_delete_by_id(id)
Esempio n. 3
0
 def price_delete_by_id(self, id):
     """Delete the price by id."""
     session = get_session()
     with session.begin():
         query = model_query(models.Price, session=session)
         query = add_identity_filter(query, id)
         count = query.delete()
         if count < 1:
             msg = ("Price %s not found.") % str(id)
             raise exception.PriceNotFound(msg)
Esempio n. 4
0
    def price_update_by_id(self, id, value):
        """Update the price by id."""
        session = get_session()

        with session.begin():
            query = model_query(models.Price, session=session)
            query = add_identity_filter(query, id)
            count = query.update(value, synchronize_session='fetch')
            if count < 1:
                msg = _("Price %s not found.") % str(id)
                raise exception.PriceNotFound(msg)
            price = query.one()

        return price
Esempio n. 5
0
    def get_price(self, resource_type=None):
        """Get the resource type by resource type and region."""
        if not resource_type:
            resource_type = self.resource_type
        price = self.db_api.price_get_by_resource(resource_type, self.region)

        if not price:
            msg = _("Price of %(res_type)s in region %(region)s could not "
                    "be found.") % {
                        'res_type': resource_type,
                        'region': self.region
                    }
            raise exception.PriceNotFound(msg)

        return price.unit_price
Esempio n. 6
0
    def put(self, data):
        """Modify the price."""
        value = data.as_dict()

        id = value.get('id', None)
        if not id:
            msg = _("Property id is required by the price.")
            raise exception.Invalid(msg)
        else:
            existed_price = pecan.request.dbapi.price_get_by_id(id)
            if not existed_price:
                msg = _("Price %s not found.") % str(id)
                raise exception.PriceNotFound(msg)

        price = pecan.request.dbapi.price_update_by_id(id, value)

        return price