Ejemplo n.º 1
0
def install_resource_to_user(user, **kwargs):

    executor_user = kwargs.get('executor_user', user)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    added = add_m2m(resource.users, user)
    if added:
        resource_installed.send(sender=resource, user=user)

    return added, resource
Ejemplo n.º 2
0
def install_resource_to_group(group, **kwargs):

    executor_user = kwargs.get('executor_user', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    added = add_m2m(resource.groups, group)
    if added:
        resource_installed.send(sender=resource, group=group)

    return added, resource
Ejemplo n.º 3
0
def install_resource_to_group(group, **kwargs):

    executor_user = kwargs.get('executor_user', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    added = add_m2m(resource.groups, group)
    if added:
        resource_installed.send(sender=resource, group=group)

    return added, resource
Ejemplo n.º 4
0
def install_resource_to_user(user, **kwargs):

    executor_user = kwargs.get('executor_user', user)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    added = add_m2m(resource.users, user)
    if added:
        resource_installed.send(sender=resource, user=user)

    return added, resource
Ejemplo n.º 5
0
def install_resource_to_all_users(**kwargs):

    executor_user = kwargs.get('executor_user', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    resource.public = True
    resource.save()

    resource_installed.send(sender=resource)

    return resource
Ejemplo n.º 6
0
def install_resource_to_group(group, **kwargs):

    packaged = kwargs.get('packaged', False)
    executor_user = kwargs.get('executor_user', None)
    templateURL = kwargs.get('templateURL', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, templateURL, executor_user, packaged)
    resource.groups.add(group)

    resource_installed.send(sender=resource, group=group)

    return resource
Ejemplo n.º 7
0
def install_resource_to_all_users(**kwargs):

    packaged = kwargs.get('packaged', False)
    executor_user = kwargs.get('executor_user', None)
    templateURL = kwargs.get('templateURL', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, templateURL, executor_user, packaged)
    resource.public = True
    resource.save()

    resource_installed.send(sender=resource)

    return resource
Ejemplo n.º 8
0
def install_resource_to_group(group, **kwargs):

    executor_user = kwargs.get('executor_user', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    if resource.groups.filter(pk=group.pk).exists():
        added = False
    else:
        added = True
        resource.groups.add(group)
        resource_installed.send(sender=resource, group=group)

    return added, resource
Ejemplo n.º 9
0
def install_resource_to_user(user, **kwargs):

    executor_user = kwargs.get('executor_user', user)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    if resource.users.filter(pk=user.pk).exists():
        added = False
    else:
        added = True
        resource.users.add(user)
        resource_installed.send(sender=resource, user=user)

    return added, resource
Ejemplo n.º 10
0
def install_resource_to_all_users(**kwargs):

    executor_user = kwargs.get('executor_user', None)
    downloaded_file = kwargs.get('file_contents', None)

    resource = install_resource(downloaded_file, executor_user)
    if resource.public:
        added = False
    else:
        added = True
        resource.public = True
        resource.save()
        resource_installed.send(sender=resource)

    return added, resource
Ejemplo n.º 11
0
def install_resource_to_user(user, **kwargs):

    executor_user = kwargs.get('executor_user', user)
    downloaded_file = kwargs.get('file_contents', None)
    raise_conflicts = kwargs.get('raise_conflicts', False)

    resource = install_resource(downloaded_file, executor_user)
    if resource.users.filter(pk=user.pk).exists():
        if raise_conflicts:
            raise IntegrityError(_('Resource already exists %(resource_id)s') % {'resource_id': resource.local_uri_part})
    else:
        resource.users.add(user)
        resource_installed.send(sender=resource, user=user)

    return resource
Ejemplo n.º 12
0
def install_resource_to_user(user, **kwargs):

    packaged = kwargs.get('packaged', False)
    executor_user = kwargs.get('executor_user', user)
    templateURL = kwargs.get('templateURL', None)
    downloaded_file = kwargs.get('file_contents', None)
    raise_conflicts = kwargs.get('raise_conflicts', False)

    resource = install_resource(downloaded_file, templateURL, executor_user, packaged)
    if raise_conflicts and resource.users.filter(pk=user.pk).exists():
        raise IntegrityError(_('Resource already exists %(resource_id)s') % {'resource_id': resource.local_uri_part})

    resource.users.add(user)

    resource_installed.send(sender=resource, user=user)

    return resource
Ejemplo n.º 13
0
def install_component(file_contents, executor_user=None, public=False, users=[], groups=[], restricted=False):
    resource = install_resource(file_contents, executor_user, restricted=restricted)
    if executor_user is not None:
        initially_available = resource.is_available_for(executor_user)
    installed_to_someone = False

    change = public is True and resource.public is False
    if change:
        resource.public = True
        resource.save()
        resource_installed.send(sender=resource)
        installed_to_someone = True

    for user in users:
        change = add_m2m(resource.users, user)
        installed_to_someone |= change
        if change and not public:
            resource_installed.send(sender=resource, user=user)

    for group in groups:
        change = add_m2m(resource.groups, group)
        installed_to_someone |= change
        if change and not public:
            resource_installed.send(sender=resource, group=group)

    if executor_user is not None:
        finally_available = resource.is_available_for(executor_user)
        return initially_available is False and finally_available is True, resource
    else:
        return installed_to_someone, resource