def model_fields(model, only=None, exclude=None, hidden=None, field_args=None, converter=None): """ Generate a dictionary of fields for a given Django model. See `model_form` docstring for description of parameters. """ from schematics.models import Model if not isinstance(model, Model): raise TypeError('model must be a schematics.Model schema') converter = converter or ModelConverter() field_args = field_args or {} gottago = wholelist() field_dict = { } if only: gottago = whitelist(*only) elif exclude: gottago = blacklist(*exclude) for field_name, field in model._fields.items(): if gottago(field_name, None): continue ishidden = False if hidden: if field_name in hidden: ishidden=True form_field = converter.convert(model, field, field_name, field_args.get(field_name), hidden=ishidden) if form_field is not None: field_dict[field_name] = form_field from pprint import pprint #pprint(field_dict) return field_dict
def test_subclassing_overides_roles(self): class Parent(Model): id = StringType() gender = StringType() name = StringType() class Options: roles = { 'public': blacklist("id", "gender"), 'gender': blacklist("gender") } class GrandParent(Parent): age = IntType() family_secret = StringType() class Options: roles = { 'grandchildren': whitelist("age"), 'public': blacklist("id", "family_secret") } gramps = GrandParent({ "id": "1", "name": "Edward", "gender": "Male", "age": 87, "family_secret": "Secretly Canadian" }) options = gramps._options self.assertEqual(options.roles, { "grandchildren": whitelist("age"), "public": blacklist("id", "family_secret"), "gender": blacklist("gender") })
def test_subclassing_preservers_roles(self): class Parent(Model): id = StringType() name = StringType() class Options: roles = {'public': blacklist("id")} class GrandParent(Parent): age = IntType() gramps = GrandParent({ "id": "1", "name": "Edward", "age": 87 }) options = gramps._options self.assertEqual(options.roles, { "public": blacklist("id") })
from couchdb_schematics.document import SchematicsDocument from schematics.exceptions import ConversionError, ValidationError from schematics.models import Model as SchematicsModel from schematics.transforms import whitelist, blacklist, export_loop, convert from schematics.types import (StringType, FloatType, URLType, IntType, BooleanType, BaseType, EmailType, MD5Type, DecimalType as BaseDecimalType) from schematics.types.compound import (ModelType, DictType, ListType as BaseListType) from schematics.types.serializable import serializable from openprocurement.api.utils import get_now, set_parent, get_schematics_document from openprocurement.api.constants import ( CPV_CODES, ORA_CODES, TZ, DK_CODES, CPV_BLOCK_FROM, ATC_CODES, INN_CODES, ATC_INN_CLASSIFICATIONS_FROM, ) schematics_default_role = SchematicsDocument.Options.roles['default'] + blacklist("__parent__") schematics_embedded_role = SchematicsDocument.Options.roles['embedded'] + blacklist("__parent__") plain_role = (blacklist('_attachments', 'revisions', 'dateModified') + schematics_embedded_role) listing_role = whitelist('dateModified', 'doc_id') draft_role = whitelist('status') class DecimalType(BaseDecimalType): def __init__(self, precision=-3, min_value=None, max_value=None, **kwargs): super(DecimalType, self).__init__(**kwargs) self.min_value, self.max_value = min_value, max_value self.precision = Decimal("1E{:d}".format(precision)) def _apply_precision(self, value):
class Options: roles = { "public": blacklist("result") }
class Options: roles = {'create': blacklist()}
class Options: roles = {'public': blacklist('private_key')}
class Options: roles = { "public": blacklist("secret") }
Organization ) from openregistry.api.models.schematics_extender import ( Model, IsoDateTimeType, ) from openregistry.api.models.roles import ( schematics_embedded_role, schematics_default_role, plain_role, listing_role, ) from openregistry.api.interfaces import IORContent create_role = (blacklist('owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'lotID', 'status', 'doc_id') + schematics_embedded_role) edit_role = (blacklist('owner_token', 'owner', 'status', '_attachments', 'revisions', 'date', 'dateModified', 'lotID', 'mode', 'doc_id') + schematics_embedded_role) view_role = (blacklist('owner_token', '_attachments', 'revisions') + schematics_embedded_role) Administrator_role = whitelist('status', 'mode') class ILot(IORContent): """ Base lot marker interface """ def get_lot(model):
serialize_when_none = False roles = { 'embedded': schematics_embedded_role, 'view': schematics_default_role, } name = StringType(required=True) name_en = StringType() name_ru = StringType() identifier = ModelType(Identifier, required=True) additionalIdentifiers = ListType(ModelType(Identifier)) address = ModelType(Address, required=True) contactPoint = ModelType(ContactPoint, required=True) view_bid_role = (blacklist('owner_token', 'owner') + schematics_default_role) class Bid(Model): class Options: serialize_when_none = False roles = { 'embedded': view_bid_role, 'view': view_bid_role, 'auction_view': whitelist('value', 'id', 'date', 'participationUrl'), 'auction_post': whitelist('value', 'id'), 'auction_patch': whitelist('id', 'participationUrl'), 'active.enquiries': whitelist(), 'active.tendering': whitelist(), 'active.auction': whitelist('value'), 'active.qualification': view_bid_role,
Item, Award, Contract, Question, Cancellation, Feature, Lot, Complaint, ) from openprocurement.tender.core.utils import (calc_auction_end_time) from openprocurement.tender.core.constants import (CPV_ITEMS_CLASS_FROM, COMPLAINT_STAND_STILL_TIME) enquiries_role = (blacklist('owner_token', '_attachments', 'revisions', 'bids', 'numberOfBids') + schematics_embedded_role) Administrator_role = whitelist('status', 'mode', 'procuringEntity', 'auctionPeriod', 'lots') class IBelowThresholdTender(ITender): """ Marker interface for belowThreshold tenders """ @implementer(IBelowThresholdTender) class Tender(BaseTender): """Data regarding tender process - publicly inviting prospective contractors to submit bids for evaluation and selecting a winner or winners. """ class Options: roles = {
class Options: roles = { 'edit_active': schematics_default_role + blacklist("kind"), }
# -*- coding: utf-8 -*- from schematics.transforms import blacklist, whitelist from openregistry.lots.core.models import (plain_role, listing_role) from openregistry.lots.core.models import (schematics_default_role, lots_embedded_role) item_create_role = blacklist('id') item_edit_role = blacklist('id') item_view_role = (schematics_default_role + blacklist()) item_roles = { 'create': item_create_role, 'edit': item_edit_role, 'view': item_view_role, } auction_create_role = blacklist('id', 'status', 'auctionID', 'relatedProcessID', 'procurementMethodType') auction_common_edit_role = blacklist('id', 'auctionID', 'procurementMethodType', 'tenderAttempts', 'status', 'relatedProcessID') auction_view_role = (schematics_default_role + blacklist()) edit_first_english = (auction_common_edit_role + blacklist('tenderingDuration')) edit_second_english = (auction_common_edit_role + blacklist( 'value', 'minimalStep', 'guarantee', 'registrationFee', 'auctionPeriod')) edit_insider = (auction_common_edit_role + blacklist('tenderingDuration', 'value', 'minimalStep', 'guarantee', 'registrationFee', 'auctionPeriod'))
from openprocurement.tender.openua.utils import (calculate_business_date, has_unanswered_complaints) from openprocurement.tender.openua.models import ( Complaint as BaseComplaint, Award as BaseAward, Item as BaseItem, PeriodStartEndRequired, SifterListType, EnquiryPeriod, ENQUIRY_STAND_STILL_TIME, AUCTION_PERIOD_TIME, calculate_normalized_date, Tender as OpenUATender, ) ts_role = blacklist('enquiryPeriod', 'qualifications') edit_role_ts = edit_role + ts_role create_role_ts = create_role + ts_role pre_qualifications_role = ( blacklist('owner_token', '_attachments', 'revisions') + schematics_embedded_role) ts_auction_role = auction_role TENDERING_DAYS = 5 TENDERING_DURATION = timedelta(days=TENDERING_DAYS) TENDERING_AUCTION = timedelta(days=1) QUESTIONS_STAND_STILL = timedelta(days=1) PREQUALIFICATION_COMPLAINT_STAND_STILL = timedelta(seconds=0) COMPLAINT_STAND_STILL = timedelta(seconds=0) COMPLAINT_SUBMIT_TIME = timedelta(seconds=0) TENDERING_EXTRA_PERIOD = timedelta(days=3)
class Options: roles = { "edit": blacklist("id", "documents", "date", "awardID", "suppliers", "items", "contractID") }
elif auction.tenderPeriod and auction.tenderPeriod.endDate: start_after = auction.tenderPeriod.endDate else: return return rounding_shouldStartAfter(start_after, auction).isoformat() def validate_startDate(self, data, startDate): auction = get_auction(data['__parent__']) if not auction.revisions and not startDate: raise ValidationError(u'This field is required.') create_role = (blacklist( 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'auctionID', 'bids', 'documents', 'awards', 'questions', 'complaints', 'auctionUrl', 'status', 'enquiryPeriod', 'tenderPeriod', 'awardPeriod', 'procurementMethod', 'eligibilityCriteria', 'eligibilityCriteria_en', 'eligibilityCriteria_ru', 'awardCriteria', 'submissionMethod', 'cancellations', 'numberOfBidders', 'contracts') + schematics_embedded_role) @implementer(IAuction) class Auction(BaseAuction): """Data regarding auction process - publicly inviting prospective contractors to submit bids for evaluation and selecting a winner or winners.""" class Options: roles = { 'create': create_role, 'edit_active.tendering': (blacklist('enquiryPeriod', 'tenderPeriod', 'auction_value',
class Options: namespace = "Framework" _status_view_role = blacklist( "doc_type", "successful", "transfer_token", "owner_token", "revisions", "_id", "_rev", "__parent__", ) _edit_role = _status_view_role + blacklist( "frameworkType", "prettyID", "period", "enquiryPeriod", "dateModified", "date", "doc_id") _create_role = _edit_role + blacklist("status") roles = { "create": _create_role, "edit_draft": _edit_role + blacklist("owner", "old_date"), "edit_active": whitelist("status", "procuringEntity", "qualificationPeriod", "description", "description_en", "description_ru", "documents", "frameworkDetails"), "draft": _status_view_role, "active": _status_view_role, "complete": _status_view_role, "unsuccessful": _status_view_role, "view": _edit_role + whitelist( "date", "period", "enquiryPeriod", "prettyID", "documents", "doc_id", "dateModified", "status", "owner", "next_check", ), "chronograph": whitelist("next_check"), "chronograph_view": _status_view_role, "Administrator": whitelist("status", "mode"), "default": blacklist("doc_id", "__parent__"), # obj.store() use default role "plain": blacklist( # is used for getting patches "_attachments", "revisions", "dateModified", "_id", "_rev", "doc_type", "__parent__"), "listing": whitelist("dateModified", "doc_id"), "embedded": blacklist("_id", "_rev", "doc_type", "__parent__"), }
title = StringType() # Award title title_en = StringType() title_ru = StringType() description = StringType() # Award description description_en = StringType() description_ru = StringType() status = StringType(required=True, choices=['pending', 'unsuccessful', 'active', 'cancelled']) date = IsoDateTimeType(default=get_now) value = ModelType(Value) suppliers = ListType(ModelType(Organization), default=list()) items = ListType(ModelType(Item)) documents = ListType(ModelType(Document), default=list()) complaints = ListType(ModelType(Complaint), default=list()) plain_role = (blacklist('owner_token', '_attachments', 'revisions', 'dateModified') + schematics_embedded_role) view_role = (blacklist('owner_token', '_attachments', 'revisions') + schematics_embedded_role) listing_role = whitelist('dateModified', 'doc_id') auction_view_role = whitelist('tenderID', 'dateModified', 'bids', 'auctionPeriod', 'minimalStep') enquiries_role = (blacklist('owner_token', '_attachments', 'revisions', 'bids') + schematics_embedded_role) class Tender(SchematicsDocument, Model): """Data regarding tender process - publicly inviting prospective contractors to submit bids for evaluation and selecting a winner or winners.""" class Options: roles = { 'plain': plain_role, 'view': view_role, 'listing': listing_role, 'auction_view': auction_view_role, 'active.enquiries': enquiries_role,
from schematics.transforms import whitelist, blacklist, export_loop from schematics.types import BaseType, StringType, IntType, MD5Type from schematics.types.compound import ModelType, DictType, ListType from couchdb_schematics.document import SchematicsDocument from pyramid.security import Allow from zope.interface import implementer from schematics.types.serializable import serializable from openregistry.api.models.ocds import Organization, Revision, Document as BaseDocument, Location, ItemClassification, Classification, Unit, Unit, Value, Address from openregistry.api.models.schematics_extender import Model, IsoDateTimeType from openregistry.api.models.roles import schematics_embedded_role, schematics_default_role, plain_role, listing_role from openregistry.api.interfaces import IORContent create_role = ( blacklist('owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'status') + schematics_embedded_role) edit_role = (blacklist('status', 'assetType', 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'mode') + schematics_embedded_role) view_role = (blacklist('owner_token', '_attachments', 'revisions') + schematics_embedded_role) Administrator_role = whitelist('status', 'mode') bot_role = (whitelist('status')) class IAsset(IORContent): """ Base asset marker interface """
from openprocurement.api.models import Cancellation as BaseCancellation from openprocurement.api.models import ( plain_role, create_role, edit_role, view_role, listing_role, auction_view_role, auction_post_role, auction_patch_role, enquiries_role, auction_role, chronograph_role, chronograph_view_role, view_bid_role, Administrator_bid_role, Administrator_role, schematics_default_role, TZ, get_now, schematics_embedded_role, validate_lots_uniq, embedded_lot_role, default_lot_role, calc_auction_end_time, get_tender, ComplaintModelType, validate_cpv_group, validate_items_uniq, Model, ) from openprocurement.api.models import ITender from openprocurement.tender.openua.utils import ( calculate_business_date, BLOCK_COMPLAINT_STATUS, ) edit_role_ua = edit_role + blacklist('enquiryPeriod', 'status') STAND_STILL_TIME = timedelta(days=10) ENQUIRY_STAND_STILL_TIME = timedelta(days=3) CLAIM_SUBMIT_TIME = timedelta(days=10) COMPLAINT_SUBMIT_TIME = timedelta(days=4) TENDER_PERIOD = timedelta(days=15) ENQUIRY_PERIOD_TIME = timedelta(days=10) TENDERING_EXTRA_PERIOD = timedelta(days=7) def bids_validation_wrapper(validation_func): def validator(klass, data, value): if data['status'] in ('deleted', 'invalid'): # skip not valid bids
class Options: roles = { 'www': blacklist('vote_boost'), 'www-edit': blacklist('id', 'vote_boost', 'user_id'), } serialize_when_none = False
# -*- coding: utf-8 -*- from schematics.transforms import whitelist, blacklist from openregistry.assets.core.models import assets_embedded_role, listing_role, schematics_default_role plain_role = (blacklist('_attachments', 'revisions', 'dateModified', 'rectificationPeriod') + assets_embedded_role) create_role = (blacklist('owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'status', 'rectificationPeriod') + assets_embedded_role) edit_role = (blacklist('assetType', 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'mode', 'rectificationPeriod') + assets_embedded_role) view_role = (blacklist('owner_token', '_attachments', 'revisions') + assets_embedded_role) Administrator_role = whitelist('status', 'mode', 'relatedLot') concierge_role = (whitelist('status', 'relatedLot')) decision_roles = { 'create': blacklist('decisionOf', 'relatedItem'), 'edit': blacklist('decisionOf', 'relatedItem'), 'edit_draft': blacklist('decisionOf', 'relatedItem'), 'edit_pending': blacklist('decisionOf', 'relatedItem'), } asset_roles = { 'create': create_role, # draft role
return if self.startDate and get_now() > calc_auction_end_time(auction.numberOfBids, self.startDate): start_after = calc_auction_end_time(auction.numberOfBids, self.startDate) elif auction.tenderPeriod and auction.tenderPeriod.endDate: start_after = auction.tenderPeriod.endDate else: return return rounding_shouldStartAfter(start_after, auction).isoformat() def validate_startDate(self, data, startDate): auction = get_auction(data['__parent__']) if not auction.revisions and not startDate: raise ValidationError(u'This field is required.') create_role = (blacklist('owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'auctionID', 'bids', 'documents', 'awards', 'questions', 'complaints', 'auctionUrl', 'status', 'enquiryPeriod', 'tenderPeriod', 'awardPeriod', 'procurementMethod', 'eligibilityCriteria', 'eligibilityCriteria_en', 'eligibilityCriteria_ru', 'awardCriteria', 'submissionMethod', 'cancellations', 'numberOfBidders', 'contracts') + schematics_embedded_role) @implementer(IAuction) class Auction(BaseAuction): """Data regarding auction process - publicly inviting prospective contractors to submit bids for evaluation and selecting a winner or winners.""" class Options: roles = { 'create': create_role, 'edit_active.tendering': (blacklist('enquiryPeriod', 'tenderPeriod', 'auction_value', 'auction_minimalStep', 'auction_guarantee', 'eligibilityCriteria', 'eligibilityCriteria_en', 'eligibilityCriteria_ru', 'title', 'title_ru', 'title_en', 'dgfID', 'tenderAttempts', 'minNumberOfQualifiedBids') + edit_role), 'Administrator': (whitelist('value', 'minimalStep', 'guarantee') + Administrator_role), } awards = ListType(ModelType(Award), default=list()) bids = ListType(ModelType(Bid), default=list()) # A list of all the companies who entered submissions for the auction. cancellations = ListType(ModelType(Cancellation), default=list())
class Options: roles = { 'edit': whitelist(), 'edit_contract': blacklist('id', 'documents', 'date', 'awardID', 'suppliers', 'contractID'), }
Tender as BaseTenderEU, Bid as BidEU ) from openprocurement.tender.openeu.constants import ( TENDERING_DURATION as TENDERING_DURATION_EU, ) from openprocurement.tender.competitivedialogue.utils import ( validate_features_custom_weight ) from openprocurement.tender.competitivedialogue.constants import ( CD_UA_TYPE, CD_EU_TYPE, STAGE_2_EU_TYPE, STAGE_2_UA_TYPE, STAGE2_STATUS, FEATURES_MAX_SUM ) edit_role_ua = edit_role + blacklist('enquiryPeriod', 'status') edit_stage2_pending = whitelist('status') edit_stage2_waiting = whitelist('status', 'stage2TenderID') view_role_stage1 = (view_role + blacklist('auctionPeriod')) pre_qualifications_role_stage1 = (pre_qualifications_role + blacklist('auctionPeriod')) roles = { 'plain': plain_role, 'create': create_role, 'view': view_role_stage1, 'listing': listing_role, 'active.pre-qualification': pre_qualifications_role_stage1, 'active.pre-qualification.stand-still': pre_qualifications_role_stage1, 'active.stage2.pending': pre_qualifications_role_stage1, 'active.stage2.waiting': pre_qualifications_role_stage1,
return rounding_shouldStartAfter(start_after, auction).isoformat() def validate_startDate(self, data, startDate): auction = get_auction(data['__parent__']) if not auction.revisions and not startDate: raise ValidationError(u'This field is required.') class RectificationPeriod(Period): invalidationDate = IsoDateTimeType() create_role = (blacklist( 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'auctionID', 'bids', 'documents', 'awards', 'questions', 'complaints', 'auctionUrl', 'status', 'enquiryPeriod', 'tenderPeriod', 'awardPeriod', 'procurementMethod', 'eligibilityCriteria', 'eligibilityCriteria_en', 'eligibilityCriteria_ru', 'awardCriteria', 'submissionMethod', 'cancellations', 'numberOfBidders', 'contracts') + schematics_embedded_role) edit_role = (edit_role + blacklist( 'enquiryPeriod', 'tenderPeriod', 'auction_value', 'auction_minimalStep', 'auction_guarantee', 'eligibilityCriteria', 'eligibilityCriteria_en', 'eligibilityCriteria_ru', 'awardCriteriaDetails', 'awardCriteriaDetails_en', 'awardCriteriaDetails_ru', 'procurementMethodRationale', 'procurementMethodRationale_en', 'procurementMethodRationale_ru', 'submissionMethodDetails', 'submissionMethodDetails_en', 'submissionMethodDetails_ru', 'minNumberOfQualifiedBids')) Administrator_role = (Administrator_role + whitelist('awards'))
from schematics.exceptions import ConversionError, ValidationError from schematics.types.compound import (ModelType, DictType, ListType as BaseListType) from schematics.models import Model as SchematicsModel from schematics.types.serializable import serializable from couchdb_schematics.document import SchematicsDocument from openregistry.api.constants import (DEFAULT_CURRENCY, DEFAULT_ITEM_CLASSIFICATION, ITEM_CLASSIFICATIONS, TZ, DOCUMENT_TYPES, IDENTIFIER_CODES) from openregistry.api.utils import get_now, set_parent schematics_default_role = SchematicsDocument.Options.roles[ 'default'] + blacklist("__parent__") schematics_embedded_role = SchematicsDocument.Options.roles[ 'embedded'] + blacklist("__parent__") plain_role = (blacklist('_attachments', 'revisions', 'dateModified') + schematics_embedded_role) listing_role = whitelist('dateModified', 'doc_id') draft_role = whitelist('status') class IsoDateTimeType(BaseType): MESSAGES = { 'parse': u'Could not parse {0}. Should be ISO8601.', } def to_native(self, value, context=None):
u"currency of bid should be identical to currency of value of lot" ) if lot.get('value' ).valueAddedTaxIncluded != value.valueAddedTaxIncluded: raise ValidationError( u"valueAddedTaxIncluded of bid should be identical to valueAddedTaxIncluded of value of lot" ) def validate_relatedLot(self, data, relatedLot): if isinstance(data['__parent__'], Model) and relatedLot not in [ i.id for i in get_auction(data['__parent__']).lots ]: raise ValidationError(u"relatedLot should be one of lots") view_bid_role = (blacklist('owner_token') + schematics_default_role) Administrator_bid_role = whitelist('tenderers') class Bid(Bid): class Options: roles = { 'embedded': view_bid_role, 'view': view_bid_role, 'auction_view': whitelist('value', 'lotValues', 'id', 'date', 'parameters', 'participationUrl', 'owner'), 'active.qualification': view_bid_role,
) from openprocurement.schemas.dgf.schemas_store import SchemaStore from schematics_flexible.schematics_flexible import FlexibleModelType from openregistry.assets.core.constants import ASSET_STATUSES, ALLOWED_SCHEMA_PROPERIES_CODES, SANDBOX_MODE assets_embedded_role = sensitive_embedded_role create_role = (blacklist( 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'status', 'sandboxParameters', ) + assets_embedded_role) edit_role = (blacklist('assetType', 'owner_token', 'owner', '_attachments', 'revisions', 'date', 'dateModified', 'doc_id', 'assetID', 'documents', 'mode') + assets_embedded_role) view_role = (blacklist('owner_token', '_attachments', 'revisions') + assets_embedded_role) Administrator_role = whitelist('status', 'mode', 'relatedLot') concierge_role = (whitelist('status', 'relatedLot'))
class Options: roles = { "public": blacklist("title") }
class Options: # this means that value won't appear in the JSON output by default roles = {'default': blacklist('value')}
class Options: roles = { "public": blacklist("id") }
class Options: roles = { "embedded": schematics_embedded_role, "view": schematics_default_role, "edit_active.tendering": schematics_default_role + blacklist("kind"), }
class Options: roles = { "default": blacklist("result") }
TENDER_PERIOD as TENDERING_DURATION_UA, ) from openprocurement.tender.openeu.models import ( Administrator_bid_role, view_bid_role, pre_qualifications_role, ConfidentialDocument, auction_patch_role, auction_view_role, auction_post_role, embedded_lot_role, default_lot_role, Lot as BaseLotEU, Item as BaseEUItem, LotValue as BaseLotValueEU, Tender as BaseTenderEU, Bid as BidEU) from openprocurement.tender.openeu.constants import ( TENDERING_DURATION as TENDERING_DURATION_EU, ) from openprocurement.tender.competitivedialogue.utils import ( validate_features_custom_weight) from openprocurement.tender.competitivedialogue.constants import ( CD_UA_TYPE, CD_EU_TYPE, STAGE_2_EU_TYPE, STAGE_2_UA_TYPE, STAGE2_STATUS, FEATURES_MAX_SUM) edit_role_ua = edit_role + blacklist('enquiryPeriod', 'status') edit_stage2_pending = whitelist('status') edit_stage2_waiting = whitelist('status', 'stage2TenderID') view_role_stage1 = (view_role + blacklist('auctionPeriod')) pre_qualifications_role_stage1 = (pre_qualifications_role + blacklist('auctionPeriod')) roles = { 'plain': plain_role, 'create': create_role, 'view': view_role_stage1, 'listing': listing_role, 'active.pre-qualification': pre_qualifications_role_stage1, 'active.pre-qualification.stand-still': pre_qualifications_role_stage1, 'active.stage2.pending': (enquiries_role + blacklist('auctionPeriod')), 'active.stage2.waiting': pre_qualifications_role_stage1,
from openprocurement.api.models import Lot as BaseLot from openprocurement.api.models import ListType from openprocurement.api.models import ( plain_role, create_role, edit_role, cancel_role, view_role, listing_role, auction_view_role, auction_post_role, auction_patch_role, enquiries_role, auction_role, chronograph_role, chronograph_view_role, view_bid_role, Administrator_bid_role, Administrator_role, schematics_default_role, TZ, get_now, schematics_embedded_role, validate_lots_uniq ) from openprocurement.tender.openua.interfaces import ITenderUA from schematics.exceptions import ValidationError from openprocurement.tender.openua.utils import calculate_business_date from schematics.types.serializable import serializable from openprocurement.api.models import embedded_lot_role, default_lot_role edit_role_ua = edit_role + blacklist('enquiryPeriod') STAND_STILL_TIME = timedelta(days=10) COMPLAINT_STAND_STILL_TIME = timedelta(days=3) CLAIM_SUBMIT_TIME = timedelta(days=10) COMPLAINT_SUBMIT_TIME = timedelta(days=4) TENDER_PERIOD = timedelta(days=15) ENQUIRY_PERIOD_TIME = timedelta(days=3) def bids_validation_wrapper(validation_func): def validator(klass, data, value): if data['status'] in ('deleted', 'invalid'): # skip not valid bids return
class Options: roles = { 'create': whitelist('relatedLot', 'subcontractingDetails'), 'edit': whitelist('relatedLot', 'subcontractingDetails'), 'view': (schematics_default_role + blacklist('value')), }
serialize_when_none = False roles = { 'embedded': schematics_embedded_role, 'view': schematics_default_role, } name = StringType(required=True) name_en = StringType() name_ru = StringType() identifier = ModelType(Identifier, required=True) additionalIdentifiers = ListType(ModelType(Identifier)) address = ModelType(Address, required=True) contactPoint = ModelType(ContactPoint, required=True) view_bid_role = (blacklist('owner_token', 'owner') + schematics_default_role) class Bid(Model): class Options: serialize_when_none = False roles = { 'embedded': view_bid_role, 'view': view_bid_role, 'create': whitelist('value', 'tenderers'), 'edit': whitelist('value', 'tenderers'), 'auction_view': whitelist('value', 'id', 'date', 'participationUrl'), 'auction_post': whitelist('value', 'id', 'date'), 'auction_patch': whitelist('id', 'participationUrl'), 'active.enquiries': whitelist(), 'active.tendering': whitelist(),
class Options: roles = { 'edit': blacklist('signingPeriod'), 'create': blacklist('signingPeriod', 'datePaid'), 'Administrator': whitelist('signingPeriod', 'datePaid'), }
auction_role, chronograph_role, chronograph_view_role, view_bid_role, Administrator_bid_role, Administrator_role, schematics_default_role, schematics_embedded_role, get_now, embedded_lot_role, default_lot_role, calc_auction_end_time, get_tender, validate_lots_uniq, validate_cpv_group, validate_items_uniq, ) from openprocurement.tender.openua.utils import ( calculate_business_date, BLOCK_COMPLAINT_STATUS, ) from openprocurement.tender.openua.models import ( Complaint as BaseComplaint, Award as BaseAward, Item as BaseItem, PeriodStartEndRequired, SifterListType, COMPLAINT_SUBMIT_TIME, EnquiryPeriod, ENQUIRY_STAND_STILL_TIME, AUCTION_PERIOD_TIME, ) cd_role = blacklist('enquiryPeriod', 'qualifications') edit_role_cd = edit_role + cd_role create_role_cd = create_role + cd_role pre_qualifications_role = (blacklist('owner_token', '_attachments', 'revisions') + schematics_embedded_role) cd_auction_role = auction_role TENDERING_DAYS = 30 TENDERING_DURATION = timedelta(days=TENDERING_DAYS) TENDERING_AUCTION = timedelta(days=35) QUESTIONS_STAND_STILL = timedelta(days=10) PREQUALIFICATION_COMPLAINT_STAND_STILL = timedelta(days=5) COMPLAINT_STAND_STILL = timedelta(days=10) def bids_validation_wrapper(validation_func): def validator(klass, data, value):
class Options: roles = { 'create': blacklist('id', 'dateCreated', 'status',), 'edit': blacklist('id', 'dateCreated',), }
) from openprocurement.api.models.roles import ( # noqa: F401 schematics_embedded_role, # noqa forwarded import schematics_default_role, plain_role, listing_role) from openprocurement.api.models.schematics_extender import ( # noqa: F401 Model, # noqa forwarded import IsoDateTimeType, IsoDurationType, # noqa forwarded import DecimalType # noqa forwarded import ) from .constants import LOT_STATUSES lots_embedded_role = sensitive_embedded_role create_role = ( blacklist('owner', '_attachments', 'revisions', 'date', 'dateModified', 'lotID', 'documents', 'status', 'doc_id') + lots_embedded_role) edit_role = ( blacklist('owner', '_attachments', 'revisions', 'date', 'dateModified', 'documents', 'lotID', 'mode', 'doc_id') + lots_embedded_role) view_role = (blacklist('_attachments', 'revisions') + lots_embedded_role) Administrator_role = whitelist('status', 'mode') class ILot(IORContent): """ Base lot marker interface """ def get_lot(model): while not ILot.providedBy(model): model = model.__parent__
while root.__parent__ is not None: root = root.__parent__ request = root.request role = 'edit' if request.authenticated_role == 'tender_owner': role = 'edit_contract' if request.context.status == 'pending.signed': role = 'edit_pending.signed' return role Unit = BaseUnit Value = BaseValue award_edit_role = blacklist('id', 'items', 'date', 'documents', 'complaints', 'complaintPeriod') award_create_role = blacklist('id', 'status', 'items', 'date', 'documents', 'complaints', 'complaintPeriod') award_create_reporting_role = award_create_role + blacklist('qualified') award_edit_reporting_role = award_edit_role + blacklist('qualified') class Award(BaseAward): """ An award for the given procurement. There may be more than one award per contracting process e.g. because the contract is split amongst different providers, or because it is a standing offer. """ class Options: roles = { 'create': award_create_reporting_role, 'edit': award_edit_reporting_role, 'embedded': schematics_embedded_role,
class PlanOrganization(Model): """An organization.""" name = StringType(required=True) name_en = StringType() name_ru = StringType() identifier = ModelType(Identifier, required=True) class PlanTender(Model): procurementMethod = StringType(choices=['open'], default='open', required=True) tenderPeriod = ModelType(Period, required=True) plain_role = (blacklist('revisions', 'dateModified') + schematics_embedded_role) create_role = (blacklist('owner_token', 'owner', 'revisions') + schematics_embedded_role) edit_role = (blacklist('owner_token', 'owner', 'revisions', 'dateModified', 'doc_id', 'planID') + schematics_embedded_role) cancel_role = whitelist('status') view_role = (blacklist('owner', 'owner_token', '_attachments', 'revisions') + schematics_embedded_role) listing_role = whitelist('dateModified', 'doc_id') Administrator_role = whitelist('status', 'mode', 'procuringEntity') class Plan(SchematicsDocument, Model): """Plan""" class Options: roles = { 'plain': plain_role, 'create': create_role,
class Complaint(BaseComplaint): class Options: roles = { 'active': view_bid_role, } class Contract(BaseContract): items = ListType(ModelType(Item)) def validate_dateSigned(self, data, value): if value and value > get_now(): raise ValidationError(u"Contract signature date can't be in the future") award_edit_role = blacklist('id', 'date', 'documents', 'complaints', 'complaintPeriod') award_create_role = blacklist('id', 'status', 'date', 'documents', 'complaints', 'complaintPeriod') award_create_reporting_role = award_create_role + blacklist('qualified') award_edit_reporting_role = award_edit_role + blacklist('qualified') class Award(Model): """ An award for the given procurement. There may be more than one award per contracting process e.g. because the contract is split amongst different providers, or because it is a standing offer. """ class Options: roles = { 'create': award_create_reporting_role, 'edit': award_edit_reporting_role, 'embedded': schematics_embedded_role,