本文整理汇总了Python中udata.api.api.abort函数的典型用法代码示例。如果您正苦于以下问题:Python abort函数的具体用法?Python abort怎么用?Python abort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: put
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()
开发者ID:javanna2000,项目名称:udata,代码行数:7,代码来源:api.py
示例2: put
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()
开发者ID:anukat2015,项目名称:udata,代码行数:7,代码来源:api.py
示例3: delete
def delete(self, org):
'''Delete a organization given its identifier'''
if org.deleted:
api.abort(410, 'Organization has been deleted')
EditOrganizationPermission(org).test()
org.deleted = datetime.now()
org.save()
return '', 204
开发者ID:opendatateam,项目名称:udata,代码行数:8,代码来源:api.py
示例4: put
def put(self):
'''Set the homepage datasets editorial selection'''
if not isinstance(request.json, list):
api.abort(400, 'Expect a list of dataset IDs')
ids = [ObjectId(id) for id in request.json]
Site.objects(id=current_site.id).update(set__settings__home_datasets=ids)
current_site.reload()
return current_site.settings.home_datasets
开发者ID:guillo-w,项目名称:udata,代码行数:8,代码来源:api.py
示例5: put
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()
开发者ID:odtvince,项目名称:udata,代码行数:8,代码来源:api.py
示例6: delete
def delete(self, org):
"""Delete a organization given its identifier"""
if org.deleted:
api.abort(410, "Organization has been deleted")
EditOrganizationPermission(org).test()
org.deleted = datetime.now()
org.save()
return "", 204
开发者ID:javanna2000,项目名称:udata,代码行数:8,代码来源:api.py
示例7: delete
def delete(self, reuse):
'''Delete a given reuse'''
if reuse.deleted:
api.abort(410, 'This reuse has been deleted')
ReuseEditPermission(reuse).test()
reuse.deleted = datetime.now()
reuse.save()
return '', 204
开发者ID:anukat2015,项目名称:udata,代码行数:8,代码来源:api.py
示例8: get
def get(self, user):
'''Get a user given its identifier'''
if current_user.is_anonymous or not current_user.sysadmin:
if not user.active:
api.abort(410, 'User is not active')
if user.deleted:
api.abort(410, 'User has been deleted')
return user
开发者ID:odtvince,项目名称:udata,代码行数:8,代码来源:api.py
示例9: delete
def delete(self, user):
'''Delete a user given its identifier'''
if user.deleted:
api.abort(410, 'User has already been deleted')
if user == current_user._get_current_object():
api.abort(403, 'You cannot delete yourself with this API. ' +
'Use the "me" API instead.')
user.mark_as_deleted()
return '', 204
开发者ID:odtvince,项目名称:udata,代码行数:9,代码来源:api.py
示例10: post
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
开发者ID:guillo-w,项目名称:udata,代码行数:9,代码来源:api.py
示例11: put
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()
开发者ID:opendatateam,项目名称:udata,代码行数:9,代码来源:api.py
示例12: delete
def delete(self, org, badge_kind):
'''Delete a badge for a given organization'''
badge = None
for badge in org.badges:
if badge.kind == badge_kind:
break
if badge is None:
api.abort(404, 'Badge does not exists')
org.remove_badge(badge)
return '', 204
开发者ID:grouan,项目名称:udata,代码行数:10,代码来源:api.py
示例13: remove
def remove(obj, kind):
'''
Handle badge removal API
- Returns 404 if the badge for this kind is absent
- Returns 204 on success
'''
if not obj.get_badge(kind):
api.abort(404, 'Badge does not exists')
obj.remove_badge(kind)
return '', 204
开发者ID:anukat2015,项目名称:udata,代码行数:11,代码来源:api.py
示例14: handle_upload
def handle_upload(self, dataset):
prefix = '/'.join((dataset.slug,
datetime.now().strftime('%Y%m%d-%H%M%S')))
infos = handle_upload(storages.resources, prefix)
if 'html' in infos['mime']:
api.abort(415, 'Incorrect file content type: HTML')
infos['title'] = os.path.basename(infos['filename'])
infos['checksum'] = Checksum(type='sha1', value=infos.pop('sha1'))
infos['filesize'] = infos.pop('size')
del infos['filename']
return infos
开发者ID:opendatateam,项目名称:udata,代码行数:11,代码来源:api.py
示例15: post
def post(self, reuse):
'''Add a dataset to a given reuse'''
if 'id' not in request.json:
api.abort(400, 'Expect a dataset identifier')
try:
dataset = Dataset.objects.get_or_404(id=request.json['id'])
except Dataset.DoesNotExist:
api.abort(404, 'Dataset {0} does not exists'.format(request.json['id']))
if dataset in reuse.datasets:
return reuse
reuse.datasets.append(dataset)
reuse.save()
return reuse, 201
开发者ID:anukat2015,项目名称:udata,代码行数:13,代码来源:api.py
示例16: post
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
开发者ID:opendatateam,项目名称:udata,代码行数:14,代码来源:api.py
示例17: extract_infos_from_args
def extract_infos_from_args(self, args, dataset):
prefix = '/'.join((dataset.slug,
datetime.now().strftime('%Y%m%d-%H%M%S')))
storage = storages.resources
uploaded_file = args['file']
if 'html' in uploaded_file.content_type:
api.abort(415, 'Incorrect file content type: HTML')
filename = storage.save(uploaded_file, prefix=prefix)
extension = fileutils.extension(filename)
uploaded_file.seek(0)
sha1 = storages.utils.sha1(uploaded_file)
filesize = (os.path.getsize(storage.path(filename))
if storage.root else None)
return {
'title': os.path.basename(filename),
'url': storage.url(filename, external=True),
'checksum': Checksum(type='sha1', value=sha1),
'format': extension,
'mime': storages.utils.mime(filename),
'filesize': filesize
}
开发者ID:vinyll,项目名称:udata,代码行数:21,代码来源:api.py
示例18: get
def get(self):
""" The returned payload is a list of OEmbed formatted responses.
See: http://oembed.com/
The `references` are composed by a keyword (`kind`) followed by
the `id` each of those separated by commas.
E.g: dataset-5369992aa3a729239d205183,territory-fr-town-75056-comptes
Only datasets and territories are supported for now.
"""
args = oembeds_parser.parse_args()
references = args['references'].split(',')
result = []
for item_reference in references:
try:
item_kind, item_id = item_reference.split('-', 1)
except ValueError:
return api.abort(400, 'Invalid ID.')
if item_kind == 'dataset':
try:
item = Dataset.objects.get(id=item_id)
except (db.ValidationError, Dataset.DoesNotExist):
return api.abort(400, 'Unknown dataset ID.')
elif (item_kind == 'territory' and
current_app.config.get('ACTIVATE_TERRITORIES')):
from udata.models import TERRITORY_DATASETS
try:
country, town, code, kind = item_id.split('-')
except ValueError:
return api.abort(400, 'Invalid territory ID.')
try:
geozone = GeoZone.objects.get(code=code)
except GeoZone.DoesNotExist:
return api.abort(400, 'Unknown territory identifier.')
if kind in TERRITORY_DATASETS:
item = TERRITORY_DATASETS[kind](geozone)
else:
return api.abort(400, 'Unknown kind of territory.')
else:
return api.abort(400, 'Invalid object type.')
width = maxwidth = 1000
height = maxheight = 200
html = theme.render('embed-dataset.html', **{
'width': width,
'height': height,
'item': item,
'item_reference': item_reference,
})
result.append({
'type': 'rich',
'version': '1.0',
'html': html,
'width': width,
'height': height,
'maxwidth': maxwidth,
'maxheight': maxheight,
})
return output_json(result, 200)
开发者ID:michelbl,项目名称:udata,代码行数:59,代码来源:api.py
示例19: get
def get(self):
"""
An OEmbed compliant API endpoint
See: http://oembed.com/
Support datasets and reuses URLs
"""
args = oembed_parser.parse_args()
if args['format'] != 'json':
api.abort(501, 'Only JSON format is supported')
url = args['url']
# Fix flask not detecting URL with https://domain:443/
if 'https:' in url and ':443/' in url:
url = url.replace(':443/', '/')
with current_app.test_request_context(url) as ctx:
if not ctx.request.endpoint:
api.abort(404, 'Unknown URL')
endpoint = ctx.request.endpoint.replace('_redirect', '')
view_args = ctx.request.view_args
if endpoint not in self.ROUTES:
api.abort(404, 'Unknown URL')
param = self.ROUTES[endpoint]
item = view_args[param]
if isinstance(item, Exception):
raise item
width = maxwidth = 1000
height = maxheight = 200
params = {
'width': width,
'height': height,
'item': item,
'type': param
}
params[param] = item
html = theme.render('oembed.html', **params)
return {
'type': 'rich',
'version': '1.0',
'html': html,
'width': width,
'height': height,
'maxwidth': maxwidth,
'maxheight': maxheight,
}
开发者ID:opendatateam,项目名称:udata,代码行数:50,代码来源:api.py
示例20: post
def post(self, id):
'''Follow an user given its ID'''
if id == str(current_user.id):
api.abort(403, "You can't follow yourself")
return super(FollowUserAPI, self).post(id)
开发者ID:pombredanne,项目名称:udata,代码行数:5,代码来源:api.py
注:本文中的udata.api.api.abort函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论