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(
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') def backends_ids(): return [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':
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'), 'badges': fields.List(fields.Nested(badge_fields), description='The reuse badges', readonly=True), 'featured': fields.Boolean(description='Is the reuse featured', readonly=True), 'private': fields.Boolean( description='Is the reuse private to the owner or the organization' ), '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), })
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'
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}
post_fields = api.model('Post', { 'id': fields.String(description='The post identifier'), 'name': fields.String(description='The post name', required=True), 'slug': fields.String( description='The post permalink string', readonly=True), 'headline': fields.String(description='The post headline', required=True), 'content': fields.Markdown( description='The post content in Markdown', required=True), 'image': fields.ImageField(description='The post image', readonly=True), 'credit_to': fields.String( description='An optional credit line (associated to the image)'), 'credit_url': fields.String( description='An optional link associated to the credits'), 'tags': fields.List( fields.String, description='Some keywords to help in search'), 'datasets': fields.List( fields.Nested(dataset_fields), description='The post datasets'), 'reuses': fields.List( fields.Nested(reuse_fields), description='The post reuses'), 'owner': fields.Nested( user_ref_fields, description='The owner user', readonly=True, allow_null=True), 'created_at': fields.ISODateTime( description='The post creation date', readonly=True), 'last_modified': fields.ISODateTime( description='The post last modification date', readonly=True), 'published': fields.ISODateTime( description='The post publication date', readonly=True), 'uri': fields.UrlFor( 'api.post', lambda o: {'post': o}, description='The post API URI', readonly=True), 'page': fields.UrlFor( 'posts.show', lambda o: {'post': o}, description='The post page URL', readonly=True, fallback_endpoint='api.post'), }, mask='*,datasets{id,title,acronym,uri,page},reuses{id,title,image,image_thumbnail,uri,page}')
from udata.api import api, API, fields from udata.core.user.api_fields import user_ref_fields from .forms import DiscussionCreateForm, DiscussionCommentForm from .models import Message, Discussion from .permissions import CloseDiscussionPermission from .signals import ( on_new_discussion, on_new_discussion_comment, on_discussion_closed, on_discussion_deleted ) ns = api.namespace('discussions', 'Discussion related operations') message_fields = api.model('DiscussionMessage', { 'content': fields.String(description='The message body'), 'posted_by': fields.Nested(user_ref_fields, description='The message author'), 'posted_on': fields.ISODateTime(description='The message posting date'), }) discussion_fields = api.model('Discussion', { 'id': fields.String(description='The discussion identifier'), 'subject': fields.Nested(api.model_reference, description='The discussion target object'), 'class': fields.ClassName(description='The object class', discriminator=True), 'title': fields.String(description='The discussion title'), 'user': fields.Nested( user_ref_fields, description='The discussion author'), 'created': fields.ISODateTime(description='The discussion creation date'), 'closed': fields.ISODateTime(description='The discussion closing date'), 'closed_by': fields.Nested(user_ref_fields, allow_null=True,
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', {
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),
from udata.api import api, fields, API from udata.auth import current_user from .actions import get_notifications notifs = api.namespace('notifications', 'Notifications API') notifications_fields = api.model( 'Notification', { 'type': fields.String(description='The notification type', readonly=True), 'created_on': fields.ISODateTime(description='The notification creation datetime', readonly=True), 'details': fields.Raw( description='Key-Value details depending on notification type', readonly=True) }) @notifs.route('/', endpoint='notifications') class NotificationsAPI(API): @api.secure @api.doc('get_notifications') @api.marshal_list_with(notifications_fields) def get(self): '''List all current user pending notifications''' user = current_user._get_current_object() return get_notifications(user)
topic_fields = api.model('Topic', { 'id': fields.String(description='The topic identifier'), 'name': fields.String(description='The topic name', required=True), 'slug': fields.String( description='The topic permalink string', readonly=True), 'description': fields.Markdown( description='The topic description in Markdown', required=True), 'tags': fields.List( fields.String, description='Some keywords to help in search', required=True), 'datasets': fields.List( fields.Nested(dataset_fields), description='The topic datasets'), 'reuses': fields.List( fields.Nested(reuse_fields), description='The topic reuses'), 'featured': fields.Boolean(description='Is the topic featured'), 'private': fields.Boolean(description='Is the topic private'), 'created_at': fields.ISODateTime( description='The topic creation date', readonly=True), 'last_modified': fields.ISODateTime( description='The topic last modification date', readonly=True), 'deleted': fields.ISODateTime( description='The organization identifier', readonly=True), 'owner': fields.Nested( user_ref_fields, description='The owner user', readonly=True, allow_null=True), 'uri': fields.UrlFor( 'api.topic', lambda o: {'topic': o}, description='The topic API URI', readonly=True), 'page': fields.UrlFor( 'topics.display', lambda o: {'topic': o}, description='The topic page URL', readonly=True), }, mask='*,datasets{id,title,uri,page},reuses{id,title, image, image_thumbnail,uri,page}')
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')
# -*- 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)
# -*- coding: utf-8 -*- from __future__ import unicode_literals from udata.api import api, fields, API from udata.auth import current_user from .actions import get_notifications notifs = api.namespace('notifications', 'Notifications API') notifications_fields = api.model('Notification', { 'type': fields.String(description='The notification type', readonly=True), 'created_on': fields.ISODateTime( description='The notification creation datetime', readonly=True), 'details': fields.Raw( description='Key-Value details depending on notification type', readonly=True) }) @notifs.route('/', endpoint='notifications') class NotificationsAPI(API): @api.secure @api.doc('get_notifications') @api.marshal_list_with(notifications_fields) def get(self): '''List all current user pending notifications''' user = current_user._get_current_object() return get_notifications(user)
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(
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), })
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
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(
from flask import request from flask.ext.security import current_user from udata.api import api, API, marshal, fields from udata.core.user.api_fields import UserReference from .forms import IssueCreateForm, IssueCommentForm from .models import Issue, Message, ISSUE_TYPES from .signals import on_new_issue, on_issue_closed message_fields = api.model('IssueMessage', { 'content': fields.String(description='The message body', required=True), 'posted_by': UserReference(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', required=True), 'type': fields.String(description='The issue type', required=True, enum=ISSUE_TYPES.keys()), 'subject': fields.String(attribute='subject.id', description='The issue target object identifier', required=True), 'user': UserReference(description='The issue author', required=True), 'created': fields.ISODateTime(description='The issue creation date', required=True), 'closed': fields.ISODateTime(description='The issue closing date'), 'closed_by': fields.String(attribute='closed_by.id', description='The user who closed the issue'), 'discussion': fields.Nested(message_fields), 'url': fields.UrlFor('api.issue', description='The issue API URI', required=True), })
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
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),
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
org_ref_fields = api.inherit('OrganizationReference', base_reference, { 'name': fields.String(description='The organization name', readonly=True), 'uri': fields.UrlFor('api.organization', lambda o: {'org': o}, description='The organization API URI', readonly=True), 'page': fields.UrlFor('organizations.show', lambda o: {'org': o}, description='The organization web page URL', readonly=True), 'logo': fields.ImageField(size=100, description='The organization logo URL'), }) from udata.core.user.api_fields import user_ref_fields 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()) }) org_fields = api.model('Organization', { 'id': fields.String(description='The organization identifier', required=True), 'name': fields.String(description='The organization name', required=True), 'acronym': fields.String(description='The organization acronym'),
# -*- coding: utf-8 -*- from __future__ import unicode_literals from udata.api import api, API, fields from udata.auth import admin_permission from . import actions from .models import HARVEST_JOB_STATUS, HARVEST_ITEM_STATUS, HarvestJob ns = api.namespace('harvest', 'Harvest related operations') 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), 'status': fields.String(description='The item status', required=True, enum=HARVEST_ITEM_STATUS.keys()), 'created': fields.ISODateTime(description='The item creation date', required=True), 'started': fields.ISODateTime(description='The item start date'), 'ended': fields.ISODateTime(description='The item end date'), 'errors': api.as_list(fields.Nested(error_fields, description='The item errors')), 'args': fields.List(fields.String, description='The item positional arguments', default=[]), 'kwargs': fields.Raw(description='The item keyword arguments', default={}), }) source_fields = api.model('HarvestSource', { 'id': fields.String(description='The source unique identifier', required=True), 'name': fields.String(description='The source display name', required=True),
from __future__ import unicode_literals from udata.api import api, fields, base_reference 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 (DATASET_BADGE_KINDS, UPDATE_FREQUENCIES, RESOURCE_TYPES, DEFAULT_FREQUENCY, CHECKSUM_TYPES, DEFAULT_CHECKSUM_TYPE, DEFAULT_LICENSE) 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'),
fields.String(description='The GeoJSON Type', required=True, enum=GEOM_TYPES), 'coordinates': fields.List(fields.Raw(), description='The geometry as coordinates lists', required=True), }) class GeoJSON(fields.Raw): pass feature_fields = api.model( 'GeoJSONFeature', { 'id': fields.String, 'type': fields.String(required=True, enum=['Feature']), 'geometry': GeoJSON(required=True), 'properties': fields.Raw, }) feature_collection_fields = api.model( 'GeoJSONFeatureCollection', { 'type': fields.String(required=True, enum=['FeatureCollection']), 'features': api.as_list(fields.Nested(feature_fields)) }) level_fields = api.model( 'TerritoryLevel', { 'id': fields.String(description='The level identifier', required=True), 'label':
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 = {
topic_fields = api.model( 'Topic', { 'id': fields.String(description='The topic identifier'), 'name': fields.String(description='The topic name', required=True), 'slug': fields.String(description='The topic permalink string', readonly=True), 'description': fields.Markdown(description='The topic description in Markdown', required=True), 'tags': fields.List(fields.String, description='Some keywords to help in search', required=True), 'datasets': fields.List(fields.Nested(dataset_fields), description='The topic datasets'), 'reuses': fields.List(fields.Nested(reuse_fields), description='The topic reuses'), 'featured': fields.Boolean(description='Is the topic featured'), 'private': fields.Boolean(description='Is the topic private'), 'created_at': fields.ISODateTime(description='The topic creation date', readonly=True), 'last_modified': fields.ISODateTime(description='The topic last modification date', readonly=True), 'deleted': fields.ISODateTime(description='The organization identifier', readonly=True), 'owner': fields.Nested(user_ref_fields, description='The owner user', readonly=True, allow_null=True), 'uri': fields.UrlFor('api.topic', lambda o: {'topic': o}, description='The topic API URI', readonly=True), 'page': fields.UrlFor('topics.display', lambda o: {'topic': o}, description='The topic page URL', readonly=True), }, mask= '*,datasets{id,title,uri,page},reuses{id,title, image, image_thumbnail,uri,page}' )
# -*- coding: utf-8 -*- from __future__ import unicode_literals from flask import url_for from udata.api import api, fields from udata.core.organization.api_fields import OrganizationReference user_fields = api.model('User', { 'id': fields.String(description='The user identifier', required=True), 'slug': fields.String(description='The user permalink string', required=True), 'email': fields.String(description='The user email', 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_url': fields.String(description='The user avatar URL'), 'website': fields.String(description='The user website'), 'about': fields.String(description='The user self description'), 'organizations': fields.List(OrganizationReference, description='The organization the user belongs to'), }) @api.model(fields={ 'id': fields.String(description='The user identifier', required=True), 'first_name': fields.String(description='The user first name', required=True), 'last_name': fields.String(description='The user larst name', required=True), 'page': fields.String(description='The user profile page URL', required=True), 'avatar_url': fields.String(description='The user avatar URL'), }) class UserReference(fields.Raw): def format(self, user):
from udata.api import api, fields from .forms import badge_form badge_fields = api.model( 'Badge', { 'kind': fields.String(description=('Kind of badge (certified, etc), ' 'specific to each model'), required=True), }) def add(obj): ''' Handle a badge add API. - Expecting badge_fieds as payload - Return the badge as payload - Return 200 if the badge is already - Return 201 if the badge is added ''' Form = badge_form(obj.__class__) form = api.validate(Form) kind = form.kind.data badge = obj.get_badge(kind) if badge: return badge else: return obj.add_badge(kind), 201
ns = api.namespace('posts', 'Posts related operations') post_fields = api.model('Post', { 'id': fields.String(description='The post identifier'), 'name': fields.String(description='The post name', required=True), 'slug': fields.String(description='The post permalink string', readonly=True), 'headline': fields.String(description='The post headline', required=True), 'content': fields.Markdown(description='The post content in Markdown', required=True), 'image': fields.ImageField(description='The post image'), 'credit_to': fields.String(description='An optionnal credit line (associated to the image)'), 'credit_url': fields.String(description='An optionnal link associated to the credits'), 'tags': fields.List(fields.String, description='Some keywords to help in search'), 'datasets': fields.List(fields.Nested(dataset_ref_fields), description='The post datasets'), 'reuses': fields.List(fields.Nested(reuse_ref_fields), description='The post reuses'), 'owner': fields.Nested(user_ref_fields, description='The owner user', readonly=True, allow_null=True), 'private': fields.Boolean(description='Is the post visible'), 'created_at': fields.ISODateTime(description='The post creation date', readonly=True), 'last_modified': fields.ISODateTime(description='The post last modification date', readonly=True), 'uri': fields.UrlFor('api.post', lambda o: {'post': o}, description='The post API URI', readonly=True), 'page': fields.UrlFor('posts.show', lambda o: {'post': o}, description='The post page URL', readonly=True), }) post_page_fields = api.model('PostPage', fields.pager(post_fields))
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), 'email': fields.Raw(attribute=lambda o: o.email if current_user_is_admin_or_self() else None, description='The user email', readonly=True), 'avatar': fields.ImageField(original=True, description='The user avatar URL'), 'avatar_thumbnail': fields.ImageField( attribute='avatar', size=BIGGEST_AVATAR_SIZE, description='The user avatar thumbnail URL. This is the square ' '({0}x{0}) and cropped version.'.format(BIGGEST_AVATAR_SIZE)), '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'), 'active': fields.Boolean(), '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, fallback_endpoint='api.user'), 'uri': fields.UrlFor('api.user', lambda o: {'user': o}, description='The user API URI', required=True), 'metrics': fields.Raw(attribute=lambda o: o.get_metrics(), description='The user metrics', readonly=True), })
activity_fields = api.model( 'Activity', { 'actor': fields.Nested(user_ref_fields, description='The user who performed the action', readonly=True), 'organization': fields.Nested(org_ref_fields, allow_null=True, readonly=True, description='The organization who performed the action'), 'related_to': fields.String(attribute='related_to', description='The activity target name', required=True), 'related_to_id': fields.String(attribute='related_to.id', description='The activity target object identifier', required=True), 'related_to_kind': fields.String(attribute='related_to.__class__.__name__', description='The activity target object class name', required=True), 'related_to_url': fields.String(attribute='related_to.display_url', description='The activity target model', required=True), 'created_at': fields.ISODateTime(description='When the action has been performed', readonly=True), 'label': fields.String(description='The label of the activity', required=True), 'key': fields.String(description='The key of the activity', required=True), 'icon': fields.String(description='The icon of the activity', required=True), 'kwargs': fields.Raw(description='Some action specific context'), })
from flask import json from werkzeug.datastructures import FileStorage from udata.api import api, fields from . import utils, chunks META = 'meta.json' IMAGES_MIMETYPES = ('image/jpeg', 'image/png', 'image/webp') 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()
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'),
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),
from flask_restful.inputs import boolean from udata.api import api, API, marshal, fields from udata.models import Metrics 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), }) def isodate(value): return date(*(int(p) for p in value.split('-'))).isoformat() parser = api.parser() parser.add_argument('start',
'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(
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))
from udata.core.organization.api_fields import org_ref_fields 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'), 'metrics': fields.Raw(description='Th last user metrics'), '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, {
'page': fields.UrlFor( 'organizations.show', lambda o: {'org': o}, description='The organization web page URL', readonly=True), 'logo': fields.ImageField( size=100, description='The organization logo URL'), }) 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()) }) org_fields = api.model('Organization', { 'id': fields.String(
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=list(MEMBERSHIP_STATUS)), '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',
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_TYPES, DEFAULT_FREQUENCY, CHECKSUM_TYPES, DEFAULT_CHECKSUM_TYPE, DEFAULT_LICENSE ) 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'), }) frequency_fields = api.model('Frequency', { 'id': fields.String(description='The frequency identifier'), 'label': fields.String(description='The frequency display name')
activity_fields = api.model('Activity', { 'actor': fields.Nested( user_ref_fields, description='The user who performed the action', readonly=True), 'organization': fields.Nested( org_ref_fields, allow_null=True, readonly=True, description='The organization who performed the action'), 'related_to': fields.String( attribute='related_to', description='The activity target name', required=True), 'related_to_id': fields.String( attribute='related_to.id', description='The activity target object identifier', required=True), 'related_to_kind': fields.String( attribute='related_to.__class__.__name__', description='The activity target object class name', required=True), 'related_to_url': fields.String( attribute='related_to.display_url', description='The activity target model', required=True), 'created_at': fields.ISODateTime( description='When the action has been performed', readonly=True), 'label': fields.String( description='The label of the activity', required=True), 'key': fields.String( description='The key of the activity', required=True), 'icon': fields.String( description='The icon of the activity', required=True), 'kwargs': fields.Raw(description='Some action specific context'), })
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=list(REUSE_TYPES)), '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'), 'badges': fields.List(fields.Nested(badge_fields), description='The reuse badges', readonly=True), 'topic': fields.String( description='The reuse topic', required=True, enum=list(REUSE_TOPICS)), 'featured': fields.Boolean(description='Is the reuse featured', readonly=True), 'private': fields.Boolean( description='Is the reuse private to the owner or the organization'), 'image': fields.ImageField( description='The reuse thumbnail thumbnail (cropped) URL'), 'image_thumbnail': fields.ImageField( attribute='image', size=BIGGEST_IMAGE_SIZE, description='The reuse thumbnail thumbnail URL. This is the square ' '({0}x{0}) and cropped version.'.format(BIGGEST_IMAGE_SIZE)), '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_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(attribute=lambda o: o.get_metrics(), 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, fallback_endpoint='api.reuse'), }, mask='*,datasets{title,uri,page}')
from udata.core.organization.api_fields import org_ref_fields activity_fields = api.model( "Activity", { "actor": fields.Nested(user_ref_fields, description="The user who performed the action", readonly=True), "organization": fields.Nested( org_ref_fields, allow_null=True, readonly=True, description="The organization who performed the action" ), "related_to": fields.String(attribute="related_to", description="The activity target name", required=True), "related_to_id": fields.String( attribute="related_to.id", description="The activity target object identifier", required=True ), "related_to_kind": fields.String( attribute="related_to.__class__.__name__", description="The activity target object class name", required=True, ), "related_to_url": fields.String( attribute="related_to.display_url", description="The activity target model", required=True ), "created_at": fields.ISODateTime(description="When the action has been performed", readonly=True), "label": fields.String(description="The label of the activity", required=True), "key": fields.String(description="The key of the activity", required=True), "icon": fields.String(description="The icon of the activity", required=True), "kwargs": fields.Raw(description="Some action specific context"), }, ) activity_page_fields = api.model("ActivityPage", fields.pager(activity_fields))
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
from udata.api import api, API, marshal, fields from udata.core.user.api_fields import user_ref_fields from .forms import IssueCreateForm, IssueCommentForm from .models import Issue, Message, ISSUE_TYPES 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), 'type': fields.String(description='The issue type', required=True, enum=ISSUE_TYPES.keys()), 'subject':
post_fields = api.model( 'Post', { 'id': fields.String(description='The post identifier'), 'name': fields.String(description='The post name', required=True), 'slug': fields.String(description='The post permalink string', readonly=True), 'headline': fields.String(description='The post headline', required=True), 'content': fields.Markdown(description='The post content in Markdown', required=True), 'image': fields.ImageField(description='The post image'), 'credit_to': fields.String( description='An optionnal credit line (associated to the image)'), 'credit_url': fields.String( description='An optionnal link associated to the credits'), 'tags': fields.List(fields.String, description='Some keywords to help in search'), 'datasets': fields.List(fields.Nested(dataset_ref_fields), description='The post datasets'), 'reuses': fields.List(fields.Nested(reuse_ref_fields), description='The post reuses'), 'owner': fields.Nested(user_ref_fields, description='The owner user', readonly=True, allow_null=True), 'private': fields.Boolean(description='Is the post visible'), 'created_at': fields.ISODateTime(description='The post creation date', readonly=True), 'last_modified': fields.ISODateTime(description='The post last modification date', readonly=True), 'uri': fields.UrlFor('api.post', lambda o: {'post': o}, description='The post API URI', readonly=True), 'page': fields.UrlFor('posts.show', lambda o: {'post': o}, description='The post page URL', readonly=True), })
# -*- coding: utf-8 -*- from __future__ import unicode_literals from udata.api import api, fields GEOM_TYPES = ( 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon' ) geojson = api.model('GeoJSON', { 'type': fields.String( description='The GeoJSON Type', required=True, enum=GEOM_TYPES), 'coordinates': fields.List( fields.Raw(), description='The geometry as coordinates lists', required=True), }) feature_fields = api.model('GeoJSONFeature', { 'id': fields.String, 'type': fields.String(required=True, enum=['Feature']), 'geometry': fields.Nested(geojson, required=True), 'properties': fields.Raw, }) feature_collection_fields = api.model('GeoJSONFeatureCollection', { 'type': fields.String(required=True, enum=['FeatureCollection']), 'features': fields.List(fields.Nested(feature_fields), required=True) })
from datetime import date from flask_restful.inputs import boolean from udata.api import api, API, marshal, fields from udata.models import Metrics 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), }) def isodate(value): return date(*(int(p) for p in value.split('-'))).isoformat() parser = api.parser() parser.add_argument( 'start', type=isodate, help='Start of the period to fetch', location='args') parser.add_argument(
# -*- coding: utf-8 -*- from __future__ import unicode_literals from udata.api import api, fields badge_fields = api.model('Badge', { 'kind': fields.String(description=('Kind of badge (certified, etc), ' 'specific to each model'), required=True), })
from udata.api import api, API, fields from udata.core.user.api_fields import user_ref_fields from .forms import DiscussionCreateForm, DiscussionCommentForm from .models import Message, Discussion from .permissions import CloseDiscussionPermission from .signals import (on_new_discussion, on_new_discussion_comment, on_discussion_closed, on_discussion_deleted) ns = api.namespace('discussions', 'Discussion related operations') message_fields = api.model( 'DiscussionMessage', { 'content': fields.String(description='The message body'), 'posted_by': fields.Nested(user_ref_fields, description='The message author'), 'posted_on': fields.ISODateTime(description='The message posting date'), }) discussion_fields = api.model( 'Discussion', { 'id': fields.String(description='The discussion identifier'), 'subject': fields.Nested(api.model_reference, description='The discussion target object'), 'class': fields.ClassName(description='The object class', discriminator=True), 'title':
from __future__ import unicode_literals from bson import ObjectId from datetime import date from udata.api import api, API, marshal, fields from udata.models import Metrics 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")
from udata.api import api, API, fields 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.Nested(api.model_reference, description='The issue target object', required=True), 'class':