def stage2_bid_post(self):
    tender = self.request.validated['tender']
    bid = self.request.validated['bid']
    # TODO can't move validator because of self.allowed_bid_status_on_create
    if bid.status not in self.allowed_bid_status_on_create:
        raise_operation_error(
            self.request, 'Bid can be added only with status: {}.'.format(
                self.allowed_bid_status_on_create))
    tender.modified = False
    api_set_ownership(bid, self.request)
    tender.bids.append(bid)
    if save_tender(self.request):
        self.LOGGER.info('Created tender bid {}'.format(bid.id),
                         extra=context_unpack(
                             self.request, {'MESSAGE_ID': 'tender_bid_create'},
                             {'bid_id': bid.id}))
        self.request.response.status = 201
        self.request.response.headers['Location'] = self.request.route_url(
            '{}:Tender Bids'.format(tender.procurementMethodType),
            tender_id=tender.id,
            bid_id=bid['id'])
        return {
            'data': bid.serialize('view'),
            'access': {
                'token': bid.owner_token
            }
        }
Beispiel #2
0
def stage2_bid_post(self):
    tender = self.request.validated['tender']
    if self.request.validated['tender_status'] != 'active.tendering':
        self.request.errors.add(
            'body', 'data',
            'Can\'t add bid in current ({}) tender status'.format(
                self.request.validated['tender_status']))
        self.request.errors.status = 403
        return
    if tender.tenderPeriod.startDate and \
            get_now() < tender.tenderPeriod.startDate or \
            get_now() > tender.tenderPeriod.endDate:
        self.request.errors.add(
            'body', 'data',
            'Bid can be added only during the tendering period: from ({}) to ({}).'
            .format(tender.tenderPeriod.startDate,
                    tender.tenderPeriod.endDate))
        self.request.errors.status = 403
        return
    bid = self.request.validated['bid']
    firm_keys = prepare_shortlistedFirms(tender.shortlistedFirms)
    bid_keys = prepare_bid_identifier(bid)
    if not (bid_keys <= firm_keys):
        self.request.errors.add('body', 'data', 'Firm can\'t create bid')
        self.request.errors.status = 403
        return
    if bid.status not in self.allowed_bid_status_on_create:
        self.request.errors.add(
            'body', 'data', 'Bid can be added only with status: {}.'.format(
                self.allowed_bid_status_on_create))
        self.request.errors.status = 403
        return
    tender.modified = False
    api_set_ownership(bid, self.request)
    tender.bids.append(bid)
    if save_tender(self.request):
        self.LOGGER.info('Created tender bid {}'.format(bid.id),
                         extra=context_unpack(
                             self.request, {'MESSAGE_ID': 'tender_bid_create'},
                             {'bid_id': bid.id}))
        self.request.response.status = 201
        self.request.response.headers['Location'] = self.request.route_url(
            'Tender Bids', tender_id=tender.id, bid_id=bid['id'])
        return {
            'data': bid.serialize('view'),
            'access': {
                'token': bid.owner_token
            }
        }
def stage2_bid_post(self):
    tender = self.request.validated['tender']
    bid = self.request.validated['bid']
    # TODO can't move validator because of self.allowed_bid_status_on_create
    if bid.status not in self.allowed_bid_status_on_create:
        raise_operation_error(self.request, 'Bid can be added only with status: {}.'.format(self.allowed_bid_status_on_create))
    tender.modified = False
    api_set_ownership(bid, self.request)
    tender.bids.append(bid)
    if save_tender(self.request):
        self.LOGGER.info('Created tender bid {}'.format(bid.id),
                         extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_bid_create'},
                                              {'bid_id': bid.id}))
        self.request.response.status = 201
        self.request.response.headers['Location'] = self.request.route_url('{}:Tender Bids'.format(tender.procurementMethodType), tender_id=tender.id,
                                                                           bid_id=bid['id'])
        return {
            'data': bid.serialize('view'),
            'access': {
                'token': bid.owner_token
            }
        }
Beispiel #4
0
def stage2_bid_post(self):
    tender = self.request.validated["tender"]
    bid = self.request.validated["bid"]
    # TODO can't move validator because of self.allowed_bid_status_on_create
    if bid.status not in self.allowed_bid_status_on_create:
        raise_operation_error(
            self.request, "Bid can be added only with status: {}.".format(self.allowed_bid_status_on_create)
        )
    tender.modified = False
    access = api_set_ownership(bid, self.request)
    tender.bids.append(bid)
    if save_tender(self.request):
        self.LOGGER.info(
            "Created tender bid {}".format(bid.id),
            extra=context_unpack(self.request, {"MESSAGE_ID": "tender_bid_create"}, {"bid_id": bid.id}),
        )
        self.request.response.status = 201
        self.request.response.headers["Location"] = self.request.route_url(
            "{}:Tender Bids".format(tender.procurementMethodType), tender_id=tender.id, bid_id=bid["id"]
        )
        return {"data": bid.serialize("view"), "access": access}