Exemplo n.º 1
0
 def _load_from_db(self, max_age, session, expired_is_error=False):
     try:
         vpno = controller.get_vpno_obj(
             vendor=self._vendor._name, ident=self._canonical_repr,
             vpno=self._vpno, session=session
         )
         data_ts = vpno.updated_at.timestamp
         now = time.time()
         if now - data_ts > max_age:
             # TODO Populate part anyway here, and use sourcing maintenance
             # queue to refresh in the background.
             raise DBPartDataExpired
         self._vqtyavail = vpno.detail.vqtyavail
         self._manufacturer = vpno.detail.manufacturer
         self._mpartno = vpno.detail.mpartno
         self._vpartdesc = vpno.detail.vpartdesc
         self._pkgqty = vpno.detail.pkgqty
         self._last_updated = vpno.updated_at
         self._vparturl = vpno.detail.vparturl
         for price in vpno.prices:
             self.add_price(
                 VendorPrice(int(price.moq), float(price.price),
                             self._vendor.currency, int(price.oqmultiple))
             )
         return vpno
     except NoResultFound:
         raise DBPartDataUnavailable
     except AttributeError:
         raise DBPartDataIncomplete
Exemplo n.º 2
0
 def _commit_to_db(self, session):
     vpno = controller.get_vpno_obj(
         vendor=self._vendor._name, ident=self._canonical_repr,
         vpno=self._vpno, session=session
     )
     controller.populate_vpart_detail(
         vpno=vpno, vpart=self, session=session
     )
     controller.populate_vpart_prices(
         vpno=vpno, vpart=self, session=session
     )
     return vpno