def process_caravan_contract_report_result(request): lot = request.validated['lot'] contract = request.validated['contract'] if lot.status == 'active.contracting' and contract.status == 'unsuccessful': LOGGER.info('Switched lot %s to %s', lot.id, 'pending.dissolution', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_pending.dissolution'})) lot.status = 'pending.dissolution' elif lot.status == 'active.contracting' and contract.status == 'complete': LOGGER.info('Switched lot %s to %s', lot.id, 'pending.sold', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_pending.sold'})) lot.status = 'pending.sold'
def process_concierge_auction_status_change(request): lot = request.validated['lot'] if lot.status == 'active.salable' and request.validated['auction'].status == 'active': LOGGER.info('Switched lot %s to %s', lot.id, 'active.auction', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_active.auction'})) lot.status = 'active.auction'
def process_convoy_auction_report_result(request): lot = request.validated['lot'] is_lot_need_to_be_dissolved = bool(request.validated['auction'].status in ['cancelled', 'unsuccessful']) if lot.status == 'active.auction' and is_lot_need_to_be_dissolved: LOGGER.info('Switched lot %s to %s', lot.id, 'pending.dissolution', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_pending.dissolution'})) lot.status = 'pending.dissolution' lot.contracts[0].status = 'cancelled' elif lot.status == 'active.auction' and request.validated['auction'].status == 'complete': LOGGER.info('Switched lot %s to %s', lot.id, 'active.contracting', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_active.contracting'})) lot.status = 'active.contracting'
def check_lot_status(request, lot, now=None): if not now: now = get_now() if lot.status == 'pending' and lot.next_check <= now: LOGGER.info('Switched lot %s to %s', lot.id, 'active.salable', extra=context_unpack(request, {'MESSAGE_ID': 'switched_lot_active.salable'})) lot.status = 'active.salable'
def patch(self): """Lot Auction Update""" if apply_patch(self.request, src=self.request.context.serialize()): self.LOGGER.info( 'Updated lot auction {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_auction_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """Lot Decision Update""" if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info( 'Updated lot decision {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_decision_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): """Auction Document Update""" if apply_patch(self.request, src=self.request.context.serialize()): update_file_content_type(self.request) self.LOGGER.info( 'Updated auction document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_document_patch'})) return {'data': self.request.context.serialize("view")}
def patch(self): self.request.registry.getAdapter(self.context, ILotManager).change_lot(self.request) lot = self.context apply_patch(self.request, src=self.request.validated['lot_src']) self.LOGGER.info( 'Updated lot {}'.format(lot.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_patch'}) ) return {'data': lot.serialize(lot.status)}
def put(self): """Auction Document Update""" document = self.request.validated['document'] self.request.validated['auction'].documents.append(document) if save_lot(self.request): self.LOGGER.info( 'Updated auction document {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_document_put'})) return {'data': document.serialize("view")}
def process_convoy_auction_report_result(request): lot = request.validated['lot'] is_lot_need_to_be_dissolved = bool( request.validated['auction'].status == 'cancelled' or all([auction.status == 'unsuccessful' for auction in lot.auctions])) if lot.status == 'active.auction' and is_lot_need_to_be_dissolved: LOGGER.info('Switched lot %s to %s', lot.id, 'pending.dissolution', extra=context_unpack( request, {'MESSAGE_ID': 'switched_lot_pending.dissolution'})) lot.status = 'pending.dissolution' lot.contracts[0].status = 'cancelled' for auction in lot.auctions[request.validated['auction']. tenderAttempts:]: auction.status = 'cancelled' elif lot.status == 'active.auction' and request.validated[ 'auction'].status == 'unsuccessful': LOGGER.info('Switched lot %s to %s', lot.id, 'active.salable', extra=context_unpack( request, {'MESSAGE_ID': 'switched_lot_active.salable'})) lot.status = 'active.salable' elif lot.status == 'active.auction' and request.validated[ 'auction'].status == 'complete': LOGGER.info('Switched lot %s to %s', lot.id, 'active.contracting', extra=context_unpack( request, {'MESSAGE_ID': 'switched_lot_active.contracting'})) lot.status = 'active.contracting' for auction in lot.auctions[request.validated['auction']. tenderAttempts:]: auction.status = 'cancelled'
def get(self): self.LOGGER.info('Extract credentials for lot {}'.format( self.context.id)) lot = self.request.validated['lot'] data = lot.serialize('extract_credentials') or {} data['transfer_token'] = lot.transfer_token self.LOGGER.info( 'Extracted credentials of lot {}'.format(lot.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_credentials_extract'})) return {'data': data}
def patch(self): """Lot Contract Update""" apply_patch(self.request, save=False, src=self.request.context.serialize()) if self.request.authenticated_role == 'caravan': process_caravan_contract_report_result(self.request) if save_lot(self.request): self.LOGGER.info( 'Updated lot contract {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_contract_patch'}) ) return {'data': self.request.context.serialize("view")}
def post(self): lot = self.request.validated['lot'] location = self.request.route_path('Lot', lot_id=lot.id) location = location[len(ROUTE_PREFIX):] # strips /api/<version> ownership_changed = self.request.change_ownership(location) if ownership_changed and save_lot(self.request): self.LOGGER.info('Updated ownership of lot {}'.format(lot.id), extra=context_unpack( self.request, {'MESSAGE_ID': 'auction_ownership_update'})) return {'data': self.request.context.serialize('view')}
def patch(self): """Lot Auction Update""" apply_patch(self.request, save=False, src=self.request.context.serialize()) if self.request.authenticated_role == 'convoy': process_convoy_auction_report_result(self.request) elif self.request.authenticated_role == 'concierge': process_concierge_auction_status_change(self.request) if save_lot(self.request): self.LOGGER.info( 'Updated lot auction {}'.format(self.request.context.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_auction_patch'}) ) return {'data': self.request.context.serialize("view")}
def collection_post(self): """Lot Item Upload""" item = self.request.validated['item'] self.context.items.append(item) if save_lot(self.request): self.LOGGER.info( 'Created lot item {}'.format(item.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_item_create'}, {'item_id': item.id})) self.request.response.status = 201 item_route = self.request.matched_route.name.replace( "collection_", "") self.request.response.headers[ 'Location'] = self.request.current_route_url( _route_name=item_route, item_id=item.id, _query={}) return {'data': item.serialize("view")}
def collection_post(self): """Lot Document Upload""" document = self.request.validated['document'] document.author = self.request.authenticated_role self.context.documents.append(document) if save_lot(self.request): self.LOGGER.info( 'Created lot document {}'.format(document.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_document_create'}, {'document_id': document.id}) ) self.request.response.status = 201 document_route = self.request.matched_route.name.replace("collection_", "") self.request.response.headers['Location'] = self.request.current_route_url( _route_name=document_route, document_id=document.id, _query={} ) return {'data': document.serialize("view")}
def collection_post(self): """Lot Decision Upload""" decision = self.request.validated['decision'] self.context.decisions.append(decision) if save_lot(self.request): self.LOGGER.info( 'Created lot decision {}'.format(decision.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_decision_create'}, {'decision_id': decision.id})) self.request.response.status = 201 decision_route = self.request.matched_route.name.replace( "collection_", "") self.request.response.headers[ 'Location'] = self.request.current_route_url( _route_name=decision_route, decision_id=decision.id, _query={}) return {'data': decision.serialize("view")}