Example #1
0
class UserProfile(Model):
    """The basic things a user profile tends to carry. Isolated in separate
    class to keep separate from private data.
    """
    # Provided by OwnedModelMixin
    owner_id = ObjectIdType(required=True)
    owner_username = StringType(max_length=30, required=True)

    # streamable # provided by StreamedModelMixin now
    created_at = MillisecondType()
    updated_at = MillisecondType()

    # identity info
    name = StringType(max_length=255)
    email = EmailType(max_length=100)
    website = URLType(max_length=255)
    bio = StringType(max_length=100)
    location_text = StringType(max_length=100)
    avatar_url = URLType(max_length=255)

    class Options:
        roles = {
            'owner': blacklist('owner_id'),
        }

    def __init__(self, *args, **kwargs):
        super(UserProfile, self).__init__(*args, **kwargs)

    def __unicode__(self):
        return u'%s' % (self.name)
Example #2
0
class ScienceAlertValidatorItem(Model):
    url = URLType(required=True)
    title = StringType(required=True)
    content = StringType(required=True)
    date = DateTimeType(required=True)
    author = StringType(required=True, regex=REGEX.NO_COMMA)
    source = URLType()  # TODO: coverage 25%
Example #3
0
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
Example #4
0
class ScienceDailyValidatorItem(Model):
    url = URLType(required=True)
    title = StringType(required=True)
    content = StringType(required=True)
    date = DateTimeType(required=True)
    source = StringType(required=True)
    subtitle = StringType(required=True)
    source_article_url = URLType()  # TODO: coverage 25%
Example #5
0
class MetaswitchTinder(Model):
    """Schematics model to parse and validate the app config."""

    app_name = StringType(required=True)
    css_cdn = URLType(
        default="https://maxcdn.bootstrapcdn.com/bootswatch/4.0.0/"
        "minty/bootstrap.min.css")
    default_user_image = URLType(required=True)
    ducks = ListType(URLType(required=True))
    sad_ducks = ListType(URLType(required=True))
    serious_ducks = ListType(URLType(required=True))
    report_email_address = EmailType(required=True)
class Identifier(Model):
    class Options:
        serialize_when_none = False

    scheme = URLType(
    )  # The scheme that holds the unique identifiers used to identify the item being identified.
    id = BaseType(
    )  # The identifier of the organization in the selected scheme.
    legalName = StringType(
    )  # The legally registered name of the organization.
    legalName_en = StringType()
    legalName_ru = StringType()
    uri = URLType()  # A URI to identify the organization.
Example #7
0
class ResultSet(Model):

    count = IntType()
    previous = URLType()
    next = URLType()

    @property
    def results(self):  # pragma: nocover
        raise NotImplementedError()

    def _parse_params(self, url):
        return dict(
            six.moves.urllib.parse.parse_qsl(
                six.moves.urllib.parse.urlparse(url).query))

    def has_previous(self):
        return self.previous is not None

    def has_next(self):
        return self.next is not None

    def get_next(self):
        if not self.has_next() or not hasattr(self, '_more'):
            return
        params = self._parse_params(self.next)
        return self._more(**params)

    def get_previous(self):
        if not self.has_previous() or not hasattr(self, '_more'):
            return
        params = self._parse_params(self.previous)
        return self._more(**params)

    def iter_pages(self):
        next_page = self
        while next_page.has_next():
            next_page = next_page.get_next()
            yield next_page

    def iter_items(self):
        return iter(self.results)

    def iter_all(self):
        for item in self.iter_items():
            yield item
        for page in self.iter_pages():
            for item in page.iter_items():
                yield item

    def __iter__(self):
        return self.iter_items()
Example #8
0
class ScienceNewsValidatorItem(Model):
    url = URLType(required=True)
    title = StringType(required=True)
    content = StringType(required=True)
    date = DateTimeType(required=True)
    subtitle = StringType(required=True)
    author = StringType(required=True, regex=REGEX.NO_COMMA)
Example #9
0
 def __init__(self, access):
     # Hold infos to reach the config formatted like an url path
     # <path.to.module>://<ip>:<port>/<access/...?<key>=<value>...
     StringType(regex='.*://\w').validate(access)
     self._ctx_module = access.split('://')[0]
     self._ctx_infos = access.split('://')[1]
     URLType().validate('http://{}'.format(self._ctx_infos))
Example #10
0
class TaskDataEntry(Model):
    """
    Taskdata file format:

    [
      {
        "task_key": "407fdd93-687a-46bb-b578-89eb96b4109d",
        "datapoint_uri": "https://domain.com/file1.jpg",
        "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa"
      },
      {
        "task_key": "20bd4f3e-4518-4602-b67a-1d8dfabcce0c",
        "datapoint_uri": "https://domain.com/file2.jpg",
        "datapoint_hash": "f4acbe8562907183a484498ba901bfe5c5503aaa"
      }
    ]
    """
    task_key = UUIDType()
    datapoint_uri = URLType(required=True, min_length=10)
    datapoint_hash = StringType()
    metadata = DictType(UnionType(
        [StringType(required=False, max_length=256), FloatType, IntType]),
                        required=False)

    def validate_metadata(self, data, value):
        if len(str(value)) > 1024:
            raise ValidationError("metadata should be < 1024")
        return value
Example #11
0
class Identifier(Model):
    scheme = StringType(required=True, choices=IDENTIFIER_CODES)  # The scheme that holds the unique identifiers used to identify the item being identified.
    id = BaseType(required=True)  # The identifier of the organization in the selected scheme.
    legalName = StringType()  # The legally registered name of the organization.
    legalName_en = StringType()
    legalName_ru = StringType()
    uri = URLType()  # A URI to identify the organization.
class Identifier(Model):
    scheme = StringType(required=True, choices=ORA_CODES)
    id = BaseType(required=True)
    legalName = StringType()
    legalName_en = StringType()
    legalName_ru = StringType()
    uri = URLType()
Example #13
0
class RestaurantModel(Model):
    id = StringType()
    name = StringType(required=True)
    link = URLType(required=True)
    tags = ListType(StringType)
    telephone = StringType()
    description = StringType()
    location = ModelType(LocationType, required=True)
    address = ModelType(AddressType, required=True)

    def to_document(r):
        return {
            "name": r.name,
            "link": r.link,
            "location": r.location.to_document(),
            "address": r.address.to_document(),
            "telephone": r.telephone,
            "description": r.description,
            "tags": r.tags,
        }

    @staticmethod
    def from_document(doc):
        r = RestaurantModel()
        r.name = doc.get("name")
        r.link = doc.get("link")
        r.location = LocationType.from_document(doc.get("location"))
        r.address = AddressType.from_document(doc.get("address"))
        r.description = doc.get("description")
        r.tags = doc.get("tags")
        r.telephone = doc.get("telephone")
        return r
Example #14
0
    class MIDSchema(Model):
        """Validating schema for Mobile ID config."""
        url = URLType(required=True)
        relyingpartyuuid = StringType(required=True)
        relyingpartyname = StringType(required=True)
        language = StringType(
            required=True, choices=['EST', 'ENG', 'RUS', 'LIT'])
        authmessage = StringType(required=True, max_length=40)
        signmessage = StringType(required=True, max_length=40)
        messageformat = StringType(default='GSM-7', choices=['GSM-7', 'UCS-2'])
        authchallengesize = IntType(default=32, choices=[32, 48, 64])
        statustimeoutms = IntType()
        roots = ListType(CertificateType, required=True)
        intermediates = ListType(CertificateType)
        ocsp = ModelType(OCSPSchema)

        # pylint: disable=no-self-use
        def validate_phonerequired(self, data, value):
            """Validate phone/idcode required field."""
            try:
                if not data['idcoderequired'] and not data['phonerequired']:
                    raise ValidationError('Either idcoderequired or '
                                          'phonerequired must be true')
            except KeyError:
                pass  # error in data structure is catched later
            return value
    class DDSSchema(Model):
        """Validating schema for DDS config."""
        url = URLType(required=True)
        countrycode = StringType(required=True)
        language = StringType(required=True,
                              choices=['EST', 'ENG', 'RUS', 'LIT'])
        servicename = StringType(required=True, max_length=20)
        authmessage = StringType(required=True, max_length=40)
        signmessage = StringType(required=True, max_length=40)
        idcoderequired = BooleanType()
        phonerequired = BooleanType()
        roots = ListType(CertificateType, required=True)
        intermediates = ListType(CertificateType)
        ocsp = ModelType(OCSPSchemaNoURL)

        # pylint: disable=no-self-use
        def validate_phonerequired(self, data, value):
            """Validate phone/idcode required field."""
            try:
                if not data['idcoderequired'] and not data['phonerequired']:
                    raise ValidationError('Either idcoderequired or '
                                          'phonerequired must be true')
            except KeyError:
                pass  # error in data structure is catched later
            return value
Example #16
0
class PostItem(Model):
    visit_ts = DateTimeType(required=True)
    date = DateType(required=True)

    link = URLType(required=True)
    parent_link = URLType(required=True)
    campus = StringType(required=True)
    sections = StringType(required=True)

    title = StringType(required=True)
    description = StringType()
    text = StringType(required=True)

    tags = ListType(StringType)
    people = ListType(StringType)
    branches = ListType(StringType)
class Document(Model):
    class Options:
        serialize_when_none = False
        roles = {
            'embedded': schematics_embedded_role,
            'view': (blacklist('revisions') + schematics_default_role),
            'revisions': whitelist('uri', 'dateModified'),
        }

    id = StringType()
    classification = StringType(choices=[
        'notice', 'biddingDocuments', 'technicalSpecifications',
        'evaluationCriteria', 'clarifications', 'tenderers'
    ])
    title = StringType()  # A title of the document.
    title_en = StringType()
    title_ru = StringType()
    description = StringType()  # A description of the document.
    description_en = StringType()
    description_ru = StringType()
    format = StringType()
    url = URLType()  # Link to the document or attachment.
    datePublished = IsoDateTimeType(default=get_now)
    dateModified = IsoDateTimeType(
        default=get_now)  # Date that the document was last dateModified
    language = StringType()
Example #18
0
 def validate_url(self, data, url):
     if data.get('documentType') == 'virtualDataRoom':
         URLType().validate(url)
     if data.get('documentType') == 'x_dgfAssetFamiliarization' and url:
         raise ValidationError(u'This field is not required.')
     if data.get('documentType') != 'x_dgfAssetFamiliarization' and not url:
         raise ValidationError(u'This field is required.')
Example #19
0
class Classification(Model):
    scheme = StringType(required=True)  # The classification scheme for the goods
    id = StringType(required=True)  # The classification ID from the Scheme used
    description = StringType(required=True)  # A description of the goods, services to be provided.
    description_en = StringType()
    description_ru = StringType()
    uri = URLType()
Example #20
0
class NewPhone(Model):
    """Input structure for a new phone."""

    number = StringType(required=True)
    type = StringType(choices=PHONE_TYPES, default='other')
    is_primary = IntType(default=0)
    uri = URLType()
Example #21
0
class ModMixin(_Model):
    count = LongType()

    liked = ListType(ObjectIdType(ObjectId))
    # create RatingType
    # https   ://developers.google.com/gdata/docs/2.0/elements#gdRating
    rating = IntType()
    followers = ListType(ObjectIdType(ObjectId))
    favorited = ListType(ObjectIdType(ObjectId))

    reviews = ListType(ModelType(Review))

    tags = ListType(ModelType(Tag))

    tels = ListType(ModelType(Tel), description='Telephones')
    emails = ListType(ModelType(Email), description='Emails')
    ims = ListType(ModelType(Im), description='Instant Message Network')

    urls = ListType(URLType(), description='Urls associated with this doc.')
    rdts = ListType(ModelType(Rdt))
    desc = StringType(description='Description')
    notes = ListType(ModelType(Note))

    shrs = ListType(
        ModelType(Shr),
        description=
        'Share List of Share docs that describe who and at what level/role this doc is shared with.'
    )

    # tos     : ie, parents
    tos = ListType(ModelType(Pth))

    # frs     : froms, ie, children
    frCount = IntType()
    frs = ListType(ModelType(Pth))
class LotValue(Model):
    class Options:
        roles = {
            'embedded':
            schematics_embedded_role,
            'view':
            schematics_default_role,
            'create':
            whitelist('value', 'relatedLot'),
            'edit':
            whitelist('value', 'relatedLot'),
            'auction_view':
            whitelist('value', 'date', 'relatedLot', 'participationUrl'),
            'auction_post':
            whitelist('value', 'date', 'relatedLot'),
            'auction_patch':
            whitelist('participationUrl', 'relatedLot'),
        }

    value = ModelType(Value, required=True)
    relatedLot = MD5Type(required=True)
    participationUrl = URLType()
    date = IsoDateTimeType(default=get_now)

    def validate_value(self, data, value):
        if value and isinstance(data['__parent__'],
                                Model) and data['relatedLot']:
            validate_LotValue_value(get_tender(data['__parent__']),
                                    data['relatedLot'], value)

    def validate_relatedLot(self, data, relatedLot):
        if isinstance(data['__parent__'], Model) and relatedLot not in [
                i.id for i in get_tender(data['__parent__']).lots
        ]:
            raise ValidationError(u"relatedLot should be one of lots")
Example #23
0
class Party(BaseModel):
    metadata = dict(
        label='party',
        description='A party is a person, project or organization related to a package.')

    type = StringType(choices=PARTY_TYPES)
    type.metadata = dict(
        label='party type',
        description='the type of this party: One of: ' + ', '.join(PARTY_TYPES))

    name = StringType()
    name.metadata = dict(
        label='name',
        description='Name of this party.')

    url = URLType()
    name.metadata = dict(
        label='url',
        description='URL to a primary web page for this party.')

    email = EmailType()
    email.metadata = dict(
        label='email',
        description='Email for this party.')

    class Options:
        fields_order = 'type', 'name', 'email', 'url'
Example #24
0
class BidderModel(Model):
  user = ModelType (
    UserModel, 
    required=True, 
    serialized_name = "User Details" )

  address = ModelType (
    AddressModel, 
    required=True,
    serialized_name = "Address" )

  billing_details = ModelType ( 
    BillingDetailsModel, 
    required=True, 
    serialized_name = "Billing Details" )

  comments = ListType(  
    ModelType(CommentModel),
    required=False,
    serialized_name = "Comments about Bidder" )

  website = URLType(
    required=False,
    verify_exists=True,
    serialized_name = "Website" )

  description = StringType (
    required=False,
    serialized_name = "Bidder Description" )
Example #25
0
class ListItem(Model):
    """Bare minimum to have the concept of streamed item.
  """
    _id = ObjectIdType()
    owner = ObjectIdType(required=True)
    username = StringType(max_length=30, required=True)

    # streamable
    created_at = DateTimeType()
    updated_at = DateTimeType()

    url = URLType()

    @classmethod
    def make_ownersafe(self, item):
        return item

    class Meta:
        id_field = ObjectIdType

    class Options:
        roles = {
            'owner': blacklist('owner', 'username'),
        }

    def __unicode__(self):
        return u'%s' % (self.url)
Example #26
0
class ScientificAmericanValidatorItem(Model):
    url = URLType(required=True)
    title = StringType(required=True)
    content = StringType(required=True)
    date = DateTimeType(required=True)
    subtitle = StringType()
    author = StringType(regex=REGEX.NO_COMMA)
    archived = IntType()
class ContactPoint(Model):
    name = StringType()
    name_en = StringType()
    name_ru = StringType()
    email = EmailType()
    telephone = StringType()
    faxNumber = StringType()
    url = URLType()
Example #28
0
class TestClass(Model):
    uuid = StringType(required=True)
    hello = StringType(required=True)
    url = URLType()

    class Options:
        roles = {'public': blacklist('uuid')}
        serialize_when_none = False
Example #29
0
 def validate_url(self, data, url):
     doc_type = data.get('documentType')
     if doc_type in DOCUMENT_TYPE_URL_ONLY:
         URLType().validate(url)
     if doc_type in DOCUMENT_TYPE_OFFLINE and url:
         raise ValidationError(u'This field is not required.')
     if doc_type not in DOCUMENT_TYPE_OFFLINE and not url:
         raise ValidationError(u'This field is required.')
Example #30
0
class LiveScienceValidatorItem(Model):
    url = URLType(required=True)
    title = StringType(required=True)
    content = StringType(required=True)
    date = DateTimeType(required=True)
    subtitle = StringType()
    author = StringType(required=True,
                        regex=REGEX.NO_COMMA)  # No comma in the name