def collection_post(self): """Post a complaint """ auction = self.context if auction.status not in ['active.tendering']: self.request.errors.add('body', 'data', 'Can\'t add complaint in current ({}) auction status'.format(auction.status)) self.request.errors.status = 403 return complaint = self.request.validated['complaint'] complaint.date = get_now() if complaint.status == 'claim': complaint.dateSubmitted = get_now() else: complaint.status = 'draft' complaint.complaintID = '{}.{}{}'.format(auction.auctionID, self.server_id, sum([len(i.complaints) for i in auction.awards], len(auction.complaints)) + 1) set_ownership(complaint, self.request) auction.complaints.append(complaint) if save_auction(self.request): self.LOGGER.info('Created auction complaint {}'.format(complaint.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_complaint_create'}, {'complaint_id': complaint.id})) self.request.response.status = 201 route = self.request.matched_route.name.replace("collection_", "") self.request.response.headers['Location'] = self.request.current_route_url(_route_name=route, complaint_id=complaint.id, _query={}) return { 'data': complaint.serialize(auction.status), 'access': { 'token': complaint.owner_token } }
def collection_post(self): """Registration of new bid proposal Creating new Bid proposal ------------------------- Example request to create bid proposal: .. sourcecode:: http POST /auctions/4879d3f8ee2443169b5fbbc9f89fa607/bids HTTP/1.1 Host: example.com Accept: application/json { "data": { "tenderers": [ { "id": { "name": "Державне управління справами", "scheme": "https://ns.openprocurement.org/ua/edrpou", "uid": "00037256", "uri": "http://www.dus.gov.ua/" }, "address": { "countryName": "Україна", "postalCode": "01220", "region": "м. Київ", "locality": "м. Київ", "streetAddress": "вул. Банкова, 11, корпус 1" } } ], "value": { "amount": 489, "currency": "UAH", "valueAddedTaxIncluded": true } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Content-Type: application/json { "data": { "id": "4879d3f8ee2443169b5fbbc9f89fa607", "status": "registration", "date": "2014-10-28T11:44:17.947Z", "tenderers": [ { "id": { "name": "Державне управління справами", "scheme": "https://ns.openprocurement.org/ua/edrpou", "uid": "00037256", "uri": "http://www.dus.gov.ua/" }, "address": { "countryName": "Україна", "postalCode": "01220", "region": "м. Київ", "locality": "м. Київ", "streetAddress": "вул. Банкова, 11, корпус 1" } } ], "value": { "amount": 489, "currency": "UAH", "valueAddedTaxIncluded": true } } } """ # See https://github.com/open-contracting/standard/issues/78#issuecomment-59830415 # for more info upon schema auction = self.request.validated['auction'] if self.request.validated[ 'auction_status'] not in TENDER_PERIOD_STATUSES: self.request.errors.add( 'body', 'data', 'Can\'t add bid in current ({}) auction status'.format( self.request.validated['auction_status'])) self.request.errors.status = 403 return if auction.tenderPeriod.startDate and get_now( ) < auction.tenderPeriod.startDate or get_now( ) > auction.tenderPeriod.endDate: self.request.errors.add( 'body', 'data', 'Bid can be added only during the tendering period: from ({}) to ({}).' .format( auction.tenderPeriod.startDate and auction.tenderPeriod.startDate.isoformat(), auction.tenderPeriod.endDate.isoformat())) self.request.errors.status = 403 return bid = self.request.validated['bid'] set_ownership(bid, self.request) auction.bids.append(bid) auction.modified = False if save_auction(self.request): self.LOGGER.info( 'Created auction bid {}'.format(bid.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_bid_create'}, {'bid_id': bid.id})) self.request.response.status = 201 route = self.request.matched_route.name.replace("collection_", "") self.request.response.headers[ 'Location'] = self.request.current_route_url(_route_name=route, bid_id=bid.id, _query={}) return { 'data': bid.serialize('view'), 'access': { 'token': bid.owner_token } }