当前位置: 首页>>代码示例>>Python>>正文


Python api.model函数代码示例

本文整理汇总了Python中udata.api.api.model函数的典型用法代码示例。如果您正苦于以下问题:Python model函数的具体用法?Python model怎么用?Python model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_uploaded_image

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from werkzeug.datastructures import FileStorage

from udata.api import api, fields


uploaded_image_fields = api.model('UploadedImage', {
    'success': fields.Boolean(
        description='Whether the upload succeeded or not.',
        readonly=True, default=True),
    'image': fields.ImageField(),
})


image_parser = api.parser()
image_parser.add_argument('file', type=FileStorage, location='files')
image_parser.add_argument('bbox', type=str, location='form')


def parse_uploaded_image(field):
    '''Parse an uploaded image and save into a db.ImageField()'''
    args = image_parser.parse_args()

    image = args['file']
    bbox = args.get('bbox', None)
    if bbox:
        bbox = [int(float(c)) for c in bbox.split(',')]
    field.save(image, bbox=bbox)
开发者ID:anukat2015,项目名称:udata,代码行数:30,代码来源:api.py

示例2:

from udata.core.reuse.api_fields import reuse_ref_fields
from udata.core.user.api_fields import user_ref_fields
from udata.models import User, Organization, Dataset, Reuse

from .actions import request_transfer, accept_transfer, refuse_transfer
from .models import TRANSFER_STATUS, Transfer


RESPONSE_TYPES = ["accept", "refuse"]


transfer_request_fields = api.model(
    "TransferRequest",
    {
        "subject": fields.Nested(base_reference, required=True, description="The transfered subject"),
        "recipient": fields.Nested(
            base_reference, required=True, description=("The transfer recipient, " "either an user or an organization")
        ),
        "comment": fields.String(description="An explanation about the transfer request", required=True),
    },
)


transfer_response_fields = api.model(
    "TransferResponse",
    {
        "response": fields.String(description="The response", required=True, enum=RESPONSE_TYPES),
        "comment": fields.String(description="An optionnal comment about the transfer response"),
    },
)

person_mapping = {User: user_ref_fields, Organization: org_ref_fields}
开发者ID:ldolberg,项目名称:udata,代码行数:32,代码来源:api.py

示例3:

from udata.core.user.api_fields import user_ref_fields
from udata.models import User, Organization, Dataset, Reuse

from .actions import request_transfer, accept_transfer, refuse_transfer
from .models import TRANSFER_STATUS, Transfer


RESPONSE_TYPES = ['accept', 'refuse']


transfer_request_fields = api.model('TransferRequest', {
    'subject': fields.Nested(
        base_reference, required=True,
        description='The transfered subject'),
    'recipient': fields.Nested(
        base_reference, required=True,
        description=('The transfer recipient, '
                     'either an user or an organization')),
    'comment': fields.String(
        description='An explanation about the transfer request',
        required=True),
})


transfer_response_fields = api.model('TransferResponse', {
    'response': fields.String(description='The response', required=True,
                              enum=RESPONSE_TYPES),
    'comment': fields.String(
        description='An optionnal comment about the transfer response'),
})

person_mapping = {
开发者ID:javanna2000,项目名称:udata,代码行数:32,代码来源:api.py

示例4: schedulables

from celery.utils.encoding import safe_repr
from flask import request

from udata.api import api, API, fields
from udata.auth import admin_permission
from udata.tasks import schedulables, celery

from .forms import CrontabTaskForm, IntervalTaskForm
from .models import PeriodicTask, PERIODS

ns = api.namespace('workers', 'Asynchronous workers related operations', path='')

crontab_fields = api.model('Crontab', {
    'minute': fields.String(description='Cron expression for minute', required=True, default='*'),
    'hour': fields.String(description='Cron expression for hour', required=True, default='*'),
    'day_of_week': fields.String(description='Cron expression for day of week', required=True, default='*'),
    'day_of_month': fields.String(description='Cron expression for day of month', required=True, default='*'),
    'month_of_year': fields.String(description='Cron expression for month of year', required=True, default='*'),
})

interval_fields = api.model('Interval', {
    'every': fields.Integer(description='The interval without unit', required=True),
    'period': fields.String(description='The period/interval type', required=True, enum=PERIODS),
})

job_fields = api.model('Job', {
    'id': fields.String(description='The job unique identifier', readonly=True),
    'name': fields.String(description='The job unique name', required=True),
    'description': fields.String(description='The job description'),
    'task': fields.String(description='The task name', required=True, enum=[job.name for job in schedulables()]),
    'crontab': fields.Nested(crontab_fields, allow_null=True),
开发者ID:guillo-w,项目名称:udata,代码行数:31,代码来源:api.py

示例5:

from flask import current_app, request
from flask_security import current_user

from udata import tracking
from udata.api import api, API, fields
from udata.models import Follow
from udata.core.user.api_fields import user_ref_fields

from .signals import on_new_follow


follow_fields = api.model('Follow', {
    'id': fields.String(
        description='The follow object technical ID', readonly=True),
    'follower': fields.Nested(
        user_ref_fields, description='The follower', readonly=True),
    'since': fields.ISODateTime(
        description='The date from which the user started following',
        readonly=True)
})

follow_page_fields = api.model('FollowPage', fields.pager(follow_fields))

parser = api.parser()
parser.add_argument(
    'page', type=int, default=1, location='args', help='The page to fetch')
parser.add_argument(
    'page_size', type=int, default=20, location='args',
    help='The page size to fetch')

NOTE = 'Returns the number of followers left after the operation'
开发者ID:odtvince,项目名称:udata,代码行数:31,代码来源:api.py

示例6: SiteAPI

from flask import request

from udata.api import api, API, fields
from udata.auth import admin_permission
from udata.models import Dataset, Reuse

from udata.core.dataset.api_fields import dataset_fields
from udata.core.reuse.api_fields import reuse_fields

from .views import current_site

site_fields = api.model('Site', {
    'id': fields.String(
        description='The Site unique identifier', required=True),
    'title': fields.String(
        description='The site display title', required=True),
    'metrics': fields.Raw(description='The associated metrics', default={}),
})


@api.route('/site/', endpoint='site')
class SiteAPI(API):

    @api.doc(id='get_site')
    @api.marshal_with(site_fields)
    def get(self):
        '''Site-wide variables'''
        return current_site

开发者ID:odtvince,项目名称:udata,代码行数:28,代码来源:api.py

示例7: OrganizationReference

from __future__ import unicode_literals

from udata.api import api, pager, fields

from udata.core.organization.api_fields import OrganizationReference
from udata.core.dataset.api_fields import DatasetReference

from .models import REUSE_TYPES

reuse_fields = api.model('Reuse', {
    'id': fields.String(description='The reuse identifier', required=True),
    'title': fields.String(description='The reuse title', required=True),
    'slug': fields.String(description='The reuse permalink string', required=True),
    'type': fields.String(description='The reuse type', required=True, enum=REUSE_TYPES.keys()),
    'featured': fields.Boolean(description='Is the reuse featured'),
    'description': fields.String(description='The reuse description in Markdown', required=True),
    'image_url': fields.String(description='The reuse thumbnail'),
    'created_at': fields.ISODateTime(description='The reuse creation date', required=True),
    'last_modified': fields.ISODateTime(description='The reuse last modification date', required=True),
    'deleted': fields.ISODateTime(description='The organization identifier', required=True),
    'datasets': fields.List(DatasetReference, description='The reused datasets'),
    'organization': OrganizationReference(description='The publishing organization'),
    'metrics': fields.Raw(description='The reuse metrics'),
    'uri': fields.UrlFor('api.reuse', lambda o: {'reuse': o},
        description='The reuse API URI', required=True),
    'page': fields.UrlFor('reuses.show', lambda o: {'reuse': o},
        description='The reuse page URL', required=True),
})

reuse_page_fields = api.model('ReusePage', pager(reuse_fields))
开发者ID:pombredanne,项目名称:udata,代码行数:30,代码来源:api_fields.py

示例8: SiteAPI

from udata.api import api, API, fields
from udata.auth import admin_permission
from udata.models import Dataset, Reuse, Site, Activity

from udata.core.dataset.api_fields import dataset_ref_fields
from udata.core.reuse.api_fields import reuse_ref_fields
from udata.core.user.api_fields import user_ref_fields
from udata.core.organization.api_fields import org_ref_fields

from .views import current_site

site_fields = api.model('Site', {
    'id': fields.String(
        description='The Site unique identifier', required=True),
    'title': fields.String(
        description='The site display title', required=True),
    'metrics': fields.Raw(description='The associated metrics', default={}),
})


@api.route('/site/', endpoint='site')
class SiteAPI(API):

    @api.doc(id='get_site')
    @api.marshal_with(site_fields)
    def get(self):
        '''Site-wide variables'''
        return current_site

开发者ID:grouan,项目名称:udata,代码行数:28,代码来源:api.py

示例9:

from udata.core.organization.api_fields import org_ref_fields  # noqa

user_fields = api.model('User', {
    'id': fields.String(
        description='The user identifier', required=True),
    'slug': fields.String(
        description='The user permalink string', required=True),
    'first_name': fields.String(
        description='The user first name', required=True),
    'last_name': fields.String(
        description='The user last name', required=True),
    'avatar': fields.ImageField(description='The user avatar URL'),
    'website': fields.String(description='The user website'),
    'about': fields.Markdown(description='The user self description'),
    'roles': fields.List(fields.String, description='Site wide user roles'),
    'organizations': fields.List(
        fields.Nested(org_ref_fields),
        description='The organization the user belongs to'),
    'since': fields.ISODateTime(
        attribute='created_at',
        description='The registeration date', required=True),
    'page': fields.UrlFor(
        'users.show', lambda u: {'user': u},
        description='The user profile page URL', readonly=True),
    'uri': fields.UrlFor(
        'api.user', lambda o: {'user': o},
        description='The user API URI', required=True),
})

me_fields = api.inherit('Me', user_fields, {
    'email': fields.String(description='The user email', required=True),
开发者ID:michelbl,项目名称:udata,代码行数:31,代码来源:api_fields.py

示例10: pager

from __future__ import unicode_literals

from flask import url_for

from udata.api import api, pager, fields

from .models import ORG_ROLES, MEMBERSHIP_STATUS


org_fields = api.model('Organization', {
    'id': fields.String(description='The organization identifier', required=True),
    'name': fields.String(description='The organization name', required=True),
    'slug': fields.String(description='The organization string used as permalink', required=True),
    'description': fields.String(description='The organization description in Markdown', required=True),
    'created_at': fields.ISODateTime(description='The organization creation date', required=True),
    'last_modified': fields.ISODateTime(description='The organization last modification date', required=True),
    'deleted': fields.ISODateTime(description='The organization deletion date if deleted'),
    'metrics': fields.Raw(description='The organization metrics'),
    'uri': fields.UrlFor('api.organization', lambda o: {'org': o},
        description='The organization API URI', required=True),
    'page': fields.UrlFor('organizations.show', lambda o: {'org': o},
        description='The organization page URL', required=True),
})

org_page_fields = api.model('OrganizationPage', pager(org_fields))

request_fields = api.model('MembershipRequest', {
    'status': fields.String(description='The current request status', required=True,
        enum=MEMBERSHIP_STATUS.keys()),
    'comment': fields.String(description='A request comment from the user', required=True),
})
开发者ID:pombredanne,项目名称:udata,代码行数:31,代码来源:api_fields.py

示例11: import

from udata.api import api, fields, base_reference
from udata.core.badges.api import badge_fields
from udata.core.organization.api_fields import org_ref_fields
from udata.core.spatial.api_fields import spatial_coverage_fields
from udata.core.user.api_fields import user_ref_fields

from .models import (
    UPDATE_FREQUENCIES, RESOURCE_FILETYPES, DEFAULT_FREQUENCY,
    CHECKSUM_TYPES, DEFAULT_CHECKSUM_TYPE, DEFAULT_LICENSE, RESOURCE_TYPES
)

checksum_fields = api.model('Checksum', {
    'type': fields.String(
        description='The hashing algorithm used to compute the checksum',
        default=DEFAULT_CHECKSUM_TYPE, enum=CHECKSUM_TYPES),
    'value': fields.String(description="The resulting checksum/hash",
                           required=True)
})

license_fields = api.model('License', {
    'id': fields.String(description='The license identifier', required=True),
    'title': fields.String(description='The resource title', required=True),
    'maintainer': fields.String(description='The license official maintainer'),
    'url': fields.String(description='The license official URL'),
    'flags': fields.List(fields.String, description='Some arbitry flags'),
    'alternate_urls': fields.List(
        fields.String,
        description='Same alternative known URLs (improve rematch)'
    ),
    'alternate_titles': fields.List(
开发者ID:odtvince,项目名称:udata,代码行数:30,代码来源:api_fields.py

示例12: import

from . import actions
from .forms import HarvestSourceForm, HarvestSourceValidationForm
from .models import (
    HARVEST_JOB_STATUS, HARVEST_ITEM_STATUS, HarvestJob,
    VALIDATION_STATES, VALIDATION_ACCEPTED
)

ns = api.namespace('harvest', 'Harvest related operations')

backends_ids = [b.name for b in actions.list_backends()]

error_fields = api.model('HarvestError', {
    'created_at': fields.ISODateTime(description='The error creation date',
                                     required=True),
    'message': fields.String(description='The error short message',
                             required=True),
    'details': fields.String(description='Optionnal details (ie. stacktrace)'),
})

item_fields = api.model('HarvestItem', {
    'remote_id': fields.String(description='The item remote ID to process',
                               required=True),
    'dataset': fields.Nested(dataset_ref_fields,
                             description='The processed dataset',
                             allow_null=True),
    'status': fields.String(description='The item status',
                            required=True,
                            enum=HARVEST_ITEM_STATUS.keys()),
    'created': fields.ISODateTime(description='The item creation date',
                                  required=True),
开发者ID:anukat2015,项目名称:udata,代码行数:30,代码来源:api.py

示例13: URL

from udata.core.user.api_fields import user_ref_fields

from .models import REUSE_TYPES

reuse_fields = api.model('Reuse', {
    'id': fields.String(description='The reuse identifier', readonly=True),
    'title': fields.String(description='The reuse title', required=True),
    'slug': fields.String(description='The reuse permalink string', readonly=True),
    'type': fields.String(description='The reuse type', required=True, enum=REUSE_TYPES.keys()),
    'url': fields.String(description='The reuse remote URL (website)', required=True),
    'description': fields.Markdown(description='The reuse description in Markdown', required=True),
    'tags': fields.List(fields.String, description='Some keywords to help in search'),
    'featured': fields.Boolean(description='Is the reuse featured', readonly=True),
    'image': fields.ImageField(description='The reuse thumbnail'),
    'created_at': fields.ISODateTime(description='The reuse creation date', readonly=True),
    'last_modified': fields.ISODateTime(description='The reuse last modification date', readonly=True),
    'deleted': fields.ISODateTime(description='The organization identifier', readonly=True),
    'datasets': fields.List(fields.Nested(dataset_ref_fields), description='The reused datasets'),
    'organization': fields.Nested(org_ref_fields, allow_null=True,
        description='The publishing organization', readonly=True),
    'owner': fields.Nested(user_ref_fields, description='The owner user', readonly=True, allow_null=True),
    'metrics': fields.Raw(description='The reuse metrics', readonly=True),
    'uri': fields.UrlFor('api.reuse', lambda o: {'reuse': o},
        description='The reuse API URI', readonly=True),
    'page': fields.UrlFor('reuses.show', lambda o: {'reuse': o},
        description='The reuse page URL', readonly=True),
})

reuse_page_fields = api.model('ReusePage', fields.pager(reuse_fields))

reuse_suggestion_fields = api.model('ReuseSuggestion', {
开发者ID:guillo-w,项目名称:udata,代码行数:31,代码来源:api_fields.py

示例14:

from udata.api import api, API, fields
from udata.models import Dataset, DatasetIssue, Reuse, ReuseIssue
from udata.core.user.api_fields import user_ref_fields

from .forms import IssueCommentForm, IssueCreateForm
from .models import Message, Issue
from .permissions import CloseIssuePermission
from .signals import on_new_issue, on_new_issue_comment, on_issue_closed

ns = api.namespace('issues', 'Issue related operations')

message_fields = api.model('IssueMessage', {
    'content': fields.String(description='The message body', required=True),
    'posted_by': fields.Nested(
        user_ref_fields, description='The message author', required=True),
    'posted_on': fields.ISODateTime(
        description='The message posting date', required=True),
})

issue_fields = api.model('Issue', {
    'id': fields.String(description='The issue identifier', readonly=True),
    'subject': fields.String(
        attribute='subject.id',
        description='The issue target object identifier', required=True),
    'class': fields.ClassName(description='The object class',
                              discriminator=True, required=True),
    'title': fields.String(description='The issue title', required=True),
    'user': fields.Nested(
        user_ref_fields, description='The issue author', required=True),
    'created': fields.ISODateTime(
开发者ID:anukat2015,项目名称:udata,代码行数:30,代码来源:api.py

示例15:

    'logo': fields.ImageField(original=True,
        description='The organization logo URL'),
    'logo_thumbnail': fields.ImageField(attribute='logo', size=BIGGEST_LOGO_SIZE,
        description='The organization logo thumbnail URL. This is the square '
        '({0}x{0}) and cropped version.'.format(BIGGEST_LOGO_SIZE)),
})


from udata.core.user.api_fields import user_ref_fields  # noqa: required

request_fields = api.model('MembershipRequest', {
    'id': fields.String(readonly=True),
    'user': fields.Nested(user_ref_fields),
    'created': fields.ISODateTime(
        description='The request creation date', readonly=True),
    'status': fields.String(
        description='The current request status', required=True,
        enum=MEMBERSHIP_STATUS.keys()),
    'comment': fields.String(
        description='A request comment from the user', required=True),
})

member_fields = api.model('Member', {
    'user': fields.Nested(user_ref_fields),
    'role': fields.String(
        description='The member role in the organization', required=True,
        enum=ORG_ROLES.keys(), default=DEFAULT_ROLE)
})

org_fields = api.model('Organization', {
    'id': fields.String(
开发者ID:odtvince,项目名称:udata,代码行数:31,代码来源:api_fields.py


注:本文中的udata.api.api.model函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。