示例#1
0
def activate(account, args):
    account = find(account)
    if account.activation_code != args['token']:
        raise BadRequest('Invalid activation code!')
    account.activated = True
    db.session.commit()
    login_user(account)
示例#2
0
def activate(account, args):
    account = find(account)
    if account.activation_code != args['token']:
        raise BadRequest('Invalid activation code!')
    account.activated = True
    db.session.commit()
    login_user(account)
示例#3
0
def create(owner_name, data):
    owner = account.find(owner_name)
    require.resource.create(owner)

    state = NodeSchemaState(owner_name, None)
    data_ = ResourceSchema().to_python(data, state=state)

    resource = Resource(owner, data_['name'], data_['url'], data_['summary'],
                        data_['meta'])
    db.session.add(resource)
    db.session.flush()
    index_add(resource)

    event_ = ResourceCreatedEvent(current_user, resource)
    event.emit(event_, [resource])

    if 'dataset' in data:
        from datahub.logic.dataset import add_resource
        reference = {'owner': owner_name, 'name': resource.name}
        add_resource(data['dataset']['owner'],
                     data['dataset']['name'],
                     reference,
                     in_tx=True)
    db.session.commit()
    return resource
示例#4
0
def create(owner_name, data):
    owner = account.find(owner_name)
    require.dataset.create(owner)

    state = NodeSchemaState(owner_name, None)
    data_ = DatasetSchema().to_python(data, state=state)

    dataset = Dataset(owner, data_['name'], data_['summary'],
                      data_['meta'])
    db.session.add(dataset)
    db.session.flush()
    index_add(dataset)

    event_ = DatasetCreatedEvent(current_user, dataset)
    event.emit(event_, [dataset])

    if 'resource' in data:
        add_resource(dataset.owner.name, dataset.name,
                     data['resource'], in_tx=True)

    db.session.commit()
    return dataset
示例#5
0
def list_by_owner(owner_name):
    """ Query for all datasets owned by a particular account. """
    # TODO: move to search
    owner = account.find(owner_name)
    return Dataset.query.join(Dataset.owner).filter(Account.name==owner.name)
示例#6
0
def list_by_owner(owner_name):
    """ Query for all resources owned by a particular account. """
    # TODO: move to search
    owner = account.find(owner_name)
    return Resource.query.join(
        Resource.owner).filter(Account.name == owner.name)