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' # related_to = db.ReferenceField(db.DomainModel, required=True) 'created_at': fields.ISODateTime(description='When the action has been performed', readonly=True), 'kwargs': fields.Raw(description='Some action specific context'), }) activity_page_fields = api.model('ActivityPage', fields.pager(activity_fields)) activity_parser = api.page_parser() @api.route('/site/activity', endpoint='site_activity') class SiteActivityAPI(API): @api.doc('site_activity', parser=activity_parser) @api.marshal_list_with(activity_page_fields) def get(self): '''Fetch site activity'''
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), 'interval': fields.Nested(interval_fields, allow_null=True), 'args': fields.List(fields.Raw, description='The job execution arguments', default=[]), 'kwargs': fields.Raw(description='The job execution keyword arguments', default={}), 'schedule': fields.String(attribute='schedule_display', description='The schedule display', readonly=True), 'last_run_at': fields.ISODateTime(description='The last job execution date', readonly=True), 'last_run_id': fields.String(description='The last execution task id', readonly=True), 'enabled': fields.Boolean(description='Is this job enabled', default=False), }) task_fields = api.model('Task', { 'id': fields.String(description='Tha task execution ID', readonly=True), 'status': fields.String(description='Cron expression for hour', readonly=True, enum=list(states.ALL_STATES)), 'result': fields.String(description='The task results if exists'), 'exc': fields.String(description='The exception thrown during execution'), 'traceback': fields.String(description='The execution traceback'), }) @ns.route('/jobs/', endpoint='jobs') class JobsAPI(API):
'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':
'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}') post_page_fields = api.model('PostPage', fields.pager(post_fields))
description='The organization string used as permalink', required=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 # 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', {
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') 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),
'flags': fields.List(fields.String, description='Some arbitry flags'), }) resource_fields = api.model('Resource', { 'id': fields.String(description='The resource unique ID', readonly=True), 'title': fields.String(description='The resource title', required=True), 'description': fields.Markdown(description='The resource markdown description'), 'type': fields.String(description='Whether the resource is an uploaded file, a remote file or an API', required=True, enum=RESOURCE_TYPES.keys()), 'format': fields.String(description='The resource format', required=True), 'url': fields.String(description='The resource URL', required=True), 'checksum': fields.Nested(checksum_fields, allow_null=True, description='A checksum to validate file validity'), 'size': fields.Integer(description='The resource file size in bytes'), 'mime': fields.String(description='The resource mime type'), 'created_at': fields.ISODateTime(description='The resource creation date', readonly=True), 'last_modified': fields.ISODateTime(attribute='modified', description='The resource last modification date', readonly=True), 'metrics': fields.Raw(description='The resource metrics', readonly=True), }) upload_fields = api.extend('UploadedResource', resource_fields, { 'success': fields.Boolean(description='Whether the upload succeeded or not.', readonly=True, default=True), # 'error': fields.String(description='An error message if success is false', readonly=True), }) resources_order = api.as_list(fields.String(description='Resource ID')) temporal_coverage_fields = api.model('TemporalCoverage', { 'start': fields.ISODateTime(description='The temporal coverage start date', required=True), 'end': fields.ISODateTime(description='The temporal coverage end date', 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, { 'email': fields.String(description='The user email', required=True), 'apikey': fields.String(description='The user API Key', readonly=True), }) apikey_fields = api.model('ApiKey', {
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': fields.String(attribute='subject.id', description='The issue target object identifier', required=True), '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, fallback_endpoint='api.topic'), }, mask='*,datasets{id,title,uri,page},reuses{id,title, image, image_thumbnail,uri,page}')
# -*- 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 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.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',
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, description='The user who closed the discussion'),
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), })
help='query string to search through resources titles') common_doc = { 'params': {'dataset': 'The dataset ID or slug'} } dataset_fields = apiv2.model('Dataset', { 'id': fields.String(description='The dataset identifier', readonly=True), 'title': fields.String(description='The dataset title', required=True), 'acronym': fields.String(description='An optional dataset acronym'), 'slug': fields.String( description='The dataset permalink string', required=True), 'description': fields.Markdown( description='The dataset description in markdown', required=True), 'created_at': fields.ISODateTime( description='The dataset creation date', required=True), 'last_modified': fields.ISODateTime( description='The dataset last modification date', required=True), 'deleted': fields.ISODateTime(description='The deletion date if deleted'), 'archived': fields.ISODateTime(description='The archival date if archived'), 'featured': fields.Boolean(description='Is the dataset featured'), 'private': fields.Boolean( description='Is the dataset private to the owner or the organization'), 'tags': fields.List(fields.String), 'badges': fields.List(fields.Nested(badge_fields), description='The dataset badges', readonly=True), 'resources': fields.Raw(attribute=lambda o: { 'rel': 'subsection', 'href': url_for('apiv2.resources', dataset=o.id, page=1, page_size=DEFAULT_PAGE_SIZE, _external=True), 'type': 'GET',
required=True, enum=RESOURCE_TYPES.keys()), 'format': fields.String(description='The resource format', required=True), 'url': fields.String(description='The resource URL', required=True), 'checksum': fields.Nested(checksum_fields, allow_null=True, description='A checksum to validate file validity'), 'size': fields.Integer(description='The resource file size in bytes'), 'mime': fields.String(description='The resource mime type'), 'created_at': fields.ISODateTime(readonly=True, description='The resource creation date'), 'published': fields.ISODateTime(description='The resource publication date'), 'last_modified': fields.ISODateTime(attribute='modified', readonly=True, description='The resource last modification date'), 'metrics': fields.Raw(description='The resource metrics', readonly=True), }) upload_fields = api.extend( 'UploadedResource', resource_fields, { 'success': fields.Boolean(description='Whether the upload succeeded or not.', readonly=True,
description=('The user or organization currently owning ' 'the transfered object')), 'recipient': fields.Polymorph(person_mapping, readonly=True, description=('The user or organization receiving ' 'the transfered object')), 'subject': fields.Polymorph(subject_mapping, readonly=True, description='The transfered object'), 'comment': fields.String(readonly=True, description='A comment about the transfer request'), 'created': fields.ISODateTime(description='The transfer request date', readonly=True), 'status': fields.String(enum=TRANSFER_STATUS.keys(), description='The current transfer request status'), 'responded': fields.ISODateTime(description='The transfer response date', readonly=True), 'reponse_comment': fields.String(readonly=True, description='A comment about the transfer response'), }) ns = api.namespace('transfer') @ns.route('/', endpoint='transfers')
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'),
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', 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), }) discussion_fields = api.model('Discussion', { 'id': fields.String( description='The discussion identifier', readonly=True), 'subject': fields.Nested(api.model_reference, description='The discussion target object', required=True), 'class': fields.ClassName(description='The object class', discriminator=True, required=True), 'title': fields.String(description='The discussion title', required=True), 'user': fields.Nested( user_ref_fields, description='The discussion author', required=True), 'created': fields.ISODateTime( description='The discussion creation date', readonly=True),