本文整理汇总了Python中openspending.model.dataset.Dataset.private方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.private方法的具体用法?Python Dataset.private怎么用?Python Dataset.private使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.private方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from openspending.model.dataset import Dataset [as 别名]
# 或者: from openspending.model.dataset.Dataset import private [as 别名]
def create(self):
"""
Adds a new dataset dynamically through a POST request
"""
# User must be authenticated so we should have a user object in
# c.account, if not abort with error message
if not c.account:
abort(status_code=400, detail='user not authenticated')
# Check if the params are there ('metadata', 'csv_file')
if len(request.params) != 2:
abort(status_code=400, detail='incorrect number of params')
metadata = request.params['metadata'] \
if 'metadata' in request.params \
else abort(status_code=400, detail='metadata is missing')
csv_file = request.params['csv_file'] \
if 'csv_file' in request.params \
else abort(status_code=400, detail='csv_file is missing')
# We proceed with the dataset
try:
model = json.load(urllib2.urlopen(metadata))
except:
abort(status_code=400, detail='JSON model could not be parsed')
try:
log.info("Validating model")
model = validate_model(model)
except Invalid as i:
log.error("Errors occured during model validation:")
for field, error in i.asdict().items():
log.error("%s: %s", field, error)
abort(status_code=400, detail='Model is not well formed')
dataset = Dataset.by_name(model['dataset']['name'])
if dataset is None:
dataset = Dataset(model)
require.dataset.create()
dataset.managers.append(c.account)
dataset.private = True # Default value
db.session.add(dataset)
else:
require.dataset.update(dataset)
log.info("Dataset: %s", dataset.name)
source = Source(dataset=dataset, creator=c.account, url=csv_file)
log.info(source)
for source_ in dataset.sources:
if source_.url == csv_file:
source = source_
break
db.session.add(source)
db.session.commit()
# Send loading of source into celery queue
load_source.delay(source.id)
return to_jsonp(dataset_apply_links(dataset.as_dict()))
示例2: load_with_model_and_csv
# 需要导入模块: from openspending.model.dataset import Dataset [as 别名]
# 或者: from openspending.model.dataset.Dataset import private [as 别名]
def load_with_model_and_csv(self, metadata, csv_file, private):
"""
Load a dataset using a metadata model file and a csv file
"""
if metadata is None:
response.status = 400
return to_jsonp({'errors': 'metadata is missing'})
if csv_file is None:
response.status = 400
return to_jsonp({'errors': 'csv_file is missing'})
# We proceed with the dataset
try:
model = json.load(urllib2.urlopen(metadata))
except:
response.status = 400
return to_jsonp({'errors': 'JSON model could not be parsed'})
try:
log.info("Validating model")
model = validate_model(model)
except Invalid as i:
log.error("Errors occured during model validation:")
for field, error in i.asdict().items():
log.error("%s: %s", field, error)
response.status = 400
return to_jsonp({'errors': 'Model is not well formed'})
dataset = Dataset.by_name(model['dataset']['name'])
if dataset is None:
dataset = Dataset(model)
require.dataset.create()
dataset.managers.append(c.account)
dataset.private = private
db.session.add(dataset)
else:
require.dataset.update(dataset)
log.info("Dataset: %s", dataset.name)
source = Source(dataset=dataset, creator=c.account,
url=csv_file)
log.info(source)
for source_ in dataset.sources:
if source_.url == csv_file:
source = source_
break
db.session.add(source)
db.session.commit()
# Send loading of source into celery queue
load_source.delay(source.id)
return to_jsonp(dataset_apply_links(dataset.as_dict()))
示例3: create
# 需要导入模块: from openspending.model.dataset import Dataset [as 别名]
# 或者: from openspending.model.dataset.Dataset import private [as 别名]
def create(self):
"""
Adds a new dataset dynamically through a POST request
"""
# User must be authenticated so we should have a user object in
# c.account, if not abort with error message
if not c.account:
abort(status_code=400, detail='user not authenticated')
# Parse the loading api parameters to get them into the right format
parser = LoadingAPIParamParser(request.params)
params, errors = parser.parse()
if errors:
response.status = 400
return to_jsonp({'errors': errors})
if params['metadata'] is None:
response.status = 400
return to_jsonp({'errors': 'metadata is missing'})
if params['csv_file'] is None:
response.status = 400
return to_jsonp({'errors': 'csv_file is missing'})
# We proceed with the dataset
try:
model = json.load(urllib2.urlopen(params['metadata']))
except:
response.status = 400
return to_jsonp({'errors': 'JSON model could not be parsed'})
try:
log.info("Validating model")
model = validate_model(model)
except Invalid as i:
log.error("Errors occured during model validation:")
for field, error in i.asdict().items():
log.error("%s: %s", field, error)
response.status = 400
return to_jsonp({'errors': 'Model is not well formed'})
dataset = Dataset.by_name(model['dataset']['name'])
if dataset is None:
dataset = Dataset(model)
require.dataset.create()
dataset.managers.append(c.account)
dataset.private = params['private']
db.session.add(dataset)
else:
require.dataset.update(dataset)
log.info("Dataset: %s", dataset.name)
source = Source(dataset=dataset, creator=c.account,
url=params['csv_file'])
log.info(source)
for source_ in dataset.sources:
if source_.url == params['csv_file']:
source = source_
break
db.session.add(source)
db.session.commit()
# Send loading of source into celery queue
load_source.delay(source.id)
return to_jsonp(dataset_apply_links(dataset.as_dict()))
示例4: create_budget_data_package
# 需要导入模块: from openspending.model.dataset import Dataset [as 别名]
# 或者: from openspending.model.dataset.Dataset import private [as 别名]
def create_budget_data_package(url, user, private):
try:
bdpkg = BudgetDataPackage(url)
except Exception as problem:
# Lots of different types of problems can arise with a
# BudgetDataPackage, but their message should be understandable
# so we catch just any Exception and email it's message to the user
log.error("Failed to parse budget data package: {0}".format(
problem.message))
return []
sources = []
for (idx, resource) in enumerate(bdpkg.resources):
dataset = Dataset.by_name(bdpkg.name)
if dataset is None:
# Get information from the descriptior file for the given
# resource (at index idx)
info = get_dataset_info_from_descriptor(bdpkg, idx)
# Set the dataset name based on the previously computed one
info['dataset']['name'] = bdpkg.name
# Create the model from the resource schema
model = create_model_from_schema(resource.schema)
# Set the default value for the time to the fiscal year of the
# resource, because it isn't included in the budget CSV so we
# won't be able to load it along with the data.
model['time']['default_value'] = resource.fiscalYear
# Add the model as the mapping
info['mapping'] = model
# Create the dataset
dataset = Dataset(info)
dataset.managers.append(user)
dataset.private = private
db.session.add(dataset)
db.session.commit()
else:
if not dataset.can_update(user):
log.error(
"User {0} not permitted to update dataset {1}".format(
user.name, bdpkg.name))
return []
if 'url' in resource:
resource_url = resource.url
elif 'path' in resource:
if 'base' in bdpkg:
resource_url = urlparse.urljoin(bdpkg.base, resource.path)
else:
resource_url = urlparse.urljoin(url, resource.path)
else:
log.error('Url not found')
return []
# We do not re-add old sources so if we find the same source
# we don't do anything, else we create the source and append it
# to the source list
for dataset_source in dataset.sources:
if dataset_source.url == resource_url:
break
else:
source = Source(dataset=dataset, creator=user,
url=resource_url)
db.session.add(source)
db.session.commit()
sources.append(source)
return sources