def collection_post(self): """Auction Document Upload""" if not self.validate_document_editing_period('add'): return document = upload_file(self.request) if self.request.authenticated_role != "auction": if not self.request.auction.rectificationPeriod: self.request.auction.rectificationPeriod = generate_rectificationPeriod_tender_period_margin( self.request.auction) invalidate_bids_data(self.request.auction) self.context.documents.append(document) if save_auction(self.request): self.LOGGER.info( 'Created auction document {}'.format(document.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_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 put(self): """Auction Document Update""" if not self.validate_document_editing_period('update'): return document = upload_file(self.request) if self.request.authenticated_role != "auction": if not self.request.auction.rectificationPeriod: self.request.auction.rectificationPeriod = generate_rectificationPeriod_tender_period_margin( self.request.auction) invalidate_bids_data(self.request.auction) self.request.validated['auction'].documents.append(document) if save_auction(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 patch(self): """Auction Document Update""" if not self.validate_document_editing_period('update'): return apply_patch(self.request, save=False, src=self.request.context.serialize()) if self.request.authenticated_role != "auction": if not self.request.auction.rectificationPeriod: self.request.auction.rectificationPeriod = generate_rectificationPeriod_tender_period_margin( self.request.auction) invalidate_bids_data(self.request.auction) if save_auction(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): """Auction Edit (partial) For example here is how procuring entity can change number of items to be procured and total Value of a auction: .. sourcecode:: http PATCH /auctions/4879d3f8ee2443169b5fbbc9f89fa607 HTTP/1.1 Host: example.com Accept: application/json { "data": { "value": { "amount": 600 }, "itemsToBeProcured": [ { "quantity": 6 } ] } } And here is the response to be expected: .. sourcecode:: http HTTP/1.0 200 OK Content-Type: application/json { "data": { "id": "4879d3f8ee2443169b5fbbc9f89fa607", "auctionID": "UA-64e93250be76435397e8c992ed4214d1", "dateModified": "2014-10-27T08:12:34.956Z", "value": { "amount": 600 }, "itemsToBeProcured": [ { "quantity": 6 } ] } } """ auction = self.context if self.request.authenticated_role != 'Administrator' and auction.status in ['complete', 'unsuccessful', 'cancelled']: self.request.errors.add('body', 'data', 'Can\'t update auction in current ({}) status'.format(auction.status)) self.request.errors.status = 403 return if self.request.authenticated_role == 'chronograph': apply_patch(self.request, save=False, src=self.request.validated['auction_src']) check_status(self.request) save_auction(self.request) else: apply_patch(self.request, save=False, src=self.request.validated['auction_src']) if auction.status == 'active.tendering' and self.request.authenticated_role == 'auction_owner': if not auction.rectificationPeriod: auction.rectificationPeriod = generate_rectificationPeriod_tender_period_margin(auction) append_additional_classificator(auction) invalidate_bids_data(auction) save_auction(self.request) self.LOGGER.info('Updated auction {}'.format(auction.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_patch'})) return {'data': auction.serialize(auction.status)}