def collection_post(self): """Tender Bid Document Upload """ tender = self.request.validated['tender'] if tender.status not in [ 'active.tendering', 'active.auction', 'active.qualification' ]: self.request.errors.add( 'body', 'data', 'Can\'t add document in current tender status') self.request.errors.status = 403 return src = tender.serialize("plain") data = self.request.validated['file'] document = Document() document.id = generate_id() document.title = data.filename document.format = data.type key = generate_id() document.url = self.request.route_url( 'Tender Bid Documents', tender_id=tender.id, bid_id=self.request.validated['bid_id'], id=document.id, _query={'download': key}) self.request.validated['bid'].documents.append(document) upload_file(tender, document, key, data.file, self.request) save_tender(tender, src, self.request) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Tender Bid Documents', tender_id=tender.id, bid_id=self.request.validated['bid_id'], id=document.id) return {'data': document.serialize("view")}
def set_ownership(item): item.owner_token = generate_id() access = {"token": item.owner_token} if isinstance(getattr(type(item), "transfer_token", None), StringType): transfer = generate_id() item.transfer_token = sha512(transfer).hexdigest() access["transfer"] = transfer return access
def collection_post(self): transfer_id = generate_id() transfer = self.request.validated["transfer"] transfer.id = transfer_id access_token = transfer.access_token transfer_token = transfer.transfer_token set_ownership(transfer, self.request, access_token=access_token, transfer_token=transfer_token) self.request.validated["transfer"] = transfer if save_transfer(self.request): self.LOGGER.info( "Created transfer {}".format(transfer.id), extra=context_unpack(self.request, {"MESSAGE_ID": "transfer_create"}, {"transfer_id": transfer.id}), ) self.request.response.status = 201 return { "data": transfer.serialize("view"), "access": { "token": access_token, "transfer": transfer_token } }
def post(self): """ Creating new submission """ submission_id = generate_id() submission = self.request.validated["submission"] submission.id = submission_id framework = self.request.validated["framework"] submission.submissionType = framework["frameworkType"] submission.mode = framework.get("mode") if self.request.json["data"].get("status") == "draft": submission.status = "draft" access = set_ownership(submission, self.request) self.request.validated["submission"] = submission self.request.validated["submission_src"] = {} if save_submission(self.request): self.LOGGER.info( "Created submission {}".format(submission_id), extra=context_unpack( self.request, {"MESSAGE_ID": "submission_create"}, { "submission_id": submission_id, "submission_mode": submission.mode }, ), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url( "{}:Submission".format(submission.submissionType), submission_id=submission_id) return {"data": submission.serialize("view"), "access": access}
def put(self): """Tender Document Update""" tender = self.request.validated['tender'] first_document = self.request.validated['documents'][0] if tender.status != 'active.enquiries': self.request.errors.add('body', 'data', 'Can\'t update document in current tender status') self.request.errors.status = 403 return if self.request.content_type == 'multipart/form-data': data = self.request.validated['file'] filename = data.filename content_type = data.type in_file = data.file else: filename = first_document.title content_type = self.request.content_type in_file = self.request.body_file document = Document() document.id = self.request.validated['id'] document.title = filename document.format = content_type document.datePublished = first_document.datePublished key = generate_id() document.url = self.request.route_url('Tender Documents', tender_id=tender.id, id=document.id, _query={'download': key}) src = tender.serialize("plain") tender.documents.append(document) upload_file(tender, document, key, in_file, self.request) save_tender(tender, src, self.request) return {'data': document.serialize("view")}
def create_qualification(self): submission = self.request.context framework = self.request.validated["framework"] qualification_id = generate_id() qualification_data = { "id": qualification_id, "frameworkID": framework["_id"], "submissionID": submission.id, "framework_owner": framework["owner"], "framework_token": framework["owner_token"], "qualificationType": framework["frameworkType"], "mode": framework.get("type") } qualification = Qualification(qualification_data) self.request.validated["qualification_src"] = {} self.request.validated["qualification"] = qualification if save_qualification(self.request): submission.qualificationID = qualification_id self.LOGGER.info( "Created qualification {}".format(qualification_id), extra=context_unpack( self.request, {"MESSAGE_ID": "qualification_create"}, {"qualification_id": qualification_id, "qualification_mode": qualification.mode}, ), )
def post(self): """This API request is targeted to creating new Lot.""" lot_id = generate_id() lot = self.request.validated['lot'] lot.id = lot_id if not lot.get('lotID'): lot.lotID = generate_lot_id(get_now(), self.db, self.server_id) self.request.registry.notify(LotInitializeEvent(lot)) default_status = type(lot).fields['status'].default status = self.request.json_body['data'].get('status', default_status) if status == 'draft': lot.status = status else: self.request.errors.add('body', 'status', 'You can create only in draft status') self.request.errors.status = 403 return acc = set_ownership(lot, self.request) self.request.validated['lot'] = lot self.request.validated['lot_src'] = {} if save_lot(self.request): self.LOGGER.info('Created lot {} ({})'.format(lot_id, lot.lotID), extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_create'}, { 'lot_id': lot_id, 'lotID': lot.lotID })) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( '{}:Lot'.format(lot.lotType), lot_id=lot_id) return {'data': lot.serialize(lot.status), 'access': acc}
def create_agreement_contract(self): db = self.request.registry.db qualification = self.request.validated["qualification"] framework = self.request.validated["framework"] agreement_data = get_agreement_by_id(db, framework.agreementID) submission_data = get_submission_by_id(db, qualification.submissionID) if agreement_data["status"] != "active": return contract_id = generate_id() first_milestone_data = { "type": "activation", "documents": qualification.documents } contract_data = { "id": contract_id, "qualificationID": qualification.id, "status": "active", "suppliers": submission_data["tenderers"], "milestones": [first_milestone_data], } new_contracts = deepcopy(agreement_data.get("contracts", [])) new_contracts.append(contract_data) apply_patch(self.request, data={"contracts": new_contracts}, src=agreement_data, obj_name="agreement") self.LOGGER.info( "Updated agreement {} with contract {}".format( agreement_data["_id"], contract_id), extra=context_unpack(self.request, {"MESSAGE_ID": "qualification_patch"}))
def post(self): """This API request is targeted to creating new Asset.""" self.request.registry.getAdapter(self.request.validated['asset'], IAssetManager).create_asset( self.request) asset_id = generate_id() asset = self.request.validated['asset'] asset.id = asset_id if not asset.get('assetID'): asset.assetID = generate_asset_id(get_now(), self.db, self.server_id) self.request.registry.notify(AssetInitializeEvent(asset)) if self.request.json_body['data'].get('status') == 'draft': asset.status = 'draft' acc = set_ownership(asset, self.request) self.request.validated['asset'] = asset self.request.validated['asset_src'] = {} if save_asset(self.request): self.LOGGER.info( 'Created asset {} ({})'.format(asset_id, asset.assetID), extra=context_unpack(self.request, {'MESSAGE_ID': 'asset_create'}, { 'asset_id': asset_id, 'assetID': asset.assetID })) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Asset', asset_id=asset_id) return {'data': asset.serialize(asset.status), 'access': acc}
def put(self): """Tender Complaint Document Update""" tender = self.request.validated['tender'] if tender.status not in ['active.enquiries', 'active.tendering', 'active.auction', 'active.qualification', 'active.awarded']: self.request.errors.add('body', 'data', 'Can\'t update document in current tender status') self.request.errors.status = 403 return first_document = self.request.validated['documents'][0] src = tender.serialize("plain") if self.request.content_type == 'multipart/form-data': data = self.request.validated['file'] filename = data.filename content_type = data.type in_file = data.file else: filename = first_document.title content_type = self.request.content_type in_file = self.request.body_file document = Document() document.id = self.request.matchdict['id'] document.title = filename document.format = content_type document.datePublished = first_document.datePublished key = generate_id() document.url = self.request.route_url('Tender Complaint Documents', tender_id=tender.id, complaint_id=self.request.validated['complaint_id'], id=document.id, _query={'download': key}) self.request.validated['complaint'].documents.append(document) upload_file(tender, document, key, in_file, self.request) save_tender(tender, src, self.request) return {'data': document.serialize("view")}
def upload_file(request, blacklisted_fields=DOCUMENT_BLACKLISTED_FIELDS): first_document = ( request.validated["documents"][0] if "documents" in request.validated and request.validated["documents"] else None ) if request.content_type == "multipart/form-data": data = request.validated["file"] filename = get_filename(data) content_type = data.type in_file = data.file else: filename = first_document.title content_type = request.content_type in_file = request.body_file if hasattr(request.context, "documents"): # upload new document model = type(request.context).documents.model_class else: # update document model = type(request.context) document = model({"title": filename, "format": content_type}) document.__parent__ = request.context if "document_id" in request.validated: document.id = request.validated["document_id"] if first_document: for attr_name in type(first_document)._fields: if attr_name not in blacklisted_fields: setattr(document, attr_name, getattr(first_document, attr_name)) key = generate_id() document_route = request.matched_route.name.replace("collection_", "") document_path = request.current_route_path( _route_name=document_route, document_id=document.id, _query={"download": key} ) document.url = "/" + "/".join(document_path.split("/")[3:]) conn = getattr(request.registry, "s3_connection", None) if conn: bucket = conn.get_bucket(request.registry.bucket_name) filename = "{}/{}/{}".format(request.validated["plan_id"], document.id, key) key = bucket.new_key(filename) key.set_metadata("Content-Type", document.format) key.set_metadata( "Content-Disposition", build_header(document.title, filename_compat=quote(document.title.encode("utf-8"))) ) key.set_contents_from_file(in_file) key.set_acl("private") else: filename = "{}_{}".format(document.id, key) request.validated["plan"]["_attachments"][filename] = { "content_type": document.format, "data": b64encode(in_file.read()), } update_logging_context(request, {"file_size": in_file.tell()}) return document
def collection_post(self): """Tender Document Upload""" tender = self.request.validated['tender'] if tender.status != 'active.enquiries': self.request.errors.add('body', 'data', 'Can\'t add document in current tender status') self.request.errors.status = 403 return src = tender.serialize("plain") data = self.request.validated['file'] document = Document() document.id = generate_id() document.title = data.filename document.format = data.type key = generate_id() document.url = self.request.route_url('Tender Documents', tender_id=tender.id, id=document.id, _query={'download': key}) tender.documents.append(document) upload_file(tender, document, key, data.file, self.request) save_tender(tender, src, self.request) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url('Tender Documents', tender_id=tender.id, id=document.id) return {'data': document.serialize("view")}
def post(self): inspection = self.request.validated['inspection'] inspection.id = generate_id() inspection.inspection_id = generate_inspection_id(get_now(), self.db, self.server_id) set_author(inspection.documents, self.request, 'author') save_inspection(self.request, date_modified=inspection.dateCreated) LOGGER.info('Created inspection {}'.format(inspection.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'inspection_create'}, {'MONITORING_ID': inspection.id})) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Inspection', inspection_id=inspection.id) return {'data': inspection.serialize('view')}
def upload_file(request, blacklisted_fields=DOCUMENT_BLACKLISTED_FIELDS): first_document = request.validated['documents'][0] if 'documents' in request.validated and request.validated['documents'] else None if request.content_type == 'multipart/form-data': data = request.validated['file'] filename = get_filename(data) content_type = data.type in_file = data.file else: filename = first_document.title content_type = request.content_type in_file = request.body_file if hasattr(request.context, "documents"): # upload new document model = type(request.context).documents.model_class else: # update document model = type(request.context) document = model({'title': filename, 'format': content_type}) document.__parent__ = request.context if 'document_id' in request.validated: document.id = request.validated['document_id'] if first_document: for attr_name in type(first_document)._fields: if attr_name not in blacklisted_fields: setattr(document, attr_name, getattr(first_document, attr_name)) key = generate_id() document_route = request.matched_route.name.replace("collection_", "") document_path = request.current_route_path(_route_name=document_route, document_id=document.id, _query={'download': key}) document.url = '/' + '/'.join(document_path.split('/')[3:]) conn = getattr(request.registry, 's3_connection', None) if conn: bucket = conn.get_bucket(request.registry.bucket_name) filename = "{}/{}/{}".format(request.validated['contract_id'], document.id, key) key = bucket.new_key(filename) key.set_metadata('Content-Type', document.format) key.set_metadata("Content-Disposition", build_header(document.title, filename_compat=quote(document.title.encode('utf-8')))) key.set_contents_from_file(in_file) key.set_acl('private') else: filename = "{}_{}".format(document.id, key) request.validated['contract']['_attachments'][filename] = { "content_type": document.format, "data": b64encode(in_file.read()) } update_logging_context(request, {'file_size': in_file.tell()}) return document
def upload_file(request, blacklisted_fields=DOCUMENT_BLACKLISTED_FIELDS): first_document = request.validated['documents'][0] if 'documents' in request.validated and request.validated['documents'] else None if request.content_type == 'multipart/form-data': data = request.validated['file'] filename = get_filename(data) content_type = data.type in_file = data.file else: filename = first_document.title content_type = request.content_type in_file = request.body_file if hasattr(request.context, "documents"): # upload new document model = type(request.context).documents.model_class else: # update document model = type(request.context) document = model({'title': filename, 'format': content_type}) document.__parent__ = request.context if 'document_id' in request.validated: document.id = request.validated['document_id'] if first_document: for attr_name in type(first_document)._fields: if attr_name not in blacklisted_fields: setattr(document, attr_name, getattr(first_document, attr_name)) key = generate_id() document_route = request.matched_route.name.replace("collection_", "") document_path = request.current_route_path(_route_name=document_route, document_id=document.id, _query={'download': key}) document.url = '/' + '/'.join(document_path.split('/')[3:]) conn = getattr(request.registry, 's3_connection', None) if conn: bucket = conn.get_bucket(request.registry.bucket_name) filename = "{}/{}/{}".format(request.validated['auction_id'], document.id, key) key = bucket.new_key(filename) key.set_metadata('Content-Type', document.format) key.set_metadata("Content-Disposition", build_header(document.title, filename_compat=quote(document.title.encode('utf-8')))) key.set_contents_from_file(in_file) key.set_acl('private') else: filename = "{}_{}".format(document.id, key) request.validated['auction']['_attachments'][filename] = { "content_type": document.format, "data": b64encode(in_file.read()) } update_logging_context(request, {'file_size': in_file.tell()}) return document
def create_agreement_contract(self): qualification = self.request.validated["qualification"] framework = self.request.validated["framework"] agreement_data = get_agreement_by_id(self.request, framework.agreementID) if not agreement_data: raise_operation_error( self.request, "agreementID must be one of exists agreement", ) submission_data = get_submission_by_id(self.request, qualification.submissionID) if not agreement_data: raise_operation_error( self.request, "submissionID must be one of exists submission", ) if agreement_data["status"] != "active": return contract_id = generate_id() first_milestone_data = { "type": "activation", "dueDate": framework.get("qualificationPeriod").get("endDate") } contract_data = { "id": contract_id, "qualificationID": qualification.id, "submissionID": submission_data["_id"], "status": "active", "suppliers": submission_data["tenderers"], "milestones": [first_milestone_data], } new_contracts = deepcopy(agreement_data.get("contracts", [])) new_contracts.append(contract_data) apply_patch(self.request, data={"contracts": new_contracts}, src=agreement_data, obj_name="agreement") self.LOGGER.info( "Updated agreement {} with contract {}".format( agreement_data["_id"], contract_id), extra=context_unpack(self.request, {"MESSAGE_ID": "qualification_patch"}))
def post(self): agreement = self.request.validated["agreement"] if not agreement.id: agreement_id = generate_id() agreement.id = agreement_id if not agreement.get("agreementID"): agreement.prettyID = generate_agreementID(get_now(), self.db, self.server_id) # Unify when cfa moved from tenders to frameworks framework = self.request.validated.get("framework") if framework: agreement.submissionType = framework["frameworkType"] agreement.mode = framework.get("mode") upload_objects_documents( self.request, agreement, route_kwargs={"agreement_id": agreement.id}, route_prefix=framework["frameworkType"]) access = set_ownership(agreement, self.request) self.request.validated["agreement"] = agreement self.request.validated["agreement_src"] = {} if save_agreement(self.request): self.LOGGER.info( "Created agreement {} ({})".format(agreement.id, agreement.agreementID), extra=context_unpack( self.request, {"MESSAGE_ID": "agreement_create"}, { "agreement_id": agreement.id, "agreementID": agreement.agreementID }, ), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url( "{}.Agreement".format(agreement.agreementType), agreement_id=agreement.id) return {"data": agreement.serialize("view"), "access": access}
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): monitor = self.request.validated['monitor'] monitor.id = generate_id() set_ownership(monitor, self.request) self.request.validated['monitor'] = monitor self.request.validated['monitor_src'] = {} if save_monitor(self.request): LOGGER.info('Created monitor {}'.format(monitor.id), extra=context_unpack(self.request, {'MESSAGE_ID': 'monitor_create'}, {'monitor_id': monitor.id})) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Monitor', monitor_id=monitor.id) return { 'data': monitor.serialize("view"), 'access': { 'token': monitor.owner_token } }
def ensure_agreement(self): framework_data = self.request.validated["framework_src"] agreementID = framework_data.get("agreementID") if agreementID: agreement = get_agreement_by_id(self.request, agreementID) if not agreement: raise_operation_error( self.request, "agreementID must be one of exists agreement", ) self.request.validated["agreement"] = agreement = Agreement( agreement) agreement.__parent__ = self.request.validated[ "qualification"].__parent__ self.request.validated["agreement_src"] = agreement.serialize( "plain") else: agreement_id = generate_id() now = get_now() transfer = generate_id() transfer_token = sha512(transfer.encode("utf-8")).hexdigest() agreement_data = { "id": agreement_id, "agreementID": generate_agreementID( get_now(), self.request.registry.databases.agreements, self.server_id), "frameworkID": framework_data["id"], "agreementType": framework_data["frameworkType"], "status": "active", "period": { "startDate": now, "endDate": framework_data.get("qualificationPeriod").get("endDate") }, "procuringEntity": framework_data.get("procuringEntity"), "classification": framework_data.get("classification"), "additionalClassifications": framework_data.get("additionalClassifications"), "contracts": [], "owner": framework_data["owner"], "owner_token": framework_data["owner_token"], "mode": framework_data.get("mode"), "dateModified": now, "date": now, "transfer_token": transfer_token, "frameworkDetails": framework_data.get("frameworkDetails"), } agreement = Agreement(agreement_data) self.request.validated["agreement_src"] = {} self.request.validated["agreement"] = agreement if save_agreement(self.request): self.LOGGER.info( "Created agreement {}".format(agreement_id), extra=context_unpack( self.request, {"MESSAGE_ID": "agreement_create"}, { "agreement_id": agreement_id, "agreement_mode": agreement.mode }, ), ) framework_data_updated = {"agreementID": agreement_id} apply_patch(self.request, data=framework_data_updated, src=self.request.validated["framework_src"], obj_name="framework") self.LOGGER.info( "Updated framework {} with agreementID".format( framework_data["id"]), extra=context_unpack( self.request, {"MESSAGE_ID": "qualification_patch"}))
def set_ownership(item): item.owner_token = generate_id()
def post(self): """This API request is targeted to creating new Plan by procuring organizations. Creating new Plan ------------------- Example request to create plan: .. sourcecode:: http POST /plans HTTP/1.1 Host: example.com Accept: application/json { "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "unit": { "code": "KGM", "name": "кг" }, "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "name": "proj_name", "id": "proj_id" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.10/plans/84582807b5654bee9e216adb05e57d39 Content-Type: application/json { "access": { "token": "e4c75de4320649a4bbbdfa180e7a9ef2" }, "data": { "items": [ { "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні" }, { "scheme": "КЕКВ", "id": "123", "description": "-" } ], "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "id": "8cd4abfd0bbb489a83a81dec1393ab8d", "unit": { "code": "KGM", "name": "кг" }, "quantity": 760 } ], "planID": "UA-2015-11-26-000001", "budget": { "amountNet": 12222, "description": "budget_description", "project": { "id": "proj_id", "name": "proj_name" }, "currency": "UAH", "amount": 10000, "id": "budget_id" }, "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "tender": { "procurementMethod": "open", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "id": "ac658c4ff7ab47dea27e32d15a655ddb" } } """ plan_id = generate_id() plan = self.request.validated["plan"] plan.id = plan_id plan.planID = generate_plan_id(get_now(), self.db, self.server_id) access = set_ownership(plan, self.request) self.request.validated["plan"] = plan self.request.validated["plan_src"] = {} if save_plan(self.request): LOGGER.info( "Created plan {} ({})".format(plan_id, plan.planID), extra=context_unpack(self.request, {"MESSAGE_ID": "plan_create"}, { "plan_id": plan_id, "planID": plan.planID }), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url( "Plan", plan_id=plan_id) return {"data": plan.serialize("view"), "access": access}
def collection_post(self): """This API request is targeted to creating new Plan by procuring organizations. Creating new Plan ------------------- Example request to create plan: .. sourcecode:: http POST /plans HTTP/1.1 Host: example.com Accept: application/json { "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "unit": { "code": "KGM", "name": "кг" }, "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "name": "proj_name", "id": "proj_id" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.10/plans/84582807b5654bee9e216adb05e57d39 Content-Type: application/json { "access": { "token": "174fd98e4e7347eb863f125c9e561b27" }, "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "id": "84582807b5654bee9e216adb05e57d39", "unit": { "code": "KGM", "name": "кг" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "id": "proj_id", "name": "proj_name" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } """ plan_data = self.request.validated['data'] plan_id = generate_id() plan = Plan(plan_data) plan.__parent__ = self.request.context plan.id = plan_id plan.planID = generate_plan_id(get_now(), self.db_plan, self.server_id) set_ownership(plan, self.request) self.request.validated['plan'] = plan self.request.validated['plan_src'] = {} if save_plan(self.request): LOGGER.info('Created plan {} ({})'.format(plan_id, plan.planID), extra=context_unpack(self.request, {'MESSAGE_ID': 'plan_create'}, { 'plan_id': plan_id, 'planID': plan.planID })) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Plan', plan_id=plan_id) return { 'data': plan.serialize('create'), 'access': { 'token': plan.owner_token } }
def set_ownership(item, request): item.owner_token = generate_id()
def collection_post(self): """This API request is targeted to creating new Tenders by procuring organizations. Creating new Tender ------------------- Example request to create tender: .. sourcecode:: http POST /tenders 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": "CPV", "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/tenders/64e93250be76435397e8c992ed4214d1 Content-Type: application/json { "data": { "id": "64e93250be76435397e8c992ed4214d1", "tenderID": "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": "CPV", "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" } } } """ tender_data = self.request.validated['data'] tender_id = generate_id() tender = Tender(tender_data) tender.id = tender_id tender.enquiryPeriod.startDate = get_now() tender.tenderID = generate_tender_id(tender.enquiryPeriod.startDate, self.db) if not tender.tenderPeriod.startDate: tender.tenderPeriod.startDate = tender.enquiryPeriod.endDate set_ownership(tender, self.request) self.request.validated['tender'] = tender self.request.validated['tender_src'] = {} save_tender(self.request) self.request.response.status = 201 self.request.response.headers[ 'Location'] = self.request.route_url('Tender', tender_id=tender_id) return { 'data': tender.serialize(tender.status), 'access': { 'token': tender.owner_token } }
def post(self): """This API request is targeted to creating new Plan by procuring organizations. Creating new Plan ------------------- Example request to create plan: .. sourcecode:: http POST /plans HTTP/1.1 Host: example.com Accept: application/json { "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "unit": { "code": "KGM", "name": "кг" }, "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "name": "proj_name", "id": "proj_id" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.10/plans/84582807b5654bee9e216adb05e57d39 Content-Type: application/json { "access": { "token": "e4c75de4320649a4bbbdfa180e7a9ef2" }, "data": { "items": [ { "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні" }, { "scheme": "КЕКВ", "id": "123", "description": "-" } ], "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "id": "8cd4abfd0bbb489a83a81dec1393ab8d", "unit": { "code": "KGM", "name": "кг" }, "quantity": 760 } ], "planID": "UA-2015-11-26-000001", "budget": { "amountNet": 12222, "description": "budget_description", "project": { "id": "proj_id", "name": "proj_name" }, "currency": "UAH", "amount": 10000, "id": "budget_id" }, "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "tender": { "procurementMethod": "open", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "id": "ac658c4ff7ab47dea27e32d15a655ddb" } } """ plan_id = generate_id() plan = self.request.validated["plan"] plan.id = plan_id plan.planID = generate_plan_id(get_now(), self.db, self.server_id) set_ownership(plan, self.request) self.request.validated["plan"] = plan self.request.validated["plan_src"] = {} if save_plan(self.request): LOGGER.info( "Created plan {} ({})".format(plan_id, plan.planID), extra=context_unpack( self.request, {"MESSAGE_ID": "plan_create"}, {"plan_id": plan_id, "planID": plan.planID} ), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url("Plan", plan_id=plan_id) return {"data": plan.serialize("create"), "access": {"token": plan.owner_token}}
def collection_post(self): """This API request is targeted to creating new Plan by procuring organizations. Creating new Plan ------------------- Example request to create plan: .. sourcecode:: http POST /plans HTTP/1.1 Host: example.com Accept: application/json { "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "unit": { "code": "KGM", "name": "кг" }, "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "name": "proj_name", "id": "proj_id" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.10/plans/84582807b5654bee9e216adb05e57d39 Content-Type: application/json { "access": { "token": "174fd98e4e7347eb863f125c9e561b27" }, "data": { "tender": { "procurementMethod": "допорогові закупівлі", "tenderPeriod": { "startDate": "2015-05-09T23:11:39.720908+03:00" } }, "items": [ { "classification": { "scheme": "CPV", "description": "Роботи з будування пневматичних будівель", "id": "45217000-1" }, "additionalClassifications": [ { "scheme": "ДКПП", "id": "28.29.39-10.00", "description": "Прилади контролювання маси та прилади контрольні автоматичні з максимальною масою зважування не більше ніж 5000 кг" } ], "deliveryDate": { "endDate": "2015-05-11T23:11:39.721063+03:00" }, "id": "84582807b5654bee9e216adb05e57d39", "unit": { "code": "KGM", "name": "кг" }, "quantity": 760 } ], "procuringEntity": { "identifier": { "scheme": "UA-EDR", "id": "111983", "legalName": "ДП Державне Уравління Справами" }, "name": "ДУС" }, "budget": { "project": { "id": "proj_id", "name": "proj_name" }, "amount": 10000, "amountNet": 12222, "id": "budget_id", "description": "budget_description" } } } """ plan_data = self.request.validated['data'] plan_id = generate_id() plan = Plan(plan_data) plan.__parent__ = self.request.context plan.id = plan_id plan.planID = generate_plan_id(get_now(), self.db_plan, self.server_id) set_ownership(plan, self.request) self.request.validated['plan'] = plan self.request.validated['plan_src'] = {} if save_plan(self.request): LOGGER.info('Created plan {} ({})'.format(plan_id, plan.planID), extra=context_unpack(self.request, {'MESSAGE_ID': 'plan_create'}, {'plan_id': plan_id, 'planID': plan.planID})) self.request.response.status = 201 self.request.response.headers[ 'Location'] = self.request.route_url('Plan', plan_id=plan_id) return { 'data': plan.serialize('create'), 'access': { 'token': plan.owner_token } }
def post(self): """This API request is targeted to creating new Frameworks by procuring organizations. Creating new Framework ------------------- Example request to create framework: .. sourcecode:: http POST /frameworks HTTP/1.1 Host: example.com Accept: application/json { "data": { "description": "Назва предмета закупівлі", "classification": { "scheme": "ДК021", "description": "Mustard seeds", "id": "03111600-8" }, "title": "Узагальнена назва закупівлі", "qualificationPeriod": { "endDate": "2021-02-07T14:33:22.129267+02:00" }, "additionalClassifications": [ { "scheme": "ДК003", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "procuringEntity": { "contactPoint": { "telephone": "0440000000", "email": "*****@*****.**", "name": "Назва організації(ЦЗО)" }, "identifier": { "scheme": "UA-EDR", "id": "40996564", "legalName": "Назва організації(ЦЗО)" }, "kind": "central", "name": "Повна назва юридичної організації.", "address": { "countryName": "Україна", "postalCode": "01220", "region": "м. Київ", "streetAddress": "вул. Банкова, 11, корпус 1", "locality": "м. Київ" } } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.1/frameworks/40b48e4878534db1bf228d5928f8f1d9 Content-Type: application/json { "data": { "status": "draft", "description": "Назва предмета закупівлі", "classification": { "scheme": "ДК021", "description": "Mustard seeds", "id": "03111600-8" }, "prettyID": "UA-F-2020-09-08-000001", "qualificationPeriod": { "endDate": "2021-02-07T14:33:22.129267+02:00" }, "frameworkType": "electronicCatalogue", "dateModified": "2020-09-08T01:00:00+03:00", "date": "2020-09-08T01:00:00+03:00", "additionalClassifications": [ { "scheme": "ДК003", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "procuringEntity": { "contactPoint": { "email": "*****@*****.**", "telephone": "0440000000", "name": "Назва організації(ЦЗО)" }, "identifier": { "scheme": "UA-EDR", "id": "40996564", "legalName": "Назва організації(ЦЗО)" }, "name": "Повна назва юридичної організації.", "kind": "central", "address": { "countryName": "Україна", "postalCode": "01220", "streetAddress": "вул. Банкова, 11, корпус 1", "region": "м. Київ", "locality": "м. Київ" } }, "owner": "broker", "title": "Узагальнена назва закупівлі", "id": "40b48e4878534db1bf228d5928f8f1d9" } } """ framework_id = generate_id() framework = self.request.validated["framework"] framework.id = framework_id if not framework.get("prettyID"): framework.prettyID = generate_framework_pretty_id( get_now(), self.db, self.server_id) access = set_ownership(framework, self.request) self.request.validated["framework"] = framework self.request.validated["framework_src"] = {} if save_framework(self.request): self.LOGGER.info( "Created framework {} ({})".format(framework_id, framework.prettyID), extra=context_unpack( self.request, {"MESSAGE_ID": "framework_create"}, { "framework_id": framework_id, "prettyID": framework.prettyID, "framework_mode": framework.mode }, ), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url( "{}:Framework".format(framework.frameworkType), framework_id=framework_id) return { "data": framework.serialize(framework.status), "access": access }
def post(self): """This API request is targeted to creating new Tenders by procuring organizations. Creating new Tender ------------------- Example request to create tender: .. sourcecode:: http POST /tenders 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": "CPV", "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/tenders/64e93250be76435397e8c992ed4214d1 Content-Type: application/json { "data": { "id": "64e93250be76435397e8c992ed4214d1", "tenderID": "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": "CPV", "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" } } } """ tender_id = generate_id() tender = self.request.validated['tender'] tender.id = tender_id tender.tenderID = generate_tender_id(get_now(), self.db, self.server_id) if hasattr(tender, "initialize"): tender.initialize() set_ownership(tender, self.request) self.request.validated['tender'] = tender self.request.validated['tender_src'] = {} if save_tender(self.request): self.LOGGER.info( 'Created tender {} ({})'.format(tender_id, tender.tenderID), extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_create'}, { 'tender_id': tender_id, 'tenderID': tender.tenderID })) self.request.response.status = 201 self.request.response.headers['Location'] = self.request.route_url( 'Tender', tender_id=tender_id) return { 'data': tender.serialize(tender.status), 'access': { 'token': tender.owner_token } }