def post(self): '''Create a new scheduled job''' if 'crontab' in request.json and 'interval' in request.json: api.abort(400, 'Cannot define both interval and crontab schedule') if 'crontab' in request.json: form = api.validate(CrontabTaskForm) else: form = api.validate(IntervalTaskForm) return form.save(), 201
def put(self, id): '''Update a single scheduled job''' task = self.get_or_404(id) if 'crontab' in request.json: task.interval = None task.crontab = PeriodicTask.Crontab() form = api.validate(CrontabTaskForm, task) else: task.crontab = None task.interval = PeriodicTask.Interval() form = api.validate(IntervalTaskForm, task) return form.save()
def post(self, dataset): '''Create a new resource for a given dataset''' form = api.validate(ResourceForm) resource = Resource() form.populate_obj(resource) dataset.add_resource(resource) return resource, 201
def put(self, org): """Update a organization given its identifier""" if org.deleted: api.abort(410, "Organization has been deleted") EditOrganizationPermission(org).test() form = api.validate(OrganizationForm, org) return form.save()
def put(self, reuse): '''Update a given reuse''' if reuse.deleted: api.abort(410, 'This reuse has been deleted') ReuseEditPermission(reuse).test() form = api.validate(ReuseForm, reuse) return form.save()
def post(self, ident): '''Validate or reject an harvest source''' form = api.validate(HarvestSourceValidationForm) if form.state.data == VALIDATION_ACCEPTED: return actions.validate_source(ident, form.comment.data) else: return actions.reject_source(ident, form.comment.data)
def put(self, dataset): '''Update a dataset given its identifier''' if dataset.deleted: api.abort(410, 'Dataset has been deleted') DatasetEditPermission(dataset).test() form = api.validate(DatasetForm, dataset) return form.save()
def post(self): '''Create a new harvests source''' form = api.validate(HarvestSourceForm) if form.organization.data: EditOrganizationPermission(form.organization.data).test() source = actions.create_source(**form.data) return source, 201
def put(self, dataset, rid): '''Update a given resource on a given dataset''' resource = self.get_resource_or_404(dataset, rid) form = api.validate(ResourceForm, resource) form.populate_obj(resource) resource.modified = datetime.now() dataset.save() return resource
def put(self, reuse): '''Update a given reuse''' request_deleted = request.json.get('deleted', True) if reuse.deleted and request_deleted is not None: api.abort(410, 'This reuse has been deleted') ReuseEditPermission(reuse).test() form = api.validate(ReuseForm, reuse) return form.save()
def put(self, dataset): '''Update a dataset given its identifier''' request_deleted = request.json.get('deleted', True) if dataset.deleted and request_deleted is not None: api.abort(410, 'Dataset has been deleted') DatasetEditPermission(dataset).test() dataset.last_modified = datetime.now() form = api.validate(DatasetForm, dataset) return form.save()
def put(self, community): '''Update a given community resource''' form = api.validate(CommunityResourceForm, community) form.populate_obj(community) if not community.organization: community.owner = current_user._get_current_object() community.modified = datetime.now() community.save() return community
def put(self, org, user): '''Update member status into a given organization.''' EditOrganizationPermission(org).test() member = org.member(user) form = api.validate(MemberForm, member) form.populate_obj(member) org.save() return member
def post(self, dataset): '''Create a new resource for a given dataset''' ResourceEditPermission(dataset).test() form = api.validate(ResourceForm) resource = Resource() form.populate_obj(resource) dataset.add_resource(resource) dataset.last_modified = datetime.now() dataset.save() return resource, 201
def post(self, org): """Create a new badge for a given organization""" Form = badge_form(Organization) form = api.validate(Form) badge = Badge(created=datetime.now(), created_by=current_user.id) form.populate_obj(badge) for existing_badge in org.badges: if existing_badge.kind == badge.kind: return existing_badge org.add_badge(badge) return badge, 201
def post(self, reuse): '''Create a new badge for a given reuse''' form = api.validate(BadgeForm) badge = ReuseBadge(created=datetime.now(), created_by=current_user.id) form.populate_obj(badge) for existing_badge in reuse.badges: if existing_badge.kind == badge.kind: return existing_badge reuse.add_badge(badge) return badge, 201
def post(self, dataset): '''Create a new badge for a given dataset''' Form = badge_form(Dataset) form = api.validate(Form) badge = Badge(created=datetime.now(), created_by=current_user.id) form.populate_obj(badge) for existing_badge in dataset.badges: if existing_badge.kind == badge.kind: return existing_badge dataset.add_badge(badge) return badge, 201
def put(self, org): ''' Update a organization given its identifier :raises PermissionDenied: ''' request_deleted = request.json.get('deleted', True) if org.deleted and request_deleted is not None: api.abort(410, 'Organization has been deleted') EditOrganizationPermission(org).test() form = api.validate(OrganizationForm, org) return form.save()
def post(self, org, user): '''Add a member into a given organization.''' EditOrganizationPermission(org).test() if org.is_member(user): return org.member(user), 409 member = Member(user=user) form = api.validate(MemberForm, member) form.populate_obj(member) org.members.append(member) org.save() return member, 201
def post(self, org, id): '''Refuse user membership to a given organization.''' membership_request = self.get_or_404(org, id) form = api.validate(MembershipRefuseForm) membership_request.status = 'refused' membership_request.handled_by = current_user._get_current_object() membership_request.handled_on = datetime.now() membership_request.refusal_comment = form.comment.data org.save() return {}, 200
def post(self): '''Create a new Discussion''' form = api.validate(DiscussionCreateForm) message = Message( content=form.comment.data, posted_by=current_user.id) discussion = Discussion(user=current_user.id, discussion=[message]) form.populate_obj(discussion) discussion.save() on_new_discussion.send(discussion) return discussion, 201
def post(self): '''Create a new community resource''' form = api.validate(CommunityResourceForm) resource = CommunityResource() form.populate_obj(resource) if not resource.dataset: api.abort(400, errors={ 'dataset': 'A dataset identifier is required' }) if not resource.organization: resource.owner = current_user._get_current_object() resource.modified = datetime.now() resource.save() return resource, 201
def post(self, id): '''Create a new Issue for an object given its ID''' form = api.validate(IssueCreateForm) message = Message(content=form.comment.data, posted_by=current_user.id) issue = self.model.objects.create( subject=id, type=form.type.data, user=current_user.id, discussion=[message] ) on_new_issue.send(issue) return marshal(issue, issue_fields), 201
def post(self): '''Create a new Issue''' form = api.validate(IssueCreateForm) message = Message( content=form.comment.data, posted_by=current_user.id ) issue = Issue(user=current_user.id, discussion=[message]) form.populate_obj(issue) issue.save() on_new_issue.send(issue) return issue, 201
def post(self, org, id): """Refuse user membership to a given organization.""" EditOrganizationPermission(org).test() membership_request = self.get_or_404(org, id) form = api.validate(MembershipRefuseForm) membership_request.status = "refused" membership_request.handled_by = current_user._get_current_object() membership_request.handled_on = datetime.now() membership_request.refusal_comment = form.comment.data org.save() notify_membership_response.delay(org, membership_request) return {}, 200
def post(self, org): '''Apply for membership to a given organization.''' membership_request = org.pending_request(current_user._get_current_object()) code = 200 if membership_request else 201 form = api.validate(MembershipRequestForm, membership_request) if not membership_request: membership_request = MembershipRequest() org.requests.append(membership_request) form.populate_obj(membership_request) org.save() return membership_request, code
def post(self, id): '''Add comment and optionnaly close an issue given its ID''' issue = Issue.objects.get_or_404(id=id) form = api.validate(IssueCommentForm) issue.discussion.append(Message( content=form.comment.data, posted_by=current_user.id )) close = form.close.data if close: issue.closed_by = current_user._get_current_object() issue.closed = datetime.now() issue.save() if close: on_issue_closed.send(issue) return marshal(issue, issue_fields), 200
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
def post(self, id): '''Add comment and optionnaly close an issue given its ID''' issue = Issue.objects.get_or_404(id=id) form = api.validate(IssueCommentForm) message = Message( content=form.comment.data, posted_by=current_user.id ) issue.discussion.append(message) close = form.close.data if close: CloseIssuePermission(issue).test() issue.closed_by = current_user._get_current_object() issue.closed = datetime.now() issue.save() if close: on_issue_closed.send(issue, message=message) else: on_new_issue_comment.send(issue, message=message) return issue
def post(self, id): '''Add comment and optionally close a discussion given its ID''' discussion = Discussion.objects.get_or_404(id=id) form = api.validate(DiscussionCommentForm) message = Message( content=form.comment.data, posted_by=current_user.id ) discussion.discussion.append(message) close = form.close.data if close: CloseDiscussionPermission(discussion).test() discussion.closed_by = current_user._get_current_object() discussion.closed = datetime.now() discussion.save() if close: on_discussion_closed.send(discussion, message=message) else: on_new_discussion_comment.send(discussion, message=message) return discussion
def put(self): api.validate(FakeForm) return {'success': True}
def put(self, topic): '''Update a given topic''' form = api.validate(TopicForm, topic) return form.save()
def put(self, ident): '''Create a new harvests source''' source = actions.get_source(ident) form = api.validate(HarvestSourceForm, source) source = actions.update_source(ident, form.data) return source
def post(self): '''Create a new organization''' form = api.validate(OrganizationForm) organization = form.save() return organization, 201
def post(self): '''Create a new object''' form = api.validate(ReuseForm) return form.save(), 201
def post(self): '''Preview an harvesting from a source created with the given payload''' form = api.validate(HarvestSourceForm) if form.organization.data: EditOrganizationPermission(form.organization.data).test() return actions.preview_from_config(**form.data)
def post(self): '''Create a topic''' form = api.validate(TopicForm) return form.save(), 201
def put(self, reuse): '''Update a given reuse''' ReuseEditPermission(reuse).test() form = api.validate(ReuseForm, reuse) return form.save()
def post(self): '''Create a new object''' form = api.validate(UserProfileAdminForm) user = form.save() return user, 201
def put(self, **kwargs): '''Update my profile''' user = current_user._get_current_object() form = api.validate(UserProfileForm, user) return form.save()
def put(self, user): '''Update a user given its identifier''' form = api.validate(UserProfileAdminForm, user) return form.save()
def post(self): '''Create a new dataset''' form = api.validate(DatasetForm) dataset = form.save() return dataset, 201
def post(self): '''Create a post''' form = api.validate(PostForm) return form.save(), 201
def put(self, post): '''Update a given post''' form = api.validate(PostForm, post) return form.save()
def post(self): class FakeForm(Form): pass api.validate(FakeForm) return {'success': True}