Exemplo n.º 1
0
 def __init__(self, paginate=True):
     self.parser = api.parser()
     # q parameter
     self.parser.add_argument('q', type=str, location='args',
                              help='The search query')
     # Sort arguments
     keys = list(self.sorts)
     choices = keys + ['-' + k for k in keys]
     help_msg = 'The field (and direction) on which sorting apply'
     self.parser.add_argument('sort', type=str, location='args',
                              choices=choices, help=help_msg)
     if paginate:
         self.parser.add_argument('page', type=int, location='args',
                                  default=1, help='The page to display')
         self.parser.add_argument('page_size', type=int, location='args',
                                  default=20, help='The page size')
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
    })

comment_discussion_fields = api.model(
    'DiscussionResponse', {
        'comment':
        fields.String(description='The comment to submit', required=True),
        'close':
        fields.Boolean(
            description=
            'Is this a closing response. Only subject owner can close')
    })

discussion_page_fields = api.model('DiscussionPage',
                                   fields.pager(discussion_fields))

parser = api.parser()
parser.add_argument('sort',
                    type=str,
                    default='-created',
                    location='args',
                    help='The sorting attribute')
parser.add_argument(
    'closed',
    type=boolean,
    location='args',
    help='Filters discussions on their closed status if specified')
parser.add_argument('for',
                    type=str,
                    location='args',
                    action='append',
                    help='Filter discussions for a given subject')
Exemplo n.º 4
0
    def delete(self, reuse):
        '''Unmark a reuse as featured'''
        reuse.featured = False
        reuse.save()
        return reuse


@ns.route('/<id>/followers/', endpoint='reuse_followers')
@ns.doc(get={'id': 'list_reuse_followers'},
        post={'id': 'follow_reuse'},
        delete={'id': 'unfollow_reuse'})
class FollowReuseAPI(FollowAPI):
    model = Reuse


suggest_parser = api.parser()
suggest_parser.add_argument('q',
                            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.doc('suggest_reuses')
    @api.expect(suggest_parser)
Exemplo n.º 5
0
)
from udata.linkchecker.checker import check_resource
from .models import (Dataset, Resource, Checksum, License, UPDATE_FREQUENCIES,
                     CommunityResource, RESOURCE_TYPES, ResourceSchema)
from .permissions import DatasetEditPermission, ResourceEditPermission
from .forms import (ResourceForm, DatasetForm, CommunityResourceForm,
                    ResourcesListForm)
from .search import DatasetSearch
from .exceptions import (SchemasCatalogNotFoundException,
                         SchemasCacheUnavailableException)

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')
Exemplo n.º 6
0
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',
Exemplo n.º 7
0
from flask import current_app
from flask_restplus import inputs

from udata import theme
from udata.api import api, API
from udata.models import db, Dataset, GeoZone, TERRITORY_DATASETS

oembed_parser = api.parser()
oembed_parser.add_argument(
    'url',
    location='args',
    required=True,
    type=inputs.url,
    help='The URL to retrieve embedding information for',
)
oembed_parser.add_argument(
    'maxwidth',
    location='args',
    help='The maximum width of the embedded resource',
)
oembed_parser.add_argument(
    'maxheight',
    location='args',
    help='The maximum height of the embedded resource',
)
oembed_parser.add_argument('format',
                           help='The required response format.',
                           location='args',
                           default='json')

oembeds_parser = api.parser()
Exemplo n.º 8
0
Arquivo: api.py Projeto: grouan/udata
    @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']
Exemplo n.º 9
0
        '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
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
Arquivo: api.py Projeto: grouan/udata
    @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
Exemplo n.º 12
0
    @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.marshal_list_with(request_fields)
    @api.doc('list_membership_requests', parser=requests_parser)
    @api.doc(responses={403: 'Not Authorized'})
Exemplo n.º 13
0
# -*- 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)
Exemplo n.º 14
0
    @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')
Exemplo n.º 15
0
    @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
Exemplo n.º 16
0
# -*- 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()
Exemplo n.º 17
0
Arquivo: api.py Projeto: grouan/udata
    @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()
Exemplo n.º 18
0
    @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')
Exemplo n.º 19
0
    @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()
Exemplo n.º 20
0
from .api_fields import (
    apikey_fields,
    me_fields,
    me_metrics_fields,
    user_fields,
    user_page_fields,
    user_suggestion_fields,
    user_role_fields,
)
from .forms import UserProfileForm, UserProfileAdminForm
from .search import UserSearch

ns = api.namespace('users', 'User related operations')
me = api.namespace('me', 'Connected user related operations')
search_parser = UserSearch.as_request_parser()
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()
Exemplo n.º 21
0
uploaded_image_fields = api.model(
    'UploadedImage', {
        'success':
        fields.Boolean(description='Whether the upload succeeded or not.',
                       readonly=True,
                       default=True),
        'image':
        fields.ImageField(),
    })

chunk_status_fields = api.model('UploadStatus', {
    'success': fields.Boolean,
    'error': fields.String
})

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

upload_parser = api.parser()
upload_parser.add_argument('file', type=FileStorage, location='files')
upload_parser.add_argument('uuid', type=str, location='form')
upload_parser.add_argument('filename', type=str, location='form')
upload_parser.add_argument('partindex', type=int, location='form')
upload_parser.add_argument('partbyteoffset', type=int, location='form')
upload_parser.add_argument('totalparts', type=int, location='form')
upload_parser.add_argument('chunksize', type=int, location='form')


class UploadStatus(Exception):
    def __init__(self, ok=True, error=None):
Exemplo n.º 22
0
from udata.core.dataset.api_fields import dataset_ref_fields

from .api_fields import (
    level_fields,
    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',
Exemplo n.º 23
0
Arquivo: api.py Projeto: vinyll/udata
    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',
Exemplo n.º 24
0
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
Exemplo n.º 25
0
Arquivo: api.py Projeto: grouan/udata
    @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)
Exemplo n.º 26
0
Arquivo: api.py Projeto: seiteta/udata
    dataset_suggestion_fields,
    frequency_fields,
    license_fields,
    resource_fields,
    upload_fields,
)
from .models import (Dataset, Resource, Checksum, License, UPDATE_FREQUENCIES,
                     CommunityResource)
from .permissions import DatasetEditPermission, ResourceEditPermission
from .forms import (ResourceForm, DatasetForm, CommunityResourceForm,
                    ResourcesListForm)
from .search import DatasetSearch

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')
Exemplo n.º 27
0
Arquivo: api.py Projeto: grouan/udata
    @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"]
Exemplo n.º 28
0
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
Exemplo n.º 29
0
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'))