def create(self): if self.validate(): auction_id = self._generate_id() self._context.id = auction_id db = self._request.registry.db server_id = self._request.registry.server_id self._context.auctionID = generate_auction_id( get_now(), db, server_id) return self._context
def _create(self, auction): auction_id = uuid4().hex now = get_now() db = self.request.registry.db server_id = self.request.registry.server_id auction.id = auction_id auction.auctionID = generate_auction_id(get_now(), db, server_id) auction.modified = True auction.auctionParameters = {'type': AUCTION_PARAMETERS_TYPE} auction.date = now return auction
def post(self): """This API request is targeted to creating new Auctions by procuring organizations. """ auction = self.request.validated['auction'] if auction['_internal_type'] == 'geb': manager = self.request.registry.queryMultiAdapter( (self.request, auction), IManager) applicant = self.request.validated['auction'] auction = manager.create(applicant) if not auction: return else: self.request.registry.getAdapter( auction, IAuctionManager).create_auction(self.request) auction_id = generate_id() auction.id = auction_id auction.auctionID = generate_auction_id(get_now(), self.db, self.server_id) if hasattr(auction, "initialize"): auction.initialize() status = self.request.json_body['data'].get('status') if status and status in ['draft', 'pending.verification']: auction.status = status acc = set_ownership(auction, self.request) self.request.validated['auction'] = auction self.request.validated['auction_src'] = {} if save_auction(self.request): self.LOGGER.info( 'Created auction {} ({})'.format(auction['id'], auction.auctionID), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_create'}, { 'auction_id': auction['id'], 'auctionID': auction.auctionID })) self.request.response.status = 201 auction_route_name = get_auction_route_name(self.request, auction) self.request.response.headers['Location'] = self.request.route_url( route_name=auction_route_name, auction_id=auction['id']) return {'data': auction.serialize(auction.status), 'access': acc}
def post(self): """This API request is targeted to creating new Auctions by procuring organizations. Creating new Auction ------------------- Example request to create auction: .. sourcecode:: http POST /auctions HTTP/1.1 Host: example.com Accept: application/json { "data": { "procuringEntity": { "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": 500, "currency": "UAH", "valueAddedTaxIncluded": true }, "itemsToBeProcured": [ { "description": "футляри до державних нагород", "primaryClassification": { "scheme": "CAV", "id": "44617100-9", "description": "Cartons" }, "additionalClassification": [ { "scheme": "ДКПП", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "unitOfMeasure": "item", "quantity": 5 } ], "enquiryPeriod": { "endDate": "2014-10-31T00:00:00" }, "tenderPeriod": { "startDate": "2014-11-03T00:00:00", "endDate": "2014-11-06T10:00:00" }, "awardPeriod": { "endDate": "2014-11-13T00:00:00" }, "deliveryDate": { "endDate": "2014-11-20T00:00:00" }, "minimalStep": { "amount": 35, "currency": "UAH" } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.1/auctions/64e93250be76435397e8c992ed4214d1 Content-Type: application/json { "data": { "id": "64e93250be76435397e8c992ed4214d1", "auctionID": "UA-64e93250be76435397e8c992ed4214d1", "dateModified": "2014-10-27T08:06:58.158Z", "procuringEntity": { "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": 500, "currency": "UAH", "valueAddedTaxIncluded": true }, "itemsToBeProcured": [ { "description": "футляри до державних нагород", "primaryClassification": { "scheme": "CAV", "id": "44617100-9", "description": "Cartons" }, "additionalClassification": [ { "scheme": "ДКПП", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "unitOfMeasure": "item", "quantity": 5 } ], "enquiryPeriod": { "endDate": "2014-10-31T00:00:00" }, "tenderPeriod": { "startDate": "2014-11-03T00:00:00", "endDate": "2014-11-06T10:00:00" }, "awardPeriod": { "endDate": "2014-11-13T00:00:00" }, "deliveryDate": { "endDate": "2014-11-20T00:00:00" }, "minimalStep": { "amount": 35, "currency": "UAH" } } } """ self.request.registry.getAdapter(self.request.validated['auction'], IAuctionManager).create_auction( self.request) auction_id = generate_id() auction = self.request.validated['auction'] auction.id = auction_id auction.auctionID = generate_auction_id(get_now(), self.db, self.server_id) if hasattr(auction, "initialize"): auction.initialize() status = self.request.json_body['data'].get('status') if status and status in ['draft', 'pending.verification']: auction.status = status acc = set_ownership(auction, self.request) self.request.validated['auction'] = auction self.request.validated['auction_src'] = {} if save_auction(self.request): self.LOGGER.info( 'Created auction {} ({})'.format(auction_id, auction.auctionID), extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_create'}, { 'auction_id': auction_id, 'auctionID': auction.auctionID })) self.request.response.status = 201 auction_route_name = get_auction_route_name(self.request, auction) self.request.response.headers['Location'] = self.request.route_url( route_name=auction_route_name, auction_id=auction_id) return {'data': auction.serialize(auction.status), 'access': acc}