Ejemplo n.º 1
0
Archivo: sites.py Proyecto: mmg1/SOSA
def list_sites(username, password):
    ctx_auth = AuthenticationContext(url)
    if ctx_auth.acquire_token_for_user(username, password):
        request = ClientRequest(ctx_auth)
        options = RequestOptions("{0}/_api/web/".format(url))
        options.set_header('Accept', 'application/json')
        options.set_header('Content-Type', 'application/json')
        data = request.execute_query_direct(options)
        s = json.loads(data.content)
        web_title = s['Title']
        return "Web title: " + web_title
    else:
        return ctx_auth.get_last_error()
        'X-HTTP-Method': 'MERGE'
    }
    request.execute_query_direct(request_url=request_url, headers=headers, data=item_payload)
    print "Task has been successfully [updated]"


def delete_list_item(web_url, ctx_auth, list_title, item_id):
    """Delete list item example"""
    request = ClientRequest(web_url, ctx_auth)
    request_url = "{0}/_api/web/lists/getbyTitle('{1}')/items({2})".format(web_url, list_title, item_id)
    print "Deleting list item..."
    headers = {
        'IF-MATCH': '*',
        'X-HTTP-Method': 'DELETE'
    }
    request.execute_query_direct(request_url=request_url, headers=headers)
    print "Task has been successfully [deleted]"


if __name__ == '__main__':
    context_auth = AuthenticationContext(url=settings['url'])
    if context_auth.acquire_token_for_user(username=settings['username'], password=settings['password']):

        read_list_items(settings['url'], context_auth, "Tasks")
        task_item = create_list_item(settings['url'], context_auth, "Tasks")
        update_list_item(settings['url'], context_auth, "Tasks", task_item['Id'])
        delete_list_item(settings['url'], context_auth, "Tasks", task_item['Id'])

    else:
        print context_auth.get_last_error()
Ejemplo n.º 3
0
 def setUpClass(cls):
     ctx_auth = AuthenticationContext(url=settings['url'])
     ctx_auth.acquire_token_for_user(username=settings['username'],
                                     password=settings['password'])
     cls.context = ClientContext(settings['url'], ctx_auth)
Ejemplo n.º 4
0
        print "Task '{0}' has been created".format(
            task_item.properties["Title"])


def generate_contacts(context):
    contacts_list = ctx.web.lists.get_by_title("Contacts")
    fake = Faker()
    for idx in range(0, 1):
        name = fake.name()
        contact_properties = {
            '__metadata': {
                'type': 'SP.Data.ContactsListItem'
            },
            'Title': name
        }
        contact_item = contacts_list.add_item(contact_properties)
        context.execute_query()
        print "Contact '{0}' has been created".format(
            contact_item.properties["Title"])


if __name__ == '__main__':
    ctx_auth = AuthenticationContext(url=settings['url'])
    if ctx_auth.acquire_token_for_user(username=settings['username'],
                                       password=settings['password']):
        ctx = ClientContext(settings['url'], ctx_auth)
        generate_tasks(ctx)
        #generate_contacts(ctx)
    else:
        print ctx_auth.get_last_error()
 def setUpClass(cls):
     ctx_auth = AuthenticationContext(url=settings['url'])
     ctx_auth.acquire_token_for_user(username=settings['username'], password=settings['password'])
     cls.context = ClientContext(settings['url'], ctx_auth)