本文整理汇总了Python中udata.api.api.parser函数的典型用法代码示例。如果您正苦于以下问题:Python parser函数的具体用法?Python parser怎么用?Python parser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parser函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import
from .api_fields import (
apikey_fields,
me_fields,
me_metrics_fields,
user_fields,
user_page_fields,
user_suggestion_fields,
)
from .forms import UserProfileForm
from .search import UserSearch
ns = api.namespace('users', 'User related operations')
me = api.namespace('me', 'Connected user related operations')
search_parser = api.search_parser(UserSearch)
filter_parser = api.parser()
filter_parser.add_argument(
'q', type=str, help='The string to filter items',
location='args', required=False)
@me.route('/', endpoint='me')
class MeAPI(API):
@api.secure
@api.doc('get_me')
@api.marshal_with(me_fields)
def get(self):
'''Fetch the current user (me) identity'''
return current_user._get_current_object()
@api.secure
示例2: date
from udata.core.site.views import current_site
metrics_fields = api.model(
"Metric",
{
"object_id": fields.String(description="The object identifier which metrics belongs to", required=True),
"date": fields.String(description="The metrics sampling date", required=True),
"level": fields.String(description="The metrics granularity level", required=True, enum=["daily", "monthly"]),
"values": fields.Raw(description="The metrics as key-value pairs", required=True),
},
)
isodate = lambda v: date(*(int(p) for p in v.split("-"))).isoformat()
parser = api.parser()
parser.add_argument("start", type=isodate, help="Start of the period to fetch", location="args")
parser.add_argument("end", type=isodate, help="End of the period to fetch", location="args")
parser.add_argument("cumulative", type=bool, help="Either cumulative metrics or not", default=True, location="args")
parser.add_argument("day", type=isodate, help="Specific day date to fetch", location="args")
@api.route("/metrics/<id>", endpoint="metrics")
class MetricsAPI(API):
@api.doc(id="metrics_for", model=[metrics_fields], parser=parser)
@api.doc(params={"id": "The object ID to fetch metric for"})
@api.doc(description="If day is set, start and end will be ignored")
def get(self, id):
"""Fetch metrics for an object given its ID"""
if id == "site":
object_id = current_site.id
示例3: OEmbedsAPI
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from flask import current_app
from udata import theme
from udata.api import api, API, output_json
from udata.models import db, Dataset, GeoZone
oembeds_parser = api.parser()
oembeds_parser.add_argument(
'references', help='References of the resources to embed.',
location='args', required=True)
@api.route('/oembeds/', endpoint='oembeds')
class OEmbedsAPI(API):
@api.doc('oembeds', parser=oembeds_parser)
def get(self):
""" The returned payload is a list of OEmbed formatted responses.
See: http://oembed.com/
The `references` are composed by a keyword (`kind`) followed by
the `id` each of those separated by commas.
E.g: dataset-5369992aa3a729239d205183,territory-fr-town-75056-comptes
Only datasets and territories are supported for now.
"""
args = oembeds_parser.parse_args()
示例4: import
from udata.linkchecker.checker import check_resource
from .models import (
Dataset, Resource, Checksum, License, UPDATE_FREQUENCIES,
CommunityResource, RESOURCE_TYPES
)
from .permissions import DatasetEditPermission, ResourceEditPermission
from .forms import (
ResourceForm, DatasetForm, CommunityResourceForm, ResourcesListForm
)
from .search import DatasetSearch
log = logging.getLogger(__name__)
ns = api.namespace('datasets', 'Dataset related operations')
search_parser = DatasetSearch.as_request_parser()
community_parser = api.parser()
community_parser.add_argument(
'sort', type=str, default='-created', location='args',
help='The sorting attribute')
community_parser.add_argument(
'page', type=int, default=1, location='args', help='The page to fetch')
community_parser.add_argument(
'page_size', type=int, default=20, location='args',
help='The page size to fetch')
community_parser.add_argument(
'organization', type=str,
help='Filter activities for that particular organization',
location='args')
community_parser.add_argument(
'dataset', type=str,
help='Filter activities for that particular dataset',
示例5: get
@api.marshal_with(me_fields)
def get(self):
"""Fetch the current user (me) identity"""
return current_user._get_current_object()
@api.secure
@api.marshal_with(user_fields)
@api.doc("update_me", responses={400: "Validation error"})
def put(self, **kwargs):
"""Update my profile"""
user = current_user._get_current_object()
form = api.validate(UserProfileForm, user)
return form.save()
avatar_parser = api.parser()
avatar_parser.add_argument("file", type=FileStorage, location="files")
avatar_parser.add_argument("bbox", type=str, location="form")
@me.route("/avatar", endpoint="my_avatar")
@api.doc(parser=avatar_parser)
class AvatarAPI(API):
@api.secure
@api.doc("my_avatar")
@api.marshal_with(avatar_fields)
def post(self):
"""Upload a new avatar"""
args = avatar_parser.parse_args()
avatar = args["file"]
示例6: put
@api.secure
@api.doc('reorder_resources', **common_doc)
@api.expect([fields.String])
@api.marshal_with(resource_fields)
def put(self, dataset):
'''Reorder resources'''
new_resources = []
for rid in request.json:
resource = get_by(dataset.resources, 'id', UUID(rid))
new_resources.append(resource)
dataset.resources = new_resources
dataset.save()
return dataset.resources, 200
upload_parser = api.parser()
upload_parser.add_argument('file', type=FileStorage, location='files')
@ns.route('/<dataset:dataset>/upload/', endpoint='upload_resource')
@api.doc(parser=upload_parser, **common_doc)
class UploadResource(API):
@api.secure
@api.doc(id='upload_resource')
@api.marshal_with(upload_fields)
def post(self, dataset):
'''Upload a new resource'''
args = upload_parser.parse_args()
storage = storages.resources
示例7: delete
@api.doc('unfeature_reuse')
@api.secure(admin_permission)
@api.marshal_with(reuse_fields)
def delete(self, reuse):
'''Unmark a reuse as featured'''
reuse.featured = False
reuse.save()
return reuse
@ns.route('/<id>/followers/', endpoint='reuse_followers')
class FollowReuseAPI(FollowAPI):
model = FollowReuse
suggest_parser = api.parser()
suggest_parser.add_argument(
'q', type=str, help='The string to autocomplete/suggest',
location='args', required=True)
suggest_parser.add_argument(
'size', type=int, help='The amount of suggestion to fetch',
location='args', default=10)
@ns.route('/suggest/', endpoint='suggest_reuses')
class SuggestReusesAPI(API):
@api.marshal_list_with(reuse_suggestion_fields)
@api.doc(id='suggest_reuses', parser=suggest_parser)
def get(self):
'''Suggest reuses'''
args = suggest_parser.parse_args()
示例8: import
resource_fields,
upload_fields,
)
from .models import (
Dataset, Resource, FollowDataset, Checksum, License, UPDATE_FREQUENCIES,
CommunityResource
)
from .permissions import DatasetEditPermission
from .forms import (
ResourceForm, DatasetForm, CommunityResourceForm, ResourcesListForm
)
from .search import DatasetSearch
ns = api.namespace('datasets', 'Dataset related operations')
search_parser = api.search_parser(DatasetSearch)
community_parser = api.parser()
community_parser.add_argument(
'sort', type=str, default='-created', location='args',
help='The sorting attribute')
community_parser.add_argument(
'page', type=int, default=1, location='args', help='The page to fetch')
community_parser.add_argument(
'page_size', type=int, default=20, location='args',
help='The page size to fetch')
community_parser.add_argument(
'organization', type=str,
help='Filter activities for that particular organization',
location='args')
community_parser.add_argument(
'dataset', type=str,
help='Filter activities for that particular dataset',
示例9: URL
'datasets.show', lambda o: {'dataset': 'not-available'},
description='The dataset page URL (fake)'),
})
preview_item_fields = api.extend('HarvestItemPreview', item_fields, {
'dataset': fields.Nested(preview_dataset_fields,
description='The processed dataset',
allow_null=True),
})
preview_job_fields = api.extend('HarvestJobPreview', job_fields, {
'items': fields.List(fields.Nested(preview_item_fields),
description='The job collected items'),
})
source_parser = api.parser()
source_parser.add_argument('owner', type=str, location='args',
help='The organization or user ID to filter on')
@ns.route('/sources/', endpoint='harvest_sources')
class SourcesAPI(API):
@api.doc('list_harvest_sources', parser=source_parser)
@api.marshal_list_with(source_fields)
def get(self):
'''List all harvest sources'''
args = source_parser.parse_args()
return actions.list_sources(args.get('owner'))
@api.doc('create_harvest_source')
@api.secure
示例10: delete
@api.doc('unfeature_reuse')
@api.secure(admin_permission)
@api.marshal_with(reuse_fields)
def delete(self, reuse):
'''Unmark a reuse as featured'''
reuse.featured = False
reuse.save()
return reuse
@ns.route('/<id>/followers/', endpoint='reuse_followers')
class FollowReuseAPI(FollowAPI):
model = FollowReuse
suggest_parser = api.parser()
suggest_parser.add_argument(
'q', type=unicode, help='The string to autocomplete/suggest',
location='args', required=True)
suggest_parser.add_argument(
'size', type=int, help='The amount of suggestion to fetch',
location='args', default=10)
@ns.route('/suggest/', endpoint='suggest_reuses')
class SuggestReusesAPI(API):
@api.marshal_list_with(reuse_suggestion_fields)
@api.doc(id='suggest_reuses', parser=suggest_parser)
def get(self):
'''Suggest reuses'''
args = suggest_parser.parse_args()
示例11:
granularity_fields,
zone_suggestion_fields,
feature_collection_fields,
)
from .models import GeoZone, GeoLevel, spatial_granularities
GEOM_TYPES = (
'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString',
'MultiPolygon'
)
ns = api.namespace('spatial', 'Spatial references')
suggest_parser = api.parser()
suggest_parser.add_argument(
'q', type=unicode, help='The string to autocomplete/suggest',
location='args', required=True)
suggest_parser.add_argument(
'size', type=int, help='The amount of suggestion to fetch',
location='args', default=10)
dataset_parser = api.parser()
dataset_parser.add_argument(
'dynamic', type=inputs.boolean, help='Append dynamic datasets',
location='args', required=False)
dataset_parser.add_argument(
'size', type=int, help='The amount of datasets to fetch',
location='args', default=25)
示例12: put
@api.doc('reorder_resources', **common_doc)
@api.expect([fields.String])
@api.marshal_with(resource_fields)
def put(self, dataset):
'''Reorder resources'''
DatasetEditPermission(dataset).test()
new_resources = []
for rid in request.json:
resource = get_by(dataset.resources, 'id', UUID(rid))
new_resources.append(resource)
dataset.resources = new_resources
dataset.save()
return dataset.resources, 200
upload_parser = api.parser()
upload_parser.add_argument('file', type=FileStorage, location='files')
@ns.route('/<dataset:dataset>/upload/', endpoint='upload_resource')
@api.doc(parser=upload_parser, **common_doc)
class UploadResource(API):
@api.secure
@api.doc(id='upload_resource')
@api.marshal_with(upload_fields)
def post(self, dataset):
'''Upload a new resource'''
DatasetEditPermission(dataset).test()
args = upload_parser.parse_args()
storage = storages.resources
示例13: 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)
示例14: post
@api.secure(admin_permission)
def post(self, org):
'''Create a new badge for a given organization'''
return badges_api.add(org)
@ns.route('/<org:org>/badges/<badge_kind>/', endpoint='organization_badge')
class OrganizationBadgeAPI(API):
@api.doc('delete_organization_badge', **common_doc)
@api.secure(admin_permission)
def delete(self, org, badge_kind):
'''Delete a badge for a given organization'''
return badges_api.remove(org, badge_kind)
requests_parser = api.parser()
requests_parser.add_argument(
'status',
type=str,
help='If provided, only return requests ith a given status',
location='args'
)
@ns.route('/<org:org>/membership/', endpoint='request_membership',
doc=common_doc)
class MembershipRequestAPI(API):
@api.secure
@api.doc('list_membership_requests')
@api.expect(requests_parser)
@api.response(403, 'Not Authorized')
示例15: OrganizationBadgeAPI
class OrganizationBadgeAPI(API):
@api.doc("delete_organization_badge", **common_doc)
@api.secure(admin_permission)
def delete(self, org, badge_kind):
"""Delete a badge for a given organization"""
badge = None
for badge in org.badges:
if badge.kind == badge_kind:
break
if badge is None:
api.abort(404, "Badge does not exists")
org.remove_badge(badge)
return "", 204
requests_parser = api.parser()
requests_parser.add_argument(
"status", type=unicode, help="If provided, only return requests ith a given status", location="args"
)
@ns.route("/<org:org>/membership/", endpoint="request_membership", doc=common_doc)
class MembershipRequestAPI(API):
@api.secure
@api.marshal_list_with(request_fields)
@api.doc("list_membership_requests", parser=requests_parser)
@api.doc(responses={403: "Not Authorized"})
def get(self, org):
"""List membership requests for a given organization"""
OrganizationPrivatePermission(org).test()
args = requests_parser.parse_args()