コード例 #1
0
class UserSchema(Schema):
    # TODO: secure password
    # TODO: validate email/username
    id = fields.Integer(dump_only=True)
    email_address = fields.String(required=True)
    username = fields.String(required=True)
    password = fields.String(required=True, load_only=True)
    date_created = fields.String(dump_only=True)
    date_updated = fields.String(dump_only=True)
    role = fields.String(default=UserRole.MEMBER,
                         validate=validate.OneOf(UserRole))

    _links = DictHyperlinks(
        {
            "self": URLFor("v1.get_user_details", values=dict(id="<id>")),
            "items": URLFor("v1.get_user_item_list",
                            values=dict(user_id="<id>")),
            "users": URLFor("v1.get_user_list"),
        },
        dump_only=True,
    )
コード例 #2
0
class ScheduledAnalysisSchema(BaseSchema):
    url = URLFor('.scheduled_analysis_detail', id='<id>', _external=True)
    sample = ForeignReferenceField(endpoint='.sample_detail',
                                   queryset=Sample.objects(),
                                   query_parameter='id')
    analysis_system_instance = ForeignReferenceField(
        endpoint='.analysis_system_instance_detail',
        queryset=AnalysisSystemInstance.objects(),
        query_parameter='uuid')

    class Meta(BaseSchema.Meta):
        model = ScheduledAnalysis
        dump_only = ['id', '_cls', 'analysis_scheduled']
コード例 #3
0
class PlaylistsSchema(Schema):
    name = fields.String(required=True)
    description = fields.String(required=True)

    _links = Hyperlinks(
        {
            "self":
            URLFor("playlistapi",
                   values=dict(playlist_id="<id>"),
                   _external=True,
                   required=True),
        },
        required=True)
コード例 #4
0
class SampleSchema(BaseSchema):
    url = URLFor('.sample_detail', id='<id>', _external=True)
    dispatched_to = List(ForeignReferenceField(endpoint='.analysis_system_detail', queryset=AnalysisSystem.objects(), query_parameter='identifier_name'))

    class Meta(BaseSchema.Meta):
        model = Sample
        exclude = ['created_by', 'comments']
        dump_only = [
            'id',
            'dispatched_to',
            '_cls',
            'delivery_date'
        ]
コード例 #5
0
class TicketSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Ticket
        include_relationships = True
        load_instance = True
        include_fk = True

    ticket_assigned = fields.Nested(UserSchema,
                                    only=("username", "first_name",
                                          "last_name"))
    reclamation = fields.Nested(ReclamationSchema,
                                only=("reclamation_customer",
                                      "reclamation_part_sn_id"))
    _links = Hyperlinks(
        {"self": URLFor("ticket_bp.ticket", ticket_number="<id>")})
コード例 #6
0
class ProcessSchema(Schema):
    process_id = fields.Int(dump_to='processID')
    reference_year = fields.Function(
        serialize=lambda itm: itm['TemporalScope'], dump_to='referenceYear')
    geography = fields.Function(serialize=lambda itm: itm['SpatialScope'])
    # reference_type_id = SKIP
    # composition_flow_id = SKIP
    data_source = fields.Str(attribute='origin', dump_to='dataSource')
    has_elem = fields.Bool(dump_to='hasElementaryFlows')
    name = fields.Function(serialize=lambda itm: itm['Name'])
    uuid = fields.Str()
    version = fields.Function(serialize=lambda itm: itm['Version'])
    resource_type = fields.Str(attribute='entity_type', dump_to='resourceType')
    is_private = fields.Bool(dump_to='isPrivate')

    _links = Hyperlinks({'self': URLFor('processes', id='<id>')})
コード例 #7
0
class FileSampleSchema(SampleSchema):
    file = URLFor('.sample_download', id='<id>', _external=True)

    class Meta(BaseSchema.Meta):
        model = FileSample
        exclude = ['created_by', 'comments']
        dump_only = SampleSchema.Meta.dump_only + [
            'file_size',
            'file_names',
            'magic_string',
            'md5sum',
            'sha1sum',
            'sha256sum',
            'sha512sum',
            'shannon_entropy',
            'ssdeep_hash'
        ]
コード例 #8
0
ファイル: __init__.py プロジェクト: tomdyson/Canella-CMS
 def __new__(cls, name, bases, d):
     rv = MethodViewType.__new__(cls, name, bases, d)
     if not rv.schema:
         return rv
     default_endpoints = cls.gen_default_api_endpoints(rv)
     if hasattr(rv, 'url_map'):
         default_endpoints.update(rv.url_map)
     for url, options in default_endpoints.items():
         api.add_resource(rv,
                          url,
                          methods=options.get(
                              'methods', ['POST', 'PUT', 'DELETE', 'GET']),
                          endpoint=options.get('endpoint'))
     site_endpoint = getattr(rv.schema, 'site_endpoint', [])
     if site_endpoint:
         rv.schema._declared_fields['site_url'] = URLFor(
             site_endpoint[0], **site_endpoint[1])
     return rv
コード例 #9
0
class AnalysisSystemInstanceSchema(BaseSchema):
    url = URLFor('.analysis_system_instance_detail',
                 uuid='<uuid>',
                 _external=True)
    analysis_system = ForeignReferenceField(endpoint='.analysis_system_detail',
                                            queryset=AnalysisSystem.objects(),
                                            query_parameter='identifier_name')
    is_online = Boolean()
    scheduled_analyses_count = Method("get_scheduled_analyses_count")

    class Meta(BaseSchema.Meta):
        model = AnalysisSystemInstance
        dump_only = ['id', '_cls', 'last_seen', 'scheduled_analyses_count']

    def get_scheduled_analyses_count(self, obj):
        analyses_count = ScheduledAnalysis.objects(
            analysis_system_instance=obj).count()
        return analyses_count
コード例 #10
0
ファイル: models.py プロジェクト: jdagdelen/stractapi
class Embedding:
    """
    A Mat2Vec word/phrase embedding. Embeddings are 300-dimensional vectors that represent the meaning
    of words and phrases in a mathematical way. Matstract embeddings are derived from the Word2Vec
    NLP architecture (Google, 2013). If no embedding exists for the single wordphrase, the sum of the embeddings
    of the sub-wordphrases is used.
    """

    uri = URLFor('embeddings_endpoint')
    wordphrase = fields.String()
    tag = fields.String()
    embedding = fields.List(fields.Decimal())
    compound = fields.Boolean(default=False)

    def __init__(self, wordphrase, tag, embedding, compound):
        self.wordphrase = wordphrase
        self.tag = tag
        # ndarrays aren't json serializable, for now we'll just cast to a list.
        if isinstance(embedding, np.ndarray):
            self.embedding = embedding.tolist()
        else:
            self.embedding = embedding
        self.compound = compound
コード例 #11
0
class AllSchema(ma.Schema):
    class Meta:
        fields = ('id', 'limit', 'url', 'https_url')
        model = Storage
    https_url = URLFor('pagedownloadfile', values=dict(name='<name>', _scheme='http', _external=True))
コード例 #12
0
class UrlSchema(ma.Schema):
    class Meta:
        fields = ('https_url',)
    https_url = URLFor('pagedownloadfile', values=dict(name='<name>', _scheme='http', _external=True))
コード例 #13
0
class RevisionsSchema(Schema):
    id = fields.Integer(required=True)
    actual = fields.Integer()
    url = URLFor('revisions', page_id='<page_id>', revision_id='<id>')