Exemplo n.º 1
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
Exemplo n.º 2
0
def update(owner_name, dataset_name, data):
    dataset = find(owner_name, dataset_name)
    require.dataset.update(dataset)

    # tell availablename about our current name:
    state = NodeSchemaState(owner_name, dataset_name)
    data = DatasetSchema().to_python(data, state=state)

    dataset.name = data['name']
    dataset.summary = data['summary']
    dataset.meta = data['meta']
    index_add(dataset)

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

    db.session.commit()
    return dataset
Exemplo n.º 3
0
def register(data):
    require.account.create()
    state = AccountSchemaState(None)
    data = RegistrationSchema().to_python(data, state=state)

    user = User(data['name'], data['full_name'], data['email'],
                hash_password(data['password']))
    db.session.add(user)
    db.session.flush()
    index_add(user)

    event_ = AccountCreatedEvent(user)
    event.emit(event_)

    send_activation(user)

    db.session.commit()

    return user
Exemplo n.º 4
0
def register(data):
    require.account.create()
    state = AccountSchemaState(None)
    data = RegistrationSchema().to_python(data, state=state)

    user = User(data['name'], data['full_name'], data['email'],
                hash_password(data['password']))
    db.session.add(user)
    db.session.flush()
    index_add(user)

    event_ = AccountCreatedEvent(user)
    event.emit(event_)

    send_activation(user)

    db.session.commit()

    return user
Exemplo n.º 5
0
def update(owner_name, resource_name, data):
    resource = find(owner_name, resource_name)
    require.resource.update(resource)

    # tell availablename about our current name:
    state = NodeSchemaState(owner_name, resource_name)
    data = ResourceSchema().to_python(data, state=state)

    resource.name = data['name']
    resource.url = data['url']
    resource.summary = data['summary']
    resource.meta = data['meta']
    index_add(resource)

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

    db.session.commit()

    return resource
Exemplo n.º 6
0
def update(account_name, data):
    """ Update an account's data. """
    account = find(account_name)
    require.account.update(account)

    # tell availablename about our current name:
    state = AccountSchemaState(account_name)
    data = AccountSchema().to_python(data, state=state)

    account.name = data['name']
    account.full_name = data['full_name']
    if 'email' in data and data['email'] is not None:
        account.email = data['email']
    index_add(account)

    # FIXME: use current_user, not owner.
    event_ = AccountUpdatedEvent(account)
    event.emit(event_)

    db.session.commit()
    return account
Exemplo n.º 7
0
def update(account_name, data):
    """ Update an account's data. """
    account = find(account_name)
    require.account.update(account)

    # tell availablename about our current name:
    state = AccountSchemaState(account_name)
    data = AccountSchema().to_python(data, state=state)

    account.name = data['name']
    account.full_name = data['full_name']
    if 'email' in data and data['email'] is not None:
        account.email = data['email']
    index_add(account)

    # FIXME: use current_user, not owner.
    event_ = AccountUpdatedEvent(account)
    event.emit(event_)

    db.session.commit()
    return account
Exemplo n.º 8
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
Exemplo n.º 9
0
def update(user, data):
    require.account.update(user)

    # TODO combine with account.update
    state = AccountSchemaState(user.name)
    data = ProfileSchema().to_python(data, state=state)

    user.name = data['name']
    user.full_name = data['full_name']
    user.email = data['email']
    if data['password']:
        user.password = hash_password(data['password'])

    db.session.add(user)
    index_add(user)

    event_ = AccountUpdatedEvent(current_user)
    event.emit(event_)

    db.session.commit()

    return user
Exemplo n.º 10
0
def update(user, data):
    require.account.update(user)

    # TODO combine with account.update
    state = AccountSchemaState(user.name)
    data = ProfileSchema().to_python(data, state=state)

    user.name = data['name']
    user.full_name = data['full_name']
    user.email = data['email']
    if data['password']:
        user.password = hash_password(data['password'])

    db.session.add(user)
    index_add(user)

    event_ = AccountUpdatedEvent(current_user)
    event.emit(event_)

    db.session.commit()

    return user
Exemplo n.º 11
0
def rebuild():
    """ Rebuild the search index for all nodes. """
    for node in Node.query:
        index_add(node)
Exemplo n.º 12
0
def rebuild():
    """ Rebuild the search index for all accounts. """
    for account in Account.query:
        index_add(account)
Exemplo n.º 13
0
def rebuild():
    """ Rebuild the search index for all accounts. """
    for account in Account.query:
        index_add(account)
Exemplo n.º 14
0
def rebuild():
    """ Rebuild the search index for all nodes. """
    for node in Node.query:
        index_add(node)