示例#1
0
文件: api.py 项目: guillo-w/udata
 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
示例#2
0
文件: api.py 项目: guillo-w/udata
 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()
示例#3
0
文件: api.py 项目: guillo-w/udata
 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
示例#4
0
文件: api.py 项目: javanna2000/udata
 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()
示例#5
0
文件: api.py 项目: anukat2015/udata
 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()
示例#6
0
文件: api.py 项目: anukat2015/udata
 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)
示例#7
0
文件: api.py 项目: javanna2000/udata
 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()
示例#8
0
文件: api.py 项目: anukat2015/udata
 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
示例#9
0
文件: api.py 项目: guillo-w/udata
 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
示例#10
0
文件: api.py 项目: odtvince/udata
 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()
示例#11
0
文件: api.py 项目: opendatateam/udata
 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()
示例#12
0
文件: api.py 项目: vinyll/udata
 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
示例#13
0
文件: api.py 项目: opendatateam/udata
    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
示例#14
0
文件: api.py 项目: opendatateam/udata
 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
示例#15
0
文件: api.py 项目: javanna2000/udata
 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
示例#16
0
文件: api.py 项目: grouan/udata
 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
示例#17
0
文件: api.py 项目: javanna2000/udata
 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
示例#18
0
文件: api.py 项目: opendatateam/udata
    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()
示例#19
0
文件: api.py 项目: opendatateam/udata
    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
示例#20
0
文件: api.py 项目: pombredanne/udata
    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
示例#21
0
文件: api.py 项目: opendatateam/udata
    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
示例#22
0
文件: api.py 项目: opendatateam/udata
 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
示例#23
0
文件: api.py 项目: pombredanne/udata
    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
示例#24
0
文件: api.py 项目: opendatateam/udata
    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
示例#25
0
文件: api.py 项目: javanna2000/udata
    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
示例#26
0
文件: api.py 项目: pombredanne/udata
    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
示例#27
0
文件: api.py 项目: pombredanne/udata
 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
示例#28
0
文件: api.py 项目: anukat2015/udata
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
示例#29
0
文件: api.py 项目: anukat2015/udata
 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
示例#30
0
文件: api.py 项目: opendatateam/udata
 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
示例#31
0
 def put(self):
     api.validate(FakeForm)
     return {'success': True}
示例#32
0
 def put(self, topic):
     '''Update a given topic'''
     form = api.validate(TopicForm, topic)
     return form.save()
示例#33
0
 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
示例#34
0
 def post(self):
     '''Create a new organization'''
     form = api.validate(OrganizationForm)
     organization = form.save()
     return organization, 201
示例#35
0
文件: api.py 项目: seiteta/udata
 def post(self):
     '''Create a new object'''
     form = api.validate(ReuseForm)
     return form.save(), 201
示例#36
0
 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)
示例#37
0
 def post(self):
     '''Create a topic'''
     form = api.validate(TopicForm)
     return form.save(), 201
示例#38
0
文件: api.py 项目: guillo-w/udata
 def put(self, reuse):
     '''Update a given reuse'''
     ReuseEditPermission(reuse).test()
     form = api.validate(ReuseForm, reuse)
     return form.save()
示例#39
0
 def post(self):
     '''Create a new object'''
     form = api.validate(UserProfileAdminForm)
     user = form.save()
     return user, 201
示例#40
0
 def put(self, **kwargs):
     '''Update my profile'''
     user = current_user._get_current_object()
     form = api.validate(UserProfileForm, user)
     return form.save()
示例#41
0
 def put(self, user):
     '''Update a user given its identifier'''
     form = api.validate(UserProfileAdminForm, user)
     return form.save()
示例#42
0
 def post(self):
     '''Create a new dataset'''
     form = api.validate(DatasetForm)
     dataset = form.save()
     return dataset, 201
示例#43
0
文件: api.py 项目: opendatateam/udata
 def post(self):
     '''Create a post'''
     form = api.validate(PostForm)
     return form.save(), 201
示例#44
0
 def put(self, post):
     '''Update a given post'''
     form = api.validate(PostForm, post)
     return form.save()
示例#45
0
 def post(self):
     class FakeForm(Form):
         pass
     api.validate(FakeForm)
     return {'success': True}