Beispiel #1
0
def create_folder_with_permissions(parent_id, folder_name, permissions=None):
    """
    Create drive folder in the specified location with given permissions.
    """
    service = Service(settings.GOOGLE_P12_PATH, settings.GOOGLE_SERVICE_EMAIL)
    folder = service.insert_folder(folder_name, parent_id)
    if folder is None:
        raise GoogleDriveError('Could not create a folder')

    permissions = permissions or []
    for permission in permissions:
        service.add_permission(folder.get('id'), permission)

    return folder
Beispiel #2
0
def create_document_from_template(template_id,
                                  name,
                                  parent_ids=None,
                                  permissions=None):
    service = Service(settings.GOOGLE_P12_PATH, settings.GOOGLE_SERVICE_EMAIL)
    upload_info = service.copy_file(template_id, name, parent_ids=parent_ids)
    if upload_info is None:
        raise GoogleDriveError('Could not create document {}'.format(name))

    logger.info(upload_info)
    document_id = upload_info.get('id')

    permissions = permissions or []
    for permission in permissions:
        service.add_permission(document_id, permission)

    upload_info['status'] = 'success'
    upload_info['id'] = document_id
    return upload_info