本文整理汇总了Python中openspending.model.Dataset.by_label方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.by_label方法的具体用法?Python Dataset.by_label怎么用?Python Dataset.by_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.Dataset
的用法示例。
在下文中一共展示了Dataset.by_label方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_from_databank
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_label [as 别名]
def load_from_databank(sourcejson, dataproviderjson, dry_run=False, overwrite=True, meta_only=False, file_dir = None):
print "Working on ", sourcejson['fields']['indicator']
dataorg = DataOrg.by_name(dataproviderjson['fields']['title'])
dataorgMeta = {
'description': dataproviderjson['fields']['description'],
'label': dataproviderjson['fields']['title']
}
if not dataorg:
dataorg = DataOrg(dataorgMeta)
db.session.add(dataorg)
#dataorg will update with id here
db.session.commit()
#get or create dataset
dataset = Dataset.by_label(sourcejson['fields']['indicator'])
description = "http://databank.edip-maps.net/admin/etldata/dataconnection/" + str(sourcejson['pk']) + "/"
modelDataset = {'dataset':
{
'label': sourcejson['fields']['indicator'],
'name': sourcejson['fields']['indicator'],
'description': description,
'dataType': sourcejson['fields']['data_type'],
'dataorg_id': dataorg.id
}
}
if not dataset:
#create one
dataset = Dataset(modelDataset['dataset'])
#dataset.ORoperations = dataproviderjson['fields'].get('ORoperations', {})
#dataset.data = dataproviderjson['fields'].get('mapping',{})
db.session.add(dataset)
else:
#dataset.ORoperations = dataproviderjson['fields'].get('ORoperations', {})
#dataset.data = dataproviderjson['fields'].get('mapping',{})
dataset.update(modelDataset['dataset'])
db.session.commit()
systemaccount = Account.by_id(1)
if dataset.source:
try:
print "trying to delete source"
print dataset.source
dataset.source.delete()
except Exception, e:
print "could not delete source", e
示例2: DataOrg
# 需要导入模块: from openspending.model import Dataset [as 别名]
# 或者: from openspending.model.Dataset import by_label [as 别名]
f.close()
metadata = []
dataconnections = []
for obj in djangodump:
if obj['model'] == "etldata.metadata":
metadata.append(obj)
elif obj['model'] == "etldata.dataconnection":
dataconnections.append(obj)
for dataobj in dataconnections:
datasetflask = Dataset.by_label(dataobj['fields']['indicator'])
if not datasetflask:
print "Could not find ", dataobj['fields']['indicator']
continue
print "\nworking on ", datasetflask
for met in metadata:
if dataobj['fields']['metadata'] == met['pk']:
dataorgobj = DataOrg.by_name(met['fields']['title'])
if not dataorgobj:
#create new one
datasetflask = DataOrg({"label":met['fields']['title'], "description":met['fields']['description']})
db.session.add(datasetflask)
datasetflask.dataorg = datasetflask
print "created a new one"
else: