コード例 #1
0
ファイル: test_types.py プロジェクト: Afey/schematics
def test_boolean_to_native():
    bool_field = BooleanType()

    for true_value in ['True', '1', 1, True]:
        assert bool_field.to_native(true_value)

    for false_value in ['False', '0', 0, False]:
        assert not bool_field.to_native(false_value)

    for bad_value in ['TrUe', 'foo', 2, None, 1.0]:
        with pytest.raises(ConversionError):
            bool_field.to_native(bad_value)
コード例 #2
0
ファイル: __init__.py プロジェクト: fbidanjiri/stacker
class Stack(Model):
    name = StringType(required=True)

    stack_name = StringType(serialize_when_none=False)

    region = StringType(serialize_when_none=False)

    profile = StringType(serialize_when_none=False)

    class_path = StringType(serialize_when_none=False)

    template_path = StringType(serialize_when_none=False)

    description = StringType(serialize_when_none=False)

    requires = ListType(StringType, serialize_when_none=False)

    required_by = ListType(StringType, serialize_when_none=False)

    locked = BooleanType(default=False)

    enabled = BooleanType(default=True)

    protected = BooleanType(default=False)

    variables = DictType(AnyType, serialize_when_none=False)

    parameters = DictType(AnyType, serialize_when_none=False)

    tags = DictType(StringType, serialize_when_none=False)

    stack_policy_path = StringType(serialize_when_none=False)

    in_progress_behavior = StringType(serialize_when_none=False)

    def validate_class_path(self, data, value):
        if value and data["template_path"]:
            raise ValidationError("template_path cannot be present when "
                                  "class_path is provided.")
        self.validate_stack_source(data)

    def validate_template_path(self, data, value):
        if value and data["class_path"]:
            raise ValidationError("class_path cannot be present when "
                                  "template_path is provided.")
        self.validate_stack_source(data)

    def validate_stack_source(self, data):
        # Locked stacks don't actually need a template, since they're
        # read-only.
        if data["locked"]:
            return

        if not (data["class_path"] or data["template_path"]):
            raise ValidationError("class_path or template_path is required.")

    def validate_parameters(self, data, value):
        if value:
            stack_name = data['name']
            raise ValidationError(
                "DEPRECATION: Stack definition %s contains "
                "deprecated 'parameters', rather than 'variables'. You are"
                " required to update your config. See https://stacker.rea"
                "dthedocs.io/en/latest/config.html#variables for "
                "additional information." % stack_name)
        return value
コード例 #3
0
class ZMessage(Model):
    author_id = IntType(required=True)
    created_at = DateTimeType(formats='%Y-%m-%dT%H:%M:%SZ', required=True)
    uploads = ListType(StringType, default=list)  # list of upload tokens
    public = BooleanType(required=True)
コード例 #4
0
class CFASelectionUATender(BaseTender):
    """Data regarding tender process - publicly inviting prospective contractors
    to submit bids for evaluation and selecting a winner or winners.
    """
    class Options:
        namespace = "Tender"
        _core_roles = BaseTender.Options.roles
        _not_implemented = whitelist("mainProcurementCategory", "milestones")
        _base_edit = (_core_roles["edit"] - _not_implemented + whitelist(
            "procuringEntity",
            "numberOfBidders",
            "serializable_guarantee",
            "items",
            "next_check",
            "tender_guarantee",
            "numberOfBids",
            "agreements",
            "hasEnquiries",
        ))
        _edit_role = _base_edit + whitelist(
            "enquiryPeriod", "tender_minimalStep", "contracts", "tenderPeriod",
            "features", "serializable_minimalStep")
        _draft_view_role = (_core_roles["view"] - _not_implemented + whitelist(
            "tender_guarantee",
            "awardPeriod",
            "auctionUrl",
            "auctionPeriod",
            "next_check",
            "procuringEntity",
            "questions",
            "complaints",
            "lots",
            "items",
            "cancellations",
            "contracts",
            "agreements",
            "numberOfBidders",
            "awards",
            "serializable_guarantee",
            "hasEnquiries",
        ))
        _view_tendering_role = _draft_view_role + whitelist(
            "tender_value",
            "tenderPeriod",
            "features",
            "enquiryPeriod",
            "tender_minimalStep",
            "serializable_value",
            "serializable_minimalStep",
        )
        _view_role = _view_tendering_role + whitelist("bids", "numberOfBids")
        _procurement_method_details = whitelist("procurementMethodDetails")
        roles = {
            "create":
            _base_edit + whitelist("lots", "procurementMethodType", "mode"),
            "edit_draft":
            _core_roles["edit_draft"] + _procurement_method_details,
            "edit_draft.pending":
            whitelist("agreements", "unsuccessfulReason") +
            _procurement_method_details,
            "edit_cancelled":
            _procurement_method_details,
            "edit_complete":
            _procurement_method_details,
            "edit_unsuccessful":
            _procurement_method_details,
            "edit_active.awarded":
            _procurement_method_details,
            "edit_active.auction":
            _procurement_method_details,
            "edit_active.tendering":
            _procurement_method_details,
            "edit_active.qualification":
            _procurement_method_details,
            "edit_active.enquiries":
            whitelist(
                "description",
                "description_en",
                "description_ru",
                "documents",
                "items",
                "lots",
                "procurementMethodDetails",
                "serializable_guarantee",
                "tenderPeriod",
                "tender_guarantee",
                "title",
                "title_en",
                "title_ru",
            ),
            "edit":
            _edit_role,
            "edit_agreement_selection":
            whitelist("agreements", "procurementMethodDetails", "status"),
            "active.tendering":
            _view_tendering_role,
            "active.enquiries":
            _view_tendering_role,
            "active.auction":
            _view_tendering_role,
            "draft":
            _draft_view_role,
            "draft.pending":
            _draft_view_role + whitelist("features"),
            "draft.unsuccessful":
            _draft_view_role + whitelist("features", "unsuccessfulReason"),
            "active.awarded":
            _view_role,
            "unsuccessful":
            _view_role,
            "cancelled":
            _view_role,
            "view":
            _view_role,
            "active.qualification":
            _view_role,
            "complete":
            _view_role,
            "chronograph":
            _core_roles["chronograph"] + _procurement_method_details,
            "chronograph_view":
            _core_roles["chronograph_view"] + whitelist("agreements") +
            _procurement_method_details,
            "Administrator":
            _core_roles["Administrator"] + _procurement_method_details,
            "contracting":
            _core_roles["contracting"] + _procurement_method_details,
            "auction_post":
            _core_roles["auction_post"] + _procurement_method_details,
            "auction_patch":
            _core_roles["auction_patch"] + _procurement_method_details,
            "auction_view":
            _core_roles["auction_view"] - whitelist("minimalStep") +
            whitelist("serializable_minimalStep") +
            _procurement_method_details,
            "listing":
            _core_roles["listing"] + _procurement_method_details,
            "embedded":
            _core_roles["embedded"],
            "plain":
            _core_roles["plain"],
            "default":
            _core_roles["default"],
        }

    items = ListType(
        ModelType(Item, required=True),
        min_size=1,
        validators=[validate_items_uniq]
    )  # The goods and services to be purchased, broken into line items wherever possible. Items should not be duplicated, but a quantity of 2 specified instead.
    value = ModelType(Value)  # The total estimated value of the procurement.
    enquiryPeriod = ModelType(
        PeriodEndRequired, required=False
    )  # The period during which enquiries may be made and will be answered.
    tenderPeriod = ModelType(
        PeriodEndRequired, required=False
    )  # The period when the tender is open for submissions. The end date is the closing date for tender submissions.
    hasEnquiries = BooleanType(
    )  # A Yes/No field as to whether enquiries were part of tender process.
    awardPeriod = ModelType(
        Period
    )  # The date or period on which an award is anticipated to be made.
    numberOfBidders = IntType(
    )  # The number of unique tenderers who participated in the tender
    bids = ListType(ModelType(Bid, required=True), default=list(
    ))  # A list of all the companies who entered submissions for the tender.
    procuringEntity = ModelType(
        ProcuringEntity, required=True
    )  # The entity managing the procurement, which may be different from the buyer who is paying / using the items being procured.
    awards = ListType(ModelType(Award, required=True), default=list())
    contracts = ListType(ModelType(Contract, required=True), default=list())
    auctionPeriod = ModelType(TenderAuctionPeriod, default={})
    minimalStep = ModelType(Value, required=False)
    auctionUrl = URLType()
    cancellations = ListType(ModelType(Cancellation, required=True),
                             default=list())
    features = ListType(ModelType(Feature, required=True),
                        validators=[validate_features_uniq])
    lots = ListType(ModelType(Lot, required=True),
                    default=list(),
                    validators=[validate_lots_uniq],
                    min_size=1,
                    max_size=1)
    guarantee = ModelType(Guarantee)
    status = StringType(
        choices=[
            "draft",
            "draft.pending",
            "draft.unsuccessful",
            "active.enquiries",
            "active.tendering",
            "active.auction",
            "active.qualification",
            "active.awarded",
            "complete",
            "cancelled",
            "unsuccessful",
        ],
        default="draft",
    )  # TODO Refactoring status
    agreements = ListType(ModelType(Agreement, required=True),
                          default=list(),
                          min_size=1,
                          max_size=1)

    procurementMethod = StringType(choices=["open", "selective", "limited"],
                                   default="selective")
    procurementMethodType = StringType(
        default="closeFrameworkAgreementSelectionUA")
    unsuccessfulReason = ListType(StringType, serialize_when_none=False)
    procuring_entity_kinds = [
        "general", "special", "defense", "central", "other"
    ]

    def get_role(self):
        root = self.__parent__
        request = root.request
        if request.authenticated_role == "Administrator":
            role = "Administrator"
        elif request.authenticated_role == "chronograph":
            role = "chronograph"
        elif request.authenticated_role == "auction":
            role = "auction_{}".format(request.method.lower())
        elif request.authenticated_role == "contracting":
            role = "contracting"
        elif request.authenticated_role == "agreement_selection":
            role = "edit_{}".format(request.authenticated_role)
        else:
            role = "edit_{}".format(request.context.status)
        return role

    def __acl__(self):
        acl = [(Allow, "{}_{}".format(i.owner,
                                      i.owner_token), "create_award_complaint")
               for i in self.bids]
        acl.extend([
            (Allow, "{}_{}".format(self.owner,
                                   self.owner_token), "edit_tender"),
            (Allow, "{}_{}".format(self.owner, self.owner_token),
             "upload_tender_documents"),
            (Allow, "{}_{}".format(self.owner,
                                   self.owner_token), "edit_complaint"),
            (Allow, "g:agreement_selection", "edit_agreement_selection"),
            (Allow, "g:agreement_selection", "edit_tender"),
        ])
        return acl

    def __local_roles__(self):
        roles = dict([("{}_{}".format(self.owner,
                                      self.owner_token), "tender_owner")])
        for i in self.bids:
            roles["{}_{}".format(i.owner, i.owner_token)] = "bid_owner"
        return roles

    # Non-required mainProcurementCategory
    def validate_mainProcurementCategory(self, data, value):
        pass

    # Not required milestones
    def validate_milestones(self, data, value):
        pass
コード例 #5
0
class Bid(BaseBid):
    class Options:
        roles = {
            'Administrator':
            Administrator_bid_role,
            'embedded':
            view_bid_role,
            'view':
            view_bid_role,
            'create':
            whitelist('value', 'tenderers', 'parameters', 'lotValues',
                      'selfQualified', 'selfEligible',
                      'subcontractingDetails'),
            'edit':
            whitelist('value', 'tenderers', 'parameters', 'lotValues',
                      'status', 'subcontractingDetails'),
            'auction_view':
            whitelist('value', 'lotValues', 'id', 'date', 'parameters',
                      'participationUrl', 'status'),
            'auction_post':
            whitelist('value', 'lotValues', 'id', 'date'),
            'auction_patch':
            whitelist('id', 'lotValues', 'participationUrl'),
            'active.enquiries':
            whitelist(),
            'active.tendering':
            whitelist(),
            'active.pre-qualification':
            whitelist('id', 'status', 'documents'),
            'active.pre-qualification.stand-still':
            whitelist('id', 'status', 'documents'),
            'active.auction':
            whitelist('id', 'status', 'documents'),
            'active.qualification':
            view_bid_role,
            'active.awarded':
            view_bid_role,
            'complete':
            view_bid_role,
            'unsuccessful':
            view_bid_role,
            'cancelled':
            view_bid_role,
            'invalid':
            whitelist('id', 'status', 'documents'),
            'deleted':
            whitelist('id', 'status'),
        }

    documents = ListType(ModelType(ConfidentialDocument), default=list())
    financialDocuments = ListType(ModelType(ConfidentialDocument),
                                  default=list())
    eligibilityDocuments = ListType(ModelType(ConfidentialDocument),
                                    default=list())
    qualificationDocuments = ListType(ModelType(ConfidentialDocument),
                                      default=list())
    lotValues = ListType(ModelType(LotValue), default=list())
    selfQualified = BooleanType(required=True, choices=[True])
    selfEligible = BooleanType(required=True, choices=[True])
    subcontractingDetails = StringType()
    status = StringType(
        choices=['pending', 'active', 'invalid', 'unsuccessful', 'deleted'],
        default='pending')

    def serialize(self, role=None):
        if role and role != 'create' and self.status in ['invalid', 'deleted']:
            role = self.status
        return super(Bid, self).serialize(role)

    @serializable(serialized_name="status")
    def serialize_status(self):
        if self.__parent__.status in ['active.tendering', 'cancelled']:
            return self.status
        if self.__parent__.lots:
            if not self.lotValues:
                return 'invalid'
            elif [
                    i.relatedLot for i in self.lotValues
                    if i.status == 'pending'
            ]:
                return 'pending'
            elif [
                    i.relatedLot for i in self.lotValues
                    if i.status == 'active'
            ]:
                return 'active'
            else:
                return 'unsuccessful'
        return self.status

    @bids_validation_wrapper
    def validate_value(self, data, value):
        BaseBid._validator_functions['value'](self, data, value)

    @bids_validation_wrapper
    def validate_lotValues(self, data, lotValues):
        BaseBid._validator_functions['lotValues'](self, data, lotValues)

    @bids_validation_wrapper
    def validate_participationUrl(self, data, participationUrl):
        BaseBid._validator_functions['participationUrl'](self, data,
                                                         participationUrl)

    @bids_validation_wrapper
    def validate_parameters(self, data, parameters):
        BaseBid._validator_functions['parameters'](self, data, parameters)
コード例 #6
0
ファイル: models.py プロジェクト: OSIRISanalytics/API
class ClearedOrderSummaryReport(BetfairModel):
    cleared_orders = ListType(ModelType(ClearedOrderSummary), required=True)
    more_available = BooleanType(required=True)
コード例 #7
0
ファイル: models.py プロジェクト: OSIRISanalytics/API
class AccountStatementReport(BetfairModel):
    account_statement = ListType(ModelType(StatementItem))
    more_available = BooleanType()
コード例 #8
0
ファイル: models.py プロジェクト: OSIRISanalytics/API
class PriceProjection(BetfairModel):
    price_data = ListType(EnumType(constants.PriceData))
    ex_best_offers_overrides = ModelType(ExBestOffersOverrides)
    virtualise = BooleanType()
    rollover_stakes = BooleanType()
コード例 #9
0
class Tender(BaseTender):
    """ ESCO Tender model """
    class Options:
        roles = {
            'plain':
            plain_role,
            'create':
            create_role_eu +
            blacklist('minValue', 'tender_minValue', 'minimalStep',
                      'tender_minimalStep', 'noticePublicationDate',
                      'tender_noticePublicationDate'),
            'edit':
            edit_role_eu +
            blacklist('minValue', 'tender_minValue', 'minimalStep',
                      'tender_minimalStep', 'noticePublicationDate',
                      'tender_noticePublicationDate'),
            'edit_draft':
            edit_role_eu +
            blacklist('minValue', 'tender_minValue', 'minimalStep',
                      'tender_minimalStep', 'noticePublicationDate',
                      'tender_noticePublicationDate'),
            'edit_active.tendering':
            edit_role_eu +
            blacklist('minValue', 'tender_minValue', 'minimalStep',
                      'tender_minimalStep', 'noticePublicationDate',
                      'tender_noticePublicationDate'),
            'edit_active.pre-qualification':
            whitelist('status'),
            'edit_active.pre-qualification.stand-still':
            whitelist(),
            'edit_active.auction':
            whitelist(),
            'edit_active.qualification':
            whitelist(),
            'edit_active.awarded':
            whitelist(),
            'edit_complete':
            whitelist(),
            'edit_unsuccessful':
            whitelist(),
            'edit_cancelled':
            whitelist(),
            'view':
            view_role,
            'listing':
            listing_role,
            'auction_view':
            auction_view_role +
            whitelist('NBUdiscountRate', 'minimalStepPercentage',
                      'yearlyPaymentsPercentageRange', 'fundingKind',
                      'procurementMethodType', 'noticePublicationDate'),
            'auction_post':
            auction_post_role,
            'auction_patch':
            auction_patch_role,
            'draft':
            enquiries_role,
            'active.tendering':
            enquiries_role,
            'active.pre-qualification':
            pre_qualifications_role,
            'active.pre-qualification.stand-still':
            pre_qualifications_role,
            'active.auction':
            pre_qualifications_role,
            'active.qualification':
            view_role,
            'active.awarded':
            view_role,
            'complete':
            view_role,
            'unsuccessful':
            view_role,
            'cancelled':
            view_role,
            'chronograph':
            chronograph_role,
            'chronograph_view':
            chronograph_view_role,
            'Administrator':
            Administrator_role,
            'default':
            schematics_default_role,
            'contracting':
            whitelist('doc_id', 'owner'),
        }

    procurementMethodType = StringType(default="esco")
    title_en = StringType(required=True, min_length=1)

    items = ListType(
        ModelType(Item),
        required=True,
        min_size=1,
        validators=[validate_cpv_group, validate_items_uniq]
    )  # The goods and services to be purchased, broken into line items wherever possible. Items should not be duplicated, but a quantity of 2 specified instead.
    minValue = ModelType(Value,
                         required=False,
                         default={
                             'amount': 0,
                             'currency': 'UAH',
                             'valueAddedTaxIncluded': True
                         })  # The total estimated value of the procurement.

    enquiryPeriod = ModelType(EnquiryPeriod, required=False)
    tenderPeriod = ModelType(PeriodStartEndRequired, required=True)
    auctionPeriod = ModelType(TenderAuctionPeriod, default={})
    hasEnquiries = BooleanType(
    )  # A Yes/No field as to whether enquiries were part of tender process.
    awardCriteria = StringType(default='ratedCriteria')
    awardPeriod = ModelType(
        Period
    )  # The date or period on which an award is anticipated to be made.
    numberOfBidders = IntType(
    )  # The number of unique tenderers who participated in the tender
    bids = SifterListType(
        BidModelType(Bid),
        default=list(),
        filter_by='status',
        filter_in_values=['invalid', 'invalid.pre-qualification', 'deleted']
    )  # A list of all the companies who entered submissions for the tender.
    procuringEntity = ModelType(
        ProcuringEntity, required=True
    )  # The entity managing the procurement, which may be different from the buyer who is paying / using the items being procured.
    awards = ListType(ModelType(Award), default=list())
    contracts = ListType(ModelType(Contract), default=list())
    minimalStep = ModelType(
        Value, required=False
    )  # Not required, blocked for create/edit, since we have minimalStepPercentage in esco
    minimalStepPercentage = DecimalType(required=True,
                                        min_value=Decimal('0.005'),
                                        max_value=Decimal('0.03'))
    questions = ListType(ModelType(Question), default=list())
    complaints = ListType(ComplaintModelType(Complaint), default=list())
    auctionUrl = URLType()
    cancellations = ListType(ModelType(Cancellation), default=list())
    features = ListType(ModelType(Feature),
                        validators=[validate_features_uniq])
    lots = ListType(ModelType(Lot),
                    default=list(),
                    validators=[validate_lots_uniq])
    guarantee = ModelType(Guarantee)
    documents = ListType(
        ModelType(Document),
        default=list())  # All documents and attachments related to the tender.
    qualifications = ListType(ModelType(Qualification), default=list())
    qualificationPeriod = ModelType(Period)
    status = StringType(choices=[
        'draft', 'active.tendering', 'active.pre-qualification',
        'active.pre-qualification.stand-still', 'active.auction',
        'active.qualification', 'active.awarded', 'complete', 'cancelled',
        'unsuccessful'
    ],
                        default='active.tendering')
    NBUdiscountRate = DecimalType(required=True,
                                  min_value=Decimal('0'),
                                  max_value=Decimal('0.99'),
                                  precision=-5)
    fundingKind = StringType(choices=['budget', 'other'],
                             required=True,
                             default='other')
    yearlyPaymentsPercentageRange = DecimalType(required=True,
                                                default=Decimal('0.8'),
                                                min_value=Decimal('0'),
                                                max_value=Decimal('1'))
    submissionMethodDetails = StringType(
        default="quick(mode:no-auction)"
    )  # TODO: temporary decision, while esco auction is not ready. Remove after adding auction. Remove function "check_submission_method_details" in openprocurement.tender.esco.subscribers
    noticePublicationDate = IsoDateTimeType()

    create_accreditation = 3
    edit_accreditation = 4
    special_fields = ['fundingKind', 'yearlyPaymentsPercentageRange']
    procuring_entity_kinds = ['general', 'special', 'defense']
    block_tender_complaint_status = OpenUATender.block_tender_complaint_status
    block_complaint_status = OpenUATender.block_complaint_status

    def import_data(self, raw_data, **kw):
        """
        Converts and imports the raw data into the instance of the model
        according to the fields in the model.
        :param raw_data:
            The data to be imported.
        """
        data = self.convert(raw_data, **kw)
        del_keys = [
            k for k in data.keys()
            if data[k] == self.__class__.fields[k].default
            or data[k] == getattr(self, k)
        ]
        for k in del_keys:
            if k in self.special_fields:
                # skip special fields :)
                continue
            del data[k]
        self._data.update(data)
        return self

    def __local_roles__(self):
        roles = dict([('{}_{}'.format(self.owner,
                                      self.owner_token), 'tender_owner')])
        for i in self.bids:
            roles['{}_{}'.format(i.owner, i.owner_token)] = 'bid_owner'
        return roles

    def __acl__(self):
        acl = [(Allow, '{}_{}'.format(i.owner, i.owner_token),
                'create_qualification_complaint') for i in self.bids
               if i.status in ['active', 'unsuccessful']]
        acl.extend([(Allow, '{}_{}'.format(i.owner, i.owner_token),
                     'create_award_complaint') for i in self.bids
                    if i.status == 'active'])
        acl.extend([
            (Allow, '{}_{}'.format(self.owner,
                                   self.owner_token), 'edit_tender'),
            (Allow, '{}_{}'.format(self.owner, self.owner_token),
             'upload_tender_documents'),
            (Allow, '{}_{}'.format(self.owner,
                                   self.owner_token), 'edit_complaint'),
        ])
        return acl

    @serializable(serialized_name="enquiryPeriod",
                  type=ModelType(EnquiryPeriod))
    def tender_enquiryPeriod(self):
        endDate = calculate_business_date(self.tenderPeriod.endDate,
                                          -QUESTIONS_STAND_STILL, self)
        return EnquiryPeriod(
            dict(startDate=self.tenderPeriod.startDate,
                 endDate=endDate,
                 invalidationDate=self.enquiryPeriod
                 and self.enquiryPeriod.invalidationDate,
                 clarificationsUntil=calculate_business_date(
                     endDate, ENQUIRY_STAND_STILL_TIME, self, True)))

    @serializable(type=ModelType(Period))
    def complaintPeriod(self):
        normalized_end = calculate_normalized_date(self.tenderPeriod.endDate,
                                                   self)
        return Period(
            dict(startDate=self.tenderPeriod.startDate,
                 endDate=calculate_business_date(normalized_end,
                                                 -COMPLAINT_SUBMIT_TIME,
                                                 self)))

    @serializable(serialize_when_none=False)
    def next_check(self):
        now = get_now()
        checks = []
        if self.status == 'active.tendering' and self.tenderPeriod.endDate and \
                not has_unanswered_complaints(self) and not has_unanswered_questions(self):
            checks.append(self.tenderPeriod.endDate.astimezone(TZ))
        elif self.status == 'active.pre-qualification.stand-still' and self.qualificationPeriod and self.qualificationPeriod.endDate:
            active_lots = [
                lot.id for lot in self.lots if lot.status == 'active'
            ] if self.lots else [None]
            if not any([
                    i.status in self.block_complaint_status
                    for q in self.qualifications
                    for i in q.complaints if q.lotID in active_lots
            ]):
                checks.append(self.qualificationPeriod.endDate.astimezone(TZ))
        elif not self.lots and self.status == 'active.auction' and self.auctionPeriod and self.auctionPeriod.startDate and not self.auctionPeriod.endDate:
            if now < self.auctionPeriod.startDate:
                checks.append(self.auctionPeriod.startDate.astimezone(TZ))
            elif now < calc_auction_end_time(
                    self.numberOfBids,
                    self.auctionPeriod.startDate).astimezone(TZ):
                checks.append(
                    calc_auction_end_time(
                        self.numberOfBids,
                        self.auctionPeriod.startDate).astimezone(TZ))
        elif self.lots and self.status == 'active.auction':
            for lot in self.lots:
                if lot.status != 'active' or not lot.auctionPeriod or not lot.auctionPeriod.startDate or lot.auctionPeriod.endDate:
                    continue
                if now < lot.auctionPeriod.startDate:
                    checks.append(lot.auctionPeriod.startDate.astimezone(TZ))
                elif now < calc_auction_end_time(
                        lot.numberOfBids,
                        lot.auctionPeriod.startDate).astimezone(TZ):
                    checks.append(
                        calc_auction_end_time(
                            lot.numberOfBids,
                            lot.auctionPeriod.startDate).astimezone(TZ))
        elif not self.lots and self.status == 'active.awarded' and not any(
            [i.status in self.block_complaint_status
             for i in self.complaints]) and not any([
                 i.status in self.block_complaint_status for a in self.awards
                 for i in a.complaints
             ]):
            standStillEnds = [
                a.complaintPeriod.endDate.astimezone(TZ) for a in self.awards
                if a.complaintPeriod.endDate
            ]
            last_award_status = self.awards[-1].status if self.awards else ''
            if standStillEnds and last_award_status == 'unsuccessful':
                checks.append(max(standStillEnds))
        elif self.lots and self.status in [
                'active.qualification', 'active.awarded'
        ] and not any([
                i.status in self.block_complaint_status
                and i.relatedLot is None for i in self.complaints
        ]):
            for lot in self.lots:
                if lot['status'] != 'active':
                    continue
                lot_awards = [i for i in self.awards if i.lotID == lot.id]
                pending_complaints = any([
                    i['status'] in self.block_complaint_status
                    and i.relatedLot == lot.id for i in self.complaints
                ])
                pending_awards_complaints = any([
                    i.status in self.block_complaint_status for a in lot_awards
                    for i in a.complaints
                ])
                standStillEnds = [
                    a.complaintPeriod.endDate.astimezone(TZ)
                    for a in lot_awards if a.complaintPeriod.endDate
                ]
                last_award_status = lot_awards[-1].status if lot_awards else ''
                if not pending_complaints and not pending_awards_complaints and standStillEnds and last_award_status == 'unsuccessful':
                    checks.append(max(standStillEnds))
        if self.status.startswith('active'):
            for award in self.awards:
                if award.status == 'active' and not any(
                    [i.awardID == award.id for i in self.contracts]):
                    checks.append(award.date)
        return min(checks).isoformat() if checks else None

    @serializable
    def numberOfBids(self):
        """A property that is serialized by schematics exports."""
        return len([
            bid for bid in self.bids if bid.status in (
                "active",
                "pending",
            )
        ])

    @serializable(serialized_name="minValue", type=ModelType(Value))
    def tender_minValue(self):
        return Value(
            dict(amount=sum([i.minValue.amount for i in self.lots]),
                 currency=self.minValue.currency,
                 valueAddedTaxIncluded=self.minValue.valueAddedTaxIncluded)
        ) if self.lots else self.minValue

    @serializable(serialized_name="guarantee",
                  serialize_when_none=False,
                  type=ModelType(Guarantee))
    def tender_guarantee(self):
        if self.lots:
            lots_amount = [
                i.guarantee.amount for i in self.lots if i.guarantee
            ]
            if not lots_amount:
                return self.guarantee
            guarantee = {'amount': sum(lots_amount)}
            lots_currency = [
                i.guarantee.currency for i in self.lots if i.guarantee
            ]
            guarantee['currency'] = lots_currency[0] if lots_currency else None
            if self.guarantee:
                guarantee['currency'] = self.guarantee.currency
            return Guarantee(guarantee)
        else:
            return self.guarantee

    @serializable(serialized_name="minimalStep",
                  type=ModelType(Value),
                  serialize_when_none=False)
    def tender_minimalStep(self):
        pass
        # return Value(dict(amount=min([i.minimalStep.amount for i in self.lots]),
        #                   currency=self.minimalStep.currency,
        #                   valueAddedTaxIncluded=self.minimalStep.valueAddedTaxIncluded)) if self.lots else self.minimalStep

    @serializable(serialized_name="minimalStepPercentage")
    def tender_minimalStepPercentage(self):
        return min([i.minimalStepPercentage for i in self.lots
                    ]) if self.lots else self.minimalStepPercentage

    @serializable(serialized_name="yearlyPaymentsPercentageRange")
    def tender_yearlyPaymentsPercentageRange(self):
        return min([i.yearlyPaymentsPercentageRange for i in self.lots
                    ]) if self.lots else self.yearlyPaymentsPercentageRange

    @serializable(serialized_name="noticePublicationDate",
                  serialize_when_none=False,
                  type=IsoDateTimeType())
    def tender_noticePublicationDate(self):
        if not self.noticePublicationDate and self.status == 'active.tendering':
            return self.__parent__.request.now
        else:
            return self.noticePublicationDate

    def validate_items(self, data, items):
        cpv_336_group = items[
            0].classification.id[:3] == '336' if items else False
        if not cpv_336_group and (
                data.get('revisions')[0].date if data.get('revisions') else
                get_now()) > CPV_ITEMS_CLASS_FROM and items and len(
                    set([i.classification.id[:4] for i in items])) != 1:
            raise ValidationError(u"CPV class of items should be identical")
        else:
            validate_cpv_group(items)

    def validate_features(self, data, features):
        if features and data['lots'] and any([
                round(
                    vnmax([
                        i for i in features if i.featureOf == 'tenderer'
                        or i.featureOf == 'lot' and i.relatedItem == lot['id']
                        or i.featureOf == 'item' and i.relatedItem in [
                            j.id
                            for j in data['items'] if j.relatedLot == lot['id']
                        ]
                    ]), 15) > 0.25 for lot in data['lots']
        ]):
            raise ValidationError(
                u"Sum of max value of all features for lot should be less then or equal to 25%"
            )
        elif features and not data['lots'] and round(vnmax(features),
                                                     15) > 0.25:
            raise ValidationError(
                u"Sum of max value of all features should be less then or equal to 25%"
            )

    def validate_auctionUrl(self, data, url):
        if url and data['lots']:
            raise ValidationError(u"url should be posted for each lot")

    def validate_minimalStep(self, data, value):
        pass

    #     if value and value.amount and data.get('minValue'):
    #         if data.get('minValue').currency != value.currency:
    #             raise ValidationError(u"currency should be identical to currency of minValue of tender")
    #         if data.get('minValue').valueAddedTaxIncluded != value.valueAddedTaxIncluded:
    #             raise ValidationError(u"valueAddedTaxIncluded should be identical to valueAddedTaxIncluded of minValue of tender")

    def validate_tenderPeriod(self, data, period):
        # if data['_rev'] is None when tender was created just now
        if not data['_rev'] and calculate_business_date(
                get_now(), -timedelta(minutes=10)) >= period.startDate:
            raise ValidationError(
                u"tenderPeriod.startDate should be in greater than current date"
            )
        if period and calculate_business_date(
                period.startDate, TENDERING_DURATION, data) > period.endDate:
            raise ValidationError(
                u"tenderPeriod should be greater than {} days".format(
                    TENDERING_DAYS))

    def validate_awardPeriod(self, data, period):
        if period and period.startDate and data.get(
                'auctionPeriod') and data.get(
                    'auctionPeriod').endDate and period.startDate < data.get(
                        'auctionPeriod').endDate:
            raise ValidationError(u"period should begin after auctionPeriod")
        if period and period.startDate and data.get(
                'tenderPeriod') and data.get(
                    'tenderPeriod').endDate and period.startDate < data.get(
                        'tenderPeriod').endDate:
            raise ValidationError(u"period should begin after tenderPeriod")

    def validate_lots(self, data, value):
        if len(set([lot.guarantee.currency
                    for lot in value if lot.guarantee])) > 1:
            raise ValidationError(
                u"lot guarantee currency should be identical to tender guarantee currency"
            )
        if len(set([lot.fundingKind for lot in value])) > 1:
            raise ValidationError(
                u"lot funding kind should be identical to tender funding kind")

    def validate_yearlyPaymentsPercentageRange(self, data, value):
        if data['fundingKind'] == 'other' and value != Decimal('0.8'):
            raise ValidationError(
                'when fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'
            )
        if data['fundingKind'] == 'budget' and (value > Decimal('0.8')
                                                or value < Decimal('0')):
            raise ValidationError(
                'when fundingKind is budget, yearlyPaymentsPercentageRange should be less or equal 0.8, and more or equal 0'
            )

    def check_auction_time(self):
        if self.auctionPeriod and self.auctionPeriod.startDate and self.auctionPeriod.shouldStartAfter \
                and self.auctionPeriod.startDate > calculate_business_date(parse_date(self.auctionPeriod.shouldStartAfter), AUCTION_PERIOD_TIME, self, True):
            self.auctionPeriod.startDate = None
        for lot in self.lots:
            if lot.auctionPeriod and lot.auctionPeriod.startDate and lot.auctionPeriod.shouldStartAfter \
                    and lot.auctionPeriod.startDate > calculate_business_date(parse_date(lot.auctionPeriod.shouldStartAfter), AUCTION_PERIOD_TIME, self, True):
                lot.auctionPeriod.startDate = None

    def invalidate_bids_data(self):
        self.check_auction_time()
        self.enquiryPeriod.invalidationDate = get_now()
        for bid in self.bids:
            if bid.status not in ["deleted", "draft"]:
                bid.status = "invalid"
コード例 #10
0
class OriginShield(Model):
    enabled = BooleanType(deserialize_from="Enabled")
    origin_shield_region = StringType(deserialize_from="OriginShieldRegion",
                                      serialize_when_none=False)
コード例 #11
0
class DistributionData(Model):
    id = StringType(deserialize_from="Id")
    arn = StringType(deserialize_from="ARN")
    status = StringType(deserialize_from="Status")
    last_modified_time = DateTimeType(deserialize_from="LastModifiedTime")
    domain_name = StringType(deserialize_from="DomainName",
                             serialize_when_none=False)
    aliases = ModelType(Alias,
                        deserialize_from="Aliases",
                        serialize_when_none=False)
    origins = ModelType(Origins,
                        deserialize_from="Origins",
                        serialize_when_none=False)
    origin_groups = ModelType(OriginGroups,
                              deserialize_from="OriginGroups",
                              serialize_when_none=False)
    default_cache_behavior = ModelType(DefaultCacheBehavior,
                                       deserialize_from="DefaultCacheBehavior",
                                       serialize_when_none=False)
    cache_behavior = ModelType(CacheBehaviors,
                               deserialize_from="CacheBehaviors",
                               serialize_when_none=False)
    custom_error_responses = ModelType(CustomErrorResponses,
                                       deserialize_from="CustomErrorResponses",
                                       serialize_when_none=False)
    comment = StringType(deserialize_from="Comment", serialize_when_none=False)
    price_class = StringType(deserialize_from="PriceClass",
                             choices=("PriceClass_100", "PriceClass_200",
                                      "PriceClass_All"))
    enabled = BooleanType(deserialize_from="Enabled",
                          serialize_when_none=False)
    state_display = StringType(choices=('Enabled', 'Disabled'))
    viewer_certificate = ModelType(ViewerCertificate,
                                   deserialize_from="ViewerCertificate",
                                   serialize_when_none=False)
    restrictions = ModelType(Restrictions,
                             deserialize_from="Restrictions",
                             serialize_when_none=False)
    web_acl_id = StringType(deserialize_from="WebACLId",
                            serialize_when_none=False)
    http_version = StringType(deserialize_from="HttpVersion",
                              choices=("http1.1", "http2"))
    is_ipv6_enabled = BooleanType(deserialize_from="IsIPV6Enabled",
                                  serialize_when_none=False)
    alias_icp_recordals = ListType(ModelType(AliasICPRecordals),
                                   deserialize_from="AliasICPRecordals",
                                   serialize_when_none=False)
    account_id = StringType()
    tags = ListType(ModelType(Tags), default=[])
    cloudwatch = ModelType(CloudWatchModel, serialize_when_none=False)

    def reference(self):
        return {
            "resource_id":
            self.arn,
            "external_link":
            f"https://console.aws.amazon.com/cloudfront/home?#distribution-settings:{self.id}"
        }

    def set_cloudwatch(self, region_code='us-east-1'):
        return {
            "namespace":
            "AWS/CloudFront",
            "dimensions": [
                CloudWatchDimensionModel({
                    'Name': 'DistributionId',
                    'Value': self.id
                })
            ],
            "region_name":
            region_code
        }
コード例 #12
0
class TrustedKeyGroups(Model):
    enabled = BooleanType(deserialize_from="Enabled")
    quantity = IntType(deserialize_from="Quantity", serialize_when_none=False)
    items = ListType(StringType,
                     deserialize_from="Items",
                     serialize_when_none=False)