class FieldModel(Model): type = StringType(required=True) merge = BoolIntType() x = DecimalType() y = DecimalType() width = StringType() height = StringType() page = StringType() signer = StringType() name = StringType() identifier = StringType() required = BoolIntType() readonly = BoolIntType() validation_type = StringType() text_style = StringType() text_font = StringType() text_size = IntType() text_color = StringType() value = StringType() options = ListType(StringType) group = StringType() class Options: serialize_when_none = False
class Manifest(Model): """ The manifest description. """ job_mode = StringType( required=True, choices=["batch", "online", "instant_delivery"]) job_api_key = UUIDType(default=uuid.uuid4) job_id = UUIDType(default=uuid.uuid4) job_total_tasks = IntType() requester_restricted_answer_set = DictType(DictType(StringType)) requester_description = StringType() requester_max_repeats = IntType() requester_min_repeats = IntType() requester_question = DictType(StringType) requester_question_example = URLType() unsafe_content = BooleanType(default=False) task_bid_price = DecimalType(required=True) oracle_stake = DecimalType(required=True) expiration_date = IntType() requester_accuracy_target = FloatType(default=.1) manifest_smart_bounty_addr = StringType() minimum_trust_server = FloatType(default=.1) minimum_trust_client = FloatType(default=.1) recording_oracle_addr = StringType(required=True) reputation_oracle_addr = StringType(required=True) reputation_agent_addr = StringType(required=True) requester_pgp_public_key = StringType() # Future TODO: replace with KV lookup on recording_oracle_addr # NOTE: URLType fails without TLD (examples: http://localhost/, # http://exchange/, etc), so using StringType instead. ro_uri = StringType() repo_uri = StringType() batch_result_delivery_webhook = URLType() online_result_delivery_webhook = URLType() instant_result_delivery_webhook = URLType() request_type = StringType( required=True, choices=[ "image_label_binary", "image_label_multiple_choice_one_option", "image_label_multiple_choice_multiple_options", "text_free_entry", "text_multiple_choice_one_option", "text_multiple_choice_multiple_options" ]) # if taskdata is directly provided taskdata = ListType(ModelType(TaskData)) # ListType(DictType(StringType)) # if taskdata is separately stored taskdata_uri = URLType() def validate_taskdata_uri(self, data, value): if data.get('taskdata') and len( data.get('taskdata')) > 0 and data.get('taskdata_uri'): raise ValidationError( u'Specify only one of taskdata {} or taskdata_uri {}'.format( data.get('taskdata'), data.get('taskdata_uri'))) return value validate_taskdata = validate_taskdata_uri
class Client(Model): _id = StringType(default=generate_uuid()) name = StringType(required=True, min_length=1, max_length=80) cpf = StringType(required=True, min_length=11, max_length=11) birthdate = DateType(required=True) amount = DecimalType(required=True, validators=[is_between]) terms = IntType(required=True, validators=[is_inside]) income = DecimalType(required=True)
class OperationData(PModel): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() asset_code = StringType() asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType(serialized_name='from') to_address = StringType(serialized_name='to') amount = DecimalType()
class OperationData(Model): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() # TODO: enums? asset_code = StringType() # TODO: min, max length? asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType() to_address = StringType() amount = DecimalType()
class Fact(Entity): @log_exceptions def __init__(self, name, store=Redis()): super().__init__(Constants.FACTS_COLLECTION, name, store) activated = BooleanType(default=False) confidence = DecimalType(default=Constants.DEFAULT_CONFIDENCE)
class _UserTemplateModel(Model): name = StringType(required=True, serialized_name='Name') object_label = StringType(serialized_name='Object label', default='{ItemNumber:04}') thumbnail_width_pixels = DecimalType( default=InselectDocument.THUMBNAIL_DEFAULT_WIDTH, min_value=InselectDocument.THUMBNAIL_MIN_WIDTH, max_value=InselectDocument.THUMBNAIL_MAX_WIDTH, serialized_name='Thumbnail width pixels') cropped_file_suffix = StringType(default='.jpg', choices=IMAGE_SUFFIXES, serialized_name='Cropped file suffix') fields = ListType(ModelType(_FieldModel), serialized_name='Fields', validators=[ _validate_fields_not_empty, _validate_field_names_unique, _validate_field_labels_unique ]) def __repr__(self): return "_UserTemplateModel ['{0}']".format(self.name) def __str__(self): return repr(self)
class Loan(Model): _id = StringType(required=True) status = StringType(default=ProcessingStatus.processing.value) result = StringType() refused_policy = StringType() amount = DecimalType(min_value=1000, max_value=4000, validators=[is_between]) terms = IntType(min_value=6, max_value=12, validators=[is_inside])
class BidModel(Model): bidder = ModelType(BidderModel, serialized_name="Bidder", required=True) project = ModelType(ProjectModel, serialized_name="Project", required=True) cost_build = DecimalType(required=True, serialized_name="Bid Price", min_value=0.01) cost_shipping = DecimalType(required=True, serialized_name="Shipping Cost", min_value=0.00) timestamp = DateTimeType(serialized_name="Date of Bid", required=True) note_bidder = StringType(serialized_name="Note from Bidder") comments = ListType(ModelType(CommentModel), serialized_name="Comments about Bid")
class Stage(Model): """ Represents a stage in a pipeline. E.g.: open deals, lost deals, etc. """ id = IntType(required=False) name = StringType(required=True) pipeline_id = PipedriveModelType(Pipeline, required=True) deal_probability = DecimalType(required=False) rotten_flag = IntType(required=False, choices=(0, 1)) rotten_days = IntType(required=False) order_nr = IntType(required=False, min_value=0)
class Arguments(Entity): txtBldgName = StringType(required=True) txtBldgAddress = StringType(required=True) cmbBldgType = StringType(required=True) cmbBldgLocation = StringType(required=True) txtBldgNumFloor = IntType(required=True) txtBldgCondArea = IntType(required=True) cmbBldgShape = StringType(required=True) txtBldgAzi = IntType(required=True) txtFloorHeight = IntType(required=True) txtLengX1 = IntType(required=True) txtLengY1 = IntType(required=True) txtLengX2 = IntType(required=True) txtLengY2 = IntType(required=True) txtLengX3 = IntType(required=True) txtLengY3 = IntType(required=True) txtFloorArea = IntType(required=True) cmbSouthWall = StringType(required=True) cmbNorthWall = StringType(required=True) cmbEastWall = StringType(required=True) cmbWestWall = StringType(required=True) cmbRoof = StringType(required=True) cmbFirstFloorContact = StringType(required=True) txtWinSouthOverhang = DecimalType(required=True) txtWinSouthFp = DecimalType(required=True) cmbHotWaterSystem = StringType(required=True) cmbBldgSystem = StringType(required=True) txtHeatSetTemp = IntType(required=True) txtCoolSetTemp = IntType(required=True) rdbtnWinWwr = BooleanType(default=True) southpercent = IntType(required=True) northpercent = IntType(required=True) eastpercent = IntType(required=True) westpercent = IntType(required=True) glasstype = StringType(required=True) txtSkyltType = StringType(required=True) txtSkyltCvr = IntType(required=True) eir = IntType(required=True) class Options: serialize_when_none = False
class TransactionData(Model): class OperationData(Model): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() # TODO: enums? asset_code = StringType() # TODO: min, max length? asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType() to_address = StringType() amount = DecimalType() hash = StringType() # TODO: min, max length? created_at = UTCDateTimeType() source_account = StringType() # TODO: min, max length? source_account_sequence = StringType() operations = ListType(ModelType(OperationData), default=[]) memo_type = StringType() memo = StringType() fee_paid = DecimalType() signatures = ListType(StringType, default=[]) # id # paging_token # envelope_xdr # time_bounds # ledger # _links # result_xdr # result_meta_xdr # operation_count # fee_meta_xdr # TODO: do it properly def __str__(self): sb = [] for key in self.__dict__: if not key.startswith('__'): sb.append("\t{key}='{value}'".format(key=key, value=self.__dict__[key])) return '\n'.join(sb) def __repr__(self): return self.__str__()
class Deal(Model): """ The model for the Pipedrive deals. """ title = StringType(required=True) id = IntType(required=False) value = DecimalType(required=False) currency = StringType(required=False) user_id = PipedriveModelType(User, required=False) # person_id = PipedriveModelType(Person, required=False) org_id = PipedriveModelType(Organization, required=False) stage_id = PipedriveModelType(Stage, required=False) status = StringType(required=False, choices=('open', 'won', 'lost', 'deleted')) lost_reson = StringType(required=False) add_time = PipedriveDateTime(required=False) visible_to = ListType(IntType)
class TransactionData(PModel): id = StringType() hash = StringType() created_at = UTCDateTimeType() source_account = StringType() source_account_sequence = StringType() operations = ListType(ModelType(OperationData), default=[]) operation_count = IntType() ledger = StringType() memo_type = StringType() memo = StringType() fee_paid = DecimalType() signatures = ListType(StringType, default=[]) paging_token = StringType() envelope_xdr = StringType() result_xdr = StringType() result_meta_xdr = StringType() fee_meta_xdr = StringType() time_bounds = ListType(IntType, default=[])
class CuppingModel(Model): id = IntType() session_id = IntType() name = StringType(max_length=128, min_length=1, required=True) scores = ScoresType(DecimalType, required=True) overall_score = DecimalType(required=True, min_value=0, max_value=100, serialized_name='overallScore') descriptors = ListType(StringType) defects = ListType(StringType) notes = StringType() is_sample = BooleanType(default=False, serialized_name='isSample') @staticmethod def from_row(cupping): attrs = { k: v for k, v in cupping.__dict__.items() if not k.startswith('_') } return CuppingModel(attrs, strict=False)
class DecimalSerializer(object): SERIALIZER = DecimalType() def can_handle(self, cls): return issubclass(cls, Decimal) @staticmethod def to_json_schema(cls): return {"type": "number"} def load(self, cls, obj): try: return self.SERIALIZER.to_native(obj) except BaseError as e: raise SerializationException(str(e)) def dump(self, cls, obj): try: return self.SERIALIZER.to_primitive(obj) except BaseError as e: raise SerializationException(str(e))
class PlayerItem(Model): id = IntType(required=True) total_stats = IntType() hits = StringType() comments = StringType() # TODO: create separate class for player_pages spider as the player_page is not available for the player_detail # spider, causing problems in the stats logger. player_page = URLType(required=True) name = StringType() full_name = StringType() age = IntType() dob = DateTimeType(default=datetime.datetime.now) height = IntType() weight = IntType() nationality = StringType() preferred_foot = StringType() international_reputation = IntType() weak_foot = IntType() skill_moves = IntType() work_rate = StringType() body_type = StringType() real_face = StringType() value = DecimalType() wage = DecimalType() release_clause = DecimalType() club_name = StringType() club_rating = IntType() club_position = StringType() club_jersey_number = IntType() club_join_date = DateTimeType(default=datetime.datetime.now) loaned_from = StringType() club_contract_end_date = DateTimeType(default=datetime.datetime.now) team_name = StringType() team_rating = IntType() team_position = StringType() team_jersey_number = IntType() overall_rating = IntType() potential_rating = IntType() positions = ListType(StringType) unique_attributes = ListType(StringType) DIV = IntType() HAN = IntType() KIC = IntType() REF = IntType() SPD = IntType() POS = IntType() PAC = IntType() SHO = IntType() PAS = IntType() DRI = IntType() DEF = IntType() PHY = IntType() vision = IntType() penalties = IntType() crossing = IntType() finishing = IntType() heading_accuracy = IntType() short_passing = IntType() volleys = IntType() aggression = IntType() interceptions = IntType() positioning = IntType() composure = IntType() dribbling = IntType() curve = IntType() fk_accuracy = IntType() long_passing = IntType() ball_control = IntType() marking = IntType() standing_tackle = IntType() sliding_tackle = IntType() acceleration = IntType() sprint_speed = IntType() agility = IntType() reactions = IntType() balance = IntType() gk_diving = IntType() gk_handling = IntType() gk_kicking = IntType() gk_positioning = IntType() gk_reflexes = IntType() shot_power = IntType() jumping = IntType() stamina = IntType() strength = IntType() long_shots = IntType() traits = ListType(StringType) LS = ListType(IntType) ST = ListType(IntType) RS = ListType(IntType) LW = ListType(IntType) LF = ListType(IntType) CF = ListType(IntType) RF = ListType(IntType) RW = ListType(IntType) LAM = ListType(IntType) CAM = ListType(IntType) RAM = ListType(IntType) LM = ListType(IntType) LCM = ListType(IntType) CM = ListType(IntType) RCM = ListType(IntType) RM = ListType(IntType) LWB = ListType(IntType) LDM = ListType(IntType) CDM = ListType(IntType) RDM = ListType(IntType) RWB = ListType(IntType) LB = ListType(IntType) LCB = ListType(IntType) CB = ListType(IntType) RCB = ListType(IntType) RB = ListType(IntType) followers = IntType() likes = IntType() dislikes = IntType() face_img = URLType() flag_img = URLType() club_logo_img = URLType() team_logo_img = URLType()
class ClubItem(Model): id = IntType(required=True) nationality = StringType() region = StringType() num_players = IntType() hits = StringType() comments = StringType() club_page = URLType(required=True) club_name = StringType() division = StringType() club_logo = URLType() flag = URLType() overall = IntType() attack = IntType() midfield = IntType() defence = IntType() home_stadium = StringType() rival_team = StringType() international_prestige = IntType() domestic_prestige = IntType() transfer_budget = DecimalType() starting_xi_average_age = DecimalType() whole_team_average_age = DecimalType() captain = IntType() short_free_kick = IntType() long_free_kick = IntType() left_short_free_kick = IntType() right_short_free_kick = IntType() penalties = IntType() left_corner = IntType() right_corner = IntType() starting_xi = ListType(IntType) defence_defensive_style = StringType() defence_depth = IntType() offense_offensive_style = StringType() offense_width = IntType() offense_players_in_box = IntType() offense_corners = IntType() offense_free_kicks = IntType() build_up_play_speed = IntType() build_up_play_dribbling = IntType() build_up_play_passing = IntType() build_up_play_positioning = IntType() chance_creation_passing = IntType() chance_creation_crossing = IntType() chance_creation_shooting = IntType() chance_creation_positioning = IntType() defence_extra_pressure = IntType() defence_extra_aggression = IntType() defence_extra_team_width = IntType() defence_extra_defender_line = StringType() squad = ListType(IntType) on_loan = ListType(IntType) kits = ListType(URLType) likes = IntType() dislikes = IntType()
class SentTransaction(Model): amount = DecimalType(required=True) receiver = StringType(required=True)
class ReceivedTransaction(Model): amount = DecimalType(required=True) sender = StringType(required=True)
class AddItemCommand(Command): seller_id = StringType(required=True) title = StringType(required=True) description = StringType() starting_price = DecimalType() end_date = DateTimeType()
class BankAccount(Model): """An Account in A Bank""" account_id = LongType(required=True, min_value=0) amount = DecimalType()
class Manifest(Model): """ The manifest description. """ job_mode = StringType(required=True, choices=["batch", "online", "instant_delivery"]) job_api_key = UUIDType(default=uuid.uuid4) job_id = UUIDType(default=uuid.uuid4) job_total_tasks = IntType(required=True) requester_restricted_answer_set = DictType(DictType(StringType)) def validate_requester_restricted_answer_set(self, data, value): """image_label_area_select should always have a single RAS set""" # validation runs before other params, so need to handle missing case if not data.get('request_type'): raise ValidationError("request_type missing") if data['request_type'] == 'image_label_area_select': if not value or len(value.keys()) == 0: value = {'label': {}} data['requester_restricted_answer_set'] = value return value requester_description = StringType() requester_max_repeats = IntType(default=100) requester_min_repeats = IntType(default=1) requester_question = DictType(StringType) requester_question_example = UnionType((URLType, ListType), field=URLType) def validate_requester_question_example(self, data, value): # validation runs before other params, so need to handle missing case if not data.get('request_type'): raise ValidationError("request_type missing") # based on https://github.com/hCaptcha/hmt-basemodels/issues/27#issuecomment-590706643 supports_lists = ['image_label_area_select', 'image_label_binary'] if isinstance(value, list) and not data['request_type'] in supports_lists: raise ValidationError( "Lists are not allowed in this challenge type") return value unsafe_content = BooleanType(default=False) task_bid_price = DecimalType(required=True) oracle_stake = DecimalType(required=True) expiration_date = IntType() requester_accuracy_target = FloatType(default=.1) manifest_smart_bounty_addr = StringType() hmtoken_addr = StringType() minimum_trust_server = FloatType(default=.1) minimum_trust_client = FloatType(default=.1) recording_oracle_addr = StringType(required=True) reputation_oracle_addr = StringType(required=True) reputation_agent_addr = StringType(required=True) requester_pgp_public_key = StringType() ro_uri = StringType() repo_uri = StringType() batch_result_delivery_webhook = URLType() online_result_delivery_webhook = URLType() instant_result_delivery_webhook = URLType() multi_challenge_manifests = ListType(ModelType(NestedManifest), required=False) request_type = StringType(required=True, choices=BASE_JOB_TYPES + ["multi_challenge"]) validate_request_type = validate_request_type request_config = ModelType(RequestConfig, required=False) # If taskdata is directly provided taskdata = ListType(ModelType(TaskData)) # If taskdata is separately stored taskdata_uri = URLType() # Groundtruth data is stored as a URL or optionally as an inlined json-serialized stringtype groundtruth_uri = URLType(required=False) groundtruth = StringType(required=False) rejected_uri = URLType(required=False) rejected_count = IntType(default=0, required=False) def validate_groundtruth(self, data, value): if data.get('groundtruth_uri') and data.get('groundtruth'): raise ValidationError( "Specify only groundtruth_uri or groundtruth, not both.") return value # internal config options for param tests etc. internal_config = ModelType(InternalConfig, required=False) # Configuration id -- XXX LEGACY confcalc_configuration_id = StringType(required=False) restricted_audience = ModelType(RestrictedAudience, required=True, default={}) def validate_taskdata_uri(self, data, value): if data.get('taskdata') and len( data.get('taskdata')) > 0 and data.get('taskdata_uri'): raise ValidationError( u'Specify only one of taskdata {} or taskdata_uri {}'.format( data.get('taskdata'), data.get('taskdata_uri'))) return value validate_taskdata = validate_taskdata_uri webhook = ModelType(Webhook)
class Balance(PModel): asset_type = StringType() asset_code = StringType() asset_issuer = StringType() balance = DecimalType(default=0) limit = DecimalType()
class ProductGDSN(Model): # Col_A = StringType(default='', serialize_when_none=False) Label_Description = StringType(max_length=200, required=False, default='None') Trade_Item_GTIN = StringType(regex="\d(539|501|509|0\d\d)\d{10}", required=True) Product_Description = StringType(max_length=200, required=True) Information_Provider_GLN = StringType(regex="\d{13}", required=True) Information_Provider_Name = StringType(max_length=100, required=False, default='GS1 Ireland') Company_Name = StringType(max_length=100, required=True) Target_Market = StringType(choices=[tm[0] for tm in TM], required=False, default='372') Trade_Item_Country_Of_Origin = StringType(choices=[tm[0] for tm in TM], required=False, default='372') Use_Language_Code_List = StringType(choices=[lng[0] for lng in LANGUAGES], default='en') # 58 Classification_Category_Code = StringType(required=True) Base_Unit_Indicator = MyBooleanType(required=True) Consumer_Unit_Indicator = MyBooleanType(required=True) Variable_Weight_Trade_Item = MyBooleanType(required=True) Ordering_Unit_Indicator = MyBooleanType(required=True) Dispatch_Unit_Indicator = MyBooleanType(required=True) Invoice_Unit_Indicator = MyBooleanType(required=True) Trade_Item_Unit_Descriptor = StringType( choices=[d[1] for d in PACKAGE_LEVELS], required=True) Functional_Name = StringType(max_length=75, required=True) Brand_Name = StringType(max_length=75, required=True) Height = DecimalType(required=False) Width = DecimalType(required=False) Depth = DecimalType(required=False) Height_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Width_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Depth_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Gross_Weight = DecimalType(required=False) Gross_Weight_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Net_Content = StringType(max_length=10, required=False) Net_Content_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Packaging_Type_Code = StringType(choices=[pt[0] for pt in PACKAGE_TYPES], required=False) Trade_Item_Last_Change_Date = DateTimeType( required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") Discontinued_Date = DateTimeType(required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") Col_AM = StringType(default='', serialize_when_none=False) Sub_Brand = StringType(max_length=75, required=False) Variant_Description = StringType(max_length=75, required=False) Net_Weight = DecimalType(required=False) Net_Weight_UOM = StringType(choices=[uom[0] for uom in UOMS], required=False) Manufacturer_GLN = StringType(required=False) Manufacturer_Name = StringType(max_length=100, required=False) Additional_Trade_Item_Identification_Type = StringType(max_length=50, required=False) Additional_Trade_Item_Identification_Value = StringType(max_length=50, required=False) Type_Of_Information = StringType(max_length=100, required=False) Uniform_Resource_Identifier = StringType(max_length=100, required=False) Packaging_Marked_Returnable = MyBooleanType() Is_Price_On_Pack = MyBooleanType() GTIN_Of_Next_Lower_Item = StringType(required=False) Amount_Of_Next_Lower_Level_Items = StringType(required=False) Quantity_Of_Children = NumberType(int, 'Integer', min_value=1, required=False) Total_Quantity_Of_Next_Lower_Level_Trade_Item = StringType(required=False) Start_Availability_Date_Time = DateTimeType( required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") End_Availability_Date_Time = DateTimeType( required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") Trade_Item_Status = StringType(max_length=25, required=False, default='ADD') Brand_Owner_GLN = StringType(required=False) Brand_Owner_Name = StringType(max_length=100, required=False) Col_AN = StringType(default='', serialize_when_none=False) Col_AO = StringType(default='', serialize_when_none=False) Col_AP = StringType(default='', serialize_when_none=False) Publication_Date = DateTimeType( required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") # pub_date Effective_Date = DateTimeType( required=False, serialized_format="%Y-%m-%dT%H:%M:%S%zZ") # eff_date Col_AZ = StringType(default='', serialize_when_none=False) Col_BA = StringType(default='', serialize_when_none=False) Col_BB = StringType(default='', serialize_when_none=False) Col_BC = StringType(default='', serialize_when_none=False) Col_BD = StringType(default='', serialize_when_none=False) Col_BE = StringType(default='', serialize_when_none=False) Col_BF = StringType(default='', serialize_when_none=False) Col_BG = StringType(default='', serialize_when_none=False) Col_BH = StringType(default='', serialize_when_none=False) Col_BI = StringType(default='', serialize_when_none=False) Col_BJ = StringType(default='', serialize_when_none=False) Col_BK = StringType(default='', serialize_when_none=False) Col_BL = StringType(default='', serialize_when_none=False) Barcode_Type = StringType(choices=[bt[0] for bt in BARCODE_TYPES], required=False) Col_BO = StringType(default='', serialize_when_none=False) Col_BP = StringType(default='', serialize_when_none=False) Col_BQ = StringType(default='', serialize_when_none=False) Col_BV = StringType(default='', serialize_when_none=False) Col_BW = StringType(default='', serialize_when_none=False) Col_BX = StringType(default='', serialize_when_none=False) Col_BY = StringType(default='', serialize_when_none=False) Col_BZ = StringType(default='', serialize_when_none=False) Col_CA = StringType(default='', serialize_when_none=False) Col_CB = StringType(default='', serialize_when_none=False) Col_CC = StringType(default='', serialize_when_none=False) Col_CD = StringType(default='', serialize_when_none=False) Col_CE = StringType(default='', serialize_when_none=False) Col_CG = StringType(default='', serialize_when_none=False) Col_CH = StringType(default='', serialize_when_none=False) Col_CI = StringType(default='', serialize_when_none=False) Col_CJ = StringType(default='', serialize_when_none=False) Col_CK = StringType(default='', serialize_when_none=False) Col_CL = StringType(default='', serialize_when_none=False) Col_CM = StringType(default='', serialize_when_none=False) Col_CN = StringType(default='', serialize_when_none=False) Col_CO = StringType(default='', serialize_when_none=False) Col_CP = StringType(default='', serialize_when_none=False) Col_CQ = StringType(default='', serialize_when_none=False) Col_CR = StringType(default='', serialize_when_none=False) Col_CS = StringType(default='', serialize_when_none=False) Col_CT = StringType(default='', serialize_when_none=False) Col_CU = StringType(default='', serialize_when_none=False) Col_CV = StringType(default='', serialize_when_none=False) Col_CW = StringType(default='', serialize_when_none=False) Col_CX = StringType(default='', serialize_when_none=False) Col_CY = StringType(default='', serialize_when_none=False) Col_CZ = StringType(default='', serialize_when_none=False) Col_DA = StringType(default='', serialize_when_none=False) Col_DB = StringType(default='', serialize_when_none=False) Col_DC = StringType(default='', serialize_when_none=False) Col_DE = StringType(default='', serialize_when_none=False) GS1CloudStatus = StringType(choices=['ACTIVE', 'INACTIVE'], required=False) ''' # def validate_Additional_Trade_Item_Identification_Value(self, data, value): # if not value: # raise ValidationError("This field is required") def validate_Label_Description(self, data, value): if data['Trade_Item_Unit_Descriptor'] == 'BASE_UNIT_OR_EACH': if not value: raise ValidationError("This field is required for base units") def validate_Classification_Category_Code(self, data, value): cs = CategoriesService() if self.Classification_Category_Code.required and not value: raise ValidationError("Classification Category Code is required") if value and not cs.first(code=value): raise ValidationError( "Classification Category Code is not valid, please consult https://www.gs1.org/gpc/browser") def validate_Manufacturer_GLN(self, data, value): if value and not re.match("\d{13}", value): raise ValidationError("Manufacturer GLN is not valid") if value and not data['Manufacturer_Name']: raise ValidationError("If Manufacturer GLN is present, Manufacturer Name should be present") def validate_Manufacturer_Name(self, data, value): if value and not data['Manufacturer_GLN']: raise ValidationError("If Manufacturer Name is present, Manufacturer GLN should be present") # def validate_Brand_Owner_GLN(self, data, value): # if value and not re.match("\d{13}", value): # raise ValidationError("Brand Owner GLN is not valid") def validate_Trade_Item_GTIN(self, data, value): if not isValid(value): raise ValidationError("GTIN not valid") def validate_Net_Content(self, data, value): if value: if not data.get('Net_Content_UOM'): raise ValidationError("Net Content is given without Net Content UOM") def validate_Net_Content_UOM(self, data, value): if value: if not data.get('Net_Content'): raise ValidationError("Net Content UOM is given without Net Content value") def validate_Net_Weight(self, data, value): if value: if not data.get('Net_Weight_UOM'): raise ValidationError("Net Weight is given without Net Weight UOM") def validate_Net_Weight_UOM(self, data, value): if value: if not data.get('Net_Weight'): raise ValidationError("Net Weight UOM is given without Net Weight value") def validate_Height_UOM(self, data, value): if data['Height'] and not value: raise ValidationError("Height UOM is required when Height is given") def validate_Width_UOM(self, data, value): if data['Width'] and not value: raise ValidationError("Width UOM is required when Width is given") def validate_Depth_UOM(self, data, value): if data['Depth'] and not value: raise ValidationError("Depth UOM is required when Depth is given") def validate_Gross_Weight_UOM(self, data, value): if data['Gross_Weight'] and not value: raise ValidationError("Gross_Weight UOM is required when Gross_Weight is given") def validate_Quantity_Of_Children(self, data, value): if data['Trade_Item_Unit_Descriptor'] != BASE_PACKAGE_LEVEL: if not value: raise ValidationError( "Quantity Of Children is required when Trade Item Unit Descriptor is not BASE UNIT OR EACH") def validate_Quantity_Of_Next_Lower_Level_Item(self, data, value): if data['GTIN_Of_Next_Lower_Item']: if not value: raise ValidationError( "Quantity Of Next Lower Level Item is required when GTIN Of Next Lower Item is given") if len(data['Quantity_Of_Next_Lower_Level_Item'].split(',')) != int(data['Quantity_Of_Children']): raise ValidationError("Length of Quantity Of Next Lower Level Item must equal the Quantity Of Children") def validate_GTIN_Of_Next_Lower_Item(self, data, value): if data['Trade_Item_Unit_Descriptor'] != BASE_PACKAGE_LEVEL: if not value: raise ValidationError( "GTIN Of Next Lower Item is required when Trade Item Unit Descriptor is not BASE UNIT OR EACH") try: int(data['Quantity_Of_Children']) except Exception as e: raise ValidationError("Quantity_Of_Children must be given") if len(data['GTIN_Of_Next_Lower_Item'].split(',')) != int(data['Quantity_Of_Children']): raise ValidationError("Length of GTIN_Of_Next_Lower_Item must equal the Quantity Of Children") # def validate_fileFormatCode(self, data, value): # pass # def validate_Uniform_Resource_Identifier(self, data, value): # if value: # if not value.startswith('http://') or not value.statswith('https://'): # raise ValidationError('Uniform_Resource_Identifier should start with http: or https:') ''' @classmethod def get_fieldnames(cls): return [ # 'Col_A', 'Label_Description', 'Trade_Item_GTIN', 'Information_Provider_GLN', 'Information_Provider_Name', 'Target_Market', 'Base_Unit_Indicator', 'Consumer_Unit_Indicator', 'Variable_Weight_Trade_Item', 'Ordering_Unit_Indicator', 'Dispatch_Unit_Indicator', 'Invoice_Unit_Indicator', 'Start_Availability_Date_Time', 'Classification_Category_Code', 'Trade_Item_Unit_Descriptor', 'Functional_Name', 'Brand_Name', 'Packaging_Marked_Returnable', 'Height', 'Height_UOM', 'Width', 'Width_UOM', 'Depth', 'Depth_UOM', 'Gross_Weight', 'Gross_Weight_UOM', 'End_Availability_Date_Time', 'Sub_Brand', 'Brand_Owner_GLN', 'Brand_Owner_Name', 'Product_Description', 'Variant_Description', 'Net_Content', 'Net_Content_UOM', 'Net_Weight', 'Net_Weight_UOM', 'Packaging_Type_Code', 'Trade_Item_Last_Change_Date', 'Discontinued_Date', 'Col_AM', # Display_Unit_Indicator 'Col_AN', # Platform_Type_Code 'Col_AO', # Packaging_Weight 'Col_AP', # Packaging_Weight_UoM 'Publication_Date', 'Effective_Date', 'GTIN_Of_Next_Lower_Item', 'Amount_Of_Next_Lower_Level_Items', 'Quantity_Of_Children', 'Total_Quantity_Of_Next_Lower_Level_Trade_Item', 'Trade_Item_Country_Of_Origin', 'Manufacturer_GLN', 'Manufacturer_Name', 'Col_AZ', 'Col_BA', 'Col_BB', 'Col_BC', 'Col_BD', 'Col_BE', 'Col_BF', 'Col_BG', 'Col_BH', 'Col_BI', 'Col_BJ', 'Col_BK', 'Col_BL', 'Is_Price_On_Pack', 'Barcode_Type', 'Col_BO', 'Col_BP', 'Col_BQ', 'Additional_Trade_Item_Identification_Type', 'Additional_Trade_Item_Identification_Value', 'Type_Of_Information', 'Uniform_Resource_Identifier', 'Col_BV', 'Col_BW', 'Col_BX', 'Col_BY', 'Col_BZ', 'Col_CA', 'Col_CB', 'Col_CC', 'Col_CD', 'Col_CE', 'Trade_Item_Status', 'Col_CG', 'Col_CH', 'Col_CI', 'Col_CJ', 'Col_CK', 'Col_CL', 'Col_CM', 'Col_CN', 'Col_CO', 'Col_CP', 'Col_CQ', 'Col_CR', 'Col_CS', 'Col_CT', 'Col_CU', 'Col_CV', 'Col_CW', 'Col_CX', 'Col_CY', 'Col_CZ', 'Col_DA', 'Col_DB', 'Col_DC', 'Use_Language_Code_List', 'Col_DE', 'GS1CloudStatus', 'Company_Name' ] @classmethod def export(cls, products, user): errors = [] content = [] tm = ProductTemplate.objects.filter(name="gs1se-base").first() keys = set(x.path.split(".")[-1] for x in tm.attributes.all()) serialized_products = serializers.serialize('json', products, fields=keys) products_data = json.loads(serialized_products) xls_keys = language_mapping(tm, user) for product in products_data: try: res = { xls_keys[key]: get_translated_values(value, user) for key, value in product.get("fields").items() } except ModelConversionError as e: errors.append({ product.gtin: dict([(k, v[0]) for k, v in e.messages.items()]) }) continue except Exception as e: errors.append({product.gtin: {'Exception': str(e)}}) continue content.append(res) return content, errors
class StockInfo(Model): stock_code = StringType() language = StringType() region = StringType() quote_type = StringType(deserialize_from="quoteType", serialized_name="quoteType") currency = StringType() fifty_two_week_low_change_percent = DecimalType( deserialize_from="fiftyTwoWeekLowChangePercent", serialized_name="fiftyTwoWeekLowChangePercent") fifty_two_week_low_change = DecimalType( deserialize_from="fifty_two_week_low_change", serialized_name="fifty_two_week_low_change") fifty_two_week_range = StringType(deserialize_from="fiftyTwoWeekRange", serialized_name="fiftyTwoWeekRange") fifty_two_week_high_change = DecimalType( deserialize_from="fiftyTwoWeekHighChange", serialized_name="fiftyTwoWeekHighChange") fifty_two_week_high_change_percent = DecimalType( deserialize_from="fiftyTwoWeekHighChangePercent", serialized_name="fiftyTwoWeekHighChangePercent") fifty_two_week_low = DecimalType(deserialize_from="fiftyTwoWeekLow", serialized_name="fiftyTwoWeekLow") fifty_two_week_high = DecimalType(deserialize_from="fiftyTwoWeekHigh", serialized_name="fiftyTwoWeekHigh") dividend_date = IntType(deserialize_from="dividendDate", serialized_name="dividendDate") earnings_timestamp = IntType(deserialize_from="earningsTimestamp", serialized_name="earningsTimestamp") earnings_timestamp_start = IntType( deserialize_from="earningsTimestampStart", serialized_name="earningsTimestampStart") earnings_timestamp_end = IntType(deserialize_from="earningsTimestampEnd", serialized_name="earningsTimestampEnd") trailing_annual_dividend_rate = DecimalType( deserialize_from="trailingAnnualDividendRate", serialized_name="trailingAnnualDividendRate") trailing_pe = DecimalType(deserialize_from="trailingPe", serialized_name="trailingPe") trailing_annual_dividend_yield = DecimalType( deserialize_from="trailingAnnualDividendYield", serialized_name="trailingAnnualDividendYield") eps_trailing_twelve_months = DecimalType( deserialize_from="epsTrailingTwelveMonths", serialized_name="epsTrailingTwelveMonths") eps_forward = DecimalType(deserialize_from="epsForward", serialized_name="epsForward") post_market_change_percent = DecimalType( deserialize_from="postMarketChangePercent", serialized_name="postMarketChangePercent") exchange_data_delayed_by = IntType( deserialize_from="exchangeDataDelayedBy", serialized_name="exchangeDataDelayedBy") shares_outstanding = IntType(deserialize_from="sharesOutstanding", serialized_name="sharesOutstanding") book_value = DecimalType(deserialize_from="bookValue", serialized_name="bookValue") fifty_day_average = DecimalType(deserialize_from="fiftyDayAverage", serialized_name="fiftyDayAverage") fifty_day_average_change = DecimalType( deserialize_from="fiftyDayAverageChange", serialized_name="fiftyDayAverageChange") fifty_day_average_change_percent = DecimalType( deserialize_from="fiftyDayAverageChangePercent", serialized_name="fiftyday_average_change_percent") two_hundred_day_average = DecimalType( deserialize_from="twoHundredDayAverage", serialized_name="twoHundredDayAverage") two_hundred_day_average_change = DecimalType( deserialize_from="twoHundredDayAverageChange", serialized_name="twoHundredDayAverageChange") two_hundred_day_average_change_percent = DecimalType( deserialize_from="twoHundredDayAverageChangePercent", serialized_name="twoHundredDayAverageChangePercent") forward_pe = DecimalType(deserialize_from="forwardPe", serialized_name="forwardPe") market_cap = IntType(deserialize_from="marketCap", serialized_name="marketCap") exchange = StringType() price_hint = IntType(deserialize_from="priceHint", serialized_name="priceHint") regular_market_price = DecimalType(deserialize_from="regularMarketPrice", serialized_name="regularMarketPrice") regular_market_time = IntType(deserialize_from="regularMarketTime", serialized_name="regular_market_time") regular_market_change = DecimalType(deserialize_from="regularMarketChange", serialized_name="regularMarketChange") regular_market_open = DecimalType(deserialize_from="regularMarketOpen", serialized_name="regularMarketOpen") regular_market_day_high = DecimalType( deserialize_from="regularMarketDayHigh", serialized_name="regularMarketDayHigh") regular_market_day_low = DecimalType( deserialize_from="regularMarketDayLow", serialized_name="regularMarketDayLow") regular_market_volume = IntType(deserialize_from="regularMarketVolume", serialized_name="regularMarketVolume") post_market_time = IntType(deserialize_from="postMarketTime", serialized_name="postMarketTime") post_market_price = DecimalType(deserialize_from="postMarketPrice", serialized_name="postMarketPrice") post_market_change = DecimalType(deserialize_from="postMarketChange", serialized_name="postMarketChange") regular_market_change_percent = DecimalType( deserialize_from="regularMarketChangePercent", serialized_name="regularMarketChangePercent") regular_market_day_range = StringType( deserialize_from="regularMarketDayRange", serialized_name="regularMarketDayRange") regular_market_previous_close = DecimalType( deserialize_from="regularMarketPreviousClose", serialized_name="regularMarketPreviousClose") message_board_id = StringType(deserialize_from="messageBoardId", serialized_name="messageBoardId") full_exchange_name = StringType(deserialize_from="fullExchangeName", serialized_name="fullExchangeName") long_name = StringType(deserialize_from="longName", serialized_name="longName") financial_currency = StringType(deserialize_from="financialCurrency", serialized_name="financialCurrency") average_daily_volume3_month = IntType( deserialize_from="averageDailyVolume3Month", serialized_name="averageDailyVolume3Month") average_daily_volume10_day = IntType( deserialize_from="averageDailyVolume10Day", serialized_name="averageDailyVolume10Day") price_to_book = DecimalType(deserialize_from="priceToBook", serialized_name="priceToBook") source_interval = IntType(deserialize_from="sourceInterval", serialized_name="sourceInterval") exchange_timezone_name = StringType( deserialize_from="exchangeTimezoneName", serialized_name="exchangeTimezoneName") exchange_timezone_short_name = StringType( deserialize_from="exchangeTimezoneShortName", serialized_name="exchangeTimezoneShortName") gmt_off_set_milliseconds = IntType( deserialize_from="gmtOffSetMilliseconds", serialized_name="gmtOffSetMilliseconds") esg_populated = BooleanType(deserialize_from="esgPopulated", serialized_name="esgPopulated") tradeable = BooleanType(deserialize_from="tradeable", serialized_name="tradeable") short_name = StringType(deserialize_from="shortName", serialized_name="shortName") market_state = StringType(deserialize_from="marketState", serialized_name="marketState") market = StringType() price = DecimalType()
class Person(XMLModel): height = DecimalType()
StringType, DateTimeType, ) from schematics.models import ModelMeta from schematics.types.compound import (ListType, ModelType, DictType) from schematics.exceptions import BaseError, ConversionError from schematics.transforms import get_import_context from ..exceptions import SerializationException from decimal import Decimal from ..compat import all_string_types MODEL_MAP = { int: IntType(), bool: BooleanType(), float: FloatType(), Decimal: DecimalType(), None: BaseType(), datetime: DateTimeType(), } for t in all_string_types: MODEL_MAP[t] = StringType() JSON_SCHEMA_MAP = OrderedDict([ (BooleanType, { "type": "boolean" }), (NumberType, { "type": "number" }), (BaseType, {
class Data(Model): a = DecimalType(min_value=-10, max_value=10)
class Container(Model): # pylint: disable=function-redefined item = PolyModelType([ModelType(self.TestModel), DecimalType()])