Exemple #1
0
def get_applications(request, response):
    """Return the list of applications and the dataconnection URLs for them.
    """
    root = get_slumber_root()
    if request.GET.has_key('model'):
        appname, modelname = request.GET['model'].split('.')
        for app in applications():
            if app.name.endswith(appname) and app.models.has_key(modelname):
                return HttpResponseRedirect(root + app.models[modelname].path)
        return HttpResponseNotFound()
    response['apps'] = dict([(app.name, root + app.path + '/')
        for app in applications()])
Exemple #2
0
def get_applications(request, response):
    """Return the list of applications and the data connection URLs for them.
    """
    root = get_slumber_root()
    if request.GET.has_key('model'):
        appname, modelname = request.GET['model'].split('.')
        for app in applications():
            if app.name.endswith(appname) and app.models.has_key(modelname):
                return HttpResponseRedirect(root + app.models[modelname].path)
        return HttpResponseNotFound()
    response['apps'] = dict([(app.name, root + app.path + '/')
                             for app in applications()])
    get_service_directory(request, response)
Exemple #3
0
def service_root(request, response):
    """Request routing for Slumber.
    """
    # We have many return statements, but there's no point in artificially
    # breaking the function up to reduce them
    # pylint: disable = R0911
    if not request.path.endswith('/'):
        return HttpResponsePermanentRedirect(request.path + '/')
    path = request.path[len(reverse('slumber.server.views.service_root')):-1]
    service = get_slumber_service()
    if service:
        if not path:
            return get_service_directory(request, response)
        elif not path.startswith(service + '/') and path != service:
            return HttpResponseNotFound()
        path = path[len(service) + 1:]

    if not path:
        return get_applications(request, response)
    else:
        # Find the app with the longest matching path
        apps = [a for a in applications() if path.startswith(a.path)]
        application = None
        for app in apps:
            if not application or len(app.path) > len(application.path):
                application = app
        if not application:
            return HttpResponseNotFound()
        remaining_path = path[len(application.path)+1:]
        if not remaining_path:
            return get_models(request, response, application)

        models = remaining_path.split('/')
        # Find the model instance and possibly return its details
        model = application.models.get(models.pop(0), None)
        if len(models) == 0:
            return get_model(request, response, model)

        try:
            # Execute the operation (if it can be found)
            operation_name = models.pop(0)
            operation = model.operation_by_name(operation_name)
            return operation.operation(request, response,
                application.path, model.name, *models)
        except NotAnOperation:
            return HttpResponseNotFound()
Exemple #4
0
def service_root(request, response):
    """Request routing for Slumber.
    """
    # We have many return statements, but there's no point in artificially
    # breaking the function up to reduce them
    # pylint: disable = R0911
    if not request.path.endswith('/'):
        return HttpResponsePermanentRedirect(request.path + '/')
    path = request.path[len(reverse('slumber.server.views.service_root')):-1]
    service = get_slumber_service()
    if service:
        if not path:
            return get_service_directory(request, response)
        elif not path.startswith(service + '/') and path != service:
            return HttpResponseNotFound()
        path = path[len(service) + 1:]

    if not path:
        return get_applications(request, response)
    else:
        # Find the app with the longest matching path
        apps = [a for a in applications() if path.startswith(a.path)]
        application = None
        for app in apps:
            if not application or len(app.path) > len(application.path):
                application = app
        if not application:
            return HttpResponseNotFound()
        remaining_path = path[len(application.path) + 1:]
        if not remaining_path:
            return get_models(request, response, application)

        models = remaining_path.split('/')
        # Find the model instance and possibly return its details
        model = application.models.get(models.pop(0), None)
        if len(models) == 0:
            return get_model(request, response, model)

        try:
            # Execute the operation (if it can be found)
            operation_name = models.pop(0)
            operation = model.operation_by_name(operation_name)
            return operation.operation(request, response, application.path,
                                       model.name, *models)
        except NotAnOperation:
            return HttpResponseNotFound()
Exemple #5
0
def service_root(request, response):
    """Request routing for Slumber.
    """
    # We have many return statements, but there's no point in artificially
    # breaking the function up to reduce them
    # pylint: disable = R0911
    # pylint: disable = too-many-branches
    # pylint: disable = too-many-locals
    service = get_slumber_service()
    apps = applications()

    if not request.path.endswith('/'):
        return HttpResponsePermanentRedirect(request.path + '/')
    path = request.path[len(reverse('slumber.server.views.service_root')):-1]

    longest = None
    for op_name in OPERATION_URIS.keys():
        if not longest or len(op_name) > len(longest):
            logging.debug("Comparing %s with %s", path, op_name)
            if path.startswith(op_name):
                longest = op_name
    if longest:
        operation = OPERATION_URIS[longest]
        if len(path) > len(longest) + 1:
            path_remainder = path[len(longest)+1:].split('/')
        else:
            path_remainder = []
        logging.debug("%s %s %s", path, longest, path_remainder)
        return operation.operation(request, response,
            operation.model.app, operation.model, *path_remainder)

    if service:
        if not path:
            return get_service_directory(request, response)
        elif not path.startswith(service + '/') and path != service:
            return HttpResponseNotFound()
        path = path[len(service) + 1:]

    if not path:
        return _get_applications(request, response, apps)
    else:
        # Find the app with the longest matching path
        apps = [a for a in apps if path.startswith(a.path)]
        application = None
        for app in apps:
            if not application or len(app.path) > len(application.path):
                application = app
        if not application:
            return HttpResponseNotFound("No app")
        remaining_path = path[len(application.path)+1:]
        if not remaining_path:
            return get_models(request, response, application)

        models = remaining_path.split('/')
        # Find the model instance and possibly return its details
        model = application.models.get(models.pop(0), None)
        if len(models) == 0:
            return get_model(request, response, model)

        try:
            # Execute the operation (if it can be found)
            operation_name = models.pop(0)
            operation = model.operations[operation_name]
            return operation.operation(request, response,
                application.path, model.name, *models)
        except KeyError:
            return HttpResponseNotFound("No op")
Exemple #6
0
 def setUp(self):
     # Ensure we bootstrap Slumber's server side
     applications()
Exemple #7
0
def service_root(request, response):
    """Request routing for Slumber.
    """
    # We have many return statements, but there's no point in artificially
    # breaking the function up to reduce them
    # pylint: disable = R0911
    # pylint: disable = too-many-branches
    # pylint: disable = too-many-locals
    service = get_slumber_service()
    apps = applications()

    if not request.path.endswith('/'):
        return HttpResponsePermanentRedirect(request.path + '/')
    path = request.path[len(reverse('slumber.server.views.service_root')):-1]

    longest = None
    for op_name in OPERATION_URIS.keys():
        if not longest or len(op_name) > len(longest):
            logging.debug("Comparing %s with %s", path, op_name)
            if path.startswith(op_name):
                longest = op_name
    if longest:
        operation = OPERATION_URIS[longest]
        if len(path) > len(longest) + 1:
            path_remainder = path[len(longest) + 1:].split('/')
        else:
            path_remainder = []
        logging.debug("%s %s %s", path, longest, path_remainder)
        return operation.operation(request, response, operation.model.app,
                                   operation.model, *path_remainder)

    if service:
        if not path:
            return get_service_directory(request, response)
        elif not path.startswith(service + '/') and path != service:
            return HttpResponseNotFound()
        path = path[len(service) + 1:]

    if not path:
        return _get_applications(request, response, apps)
    else:
        # Find the app with the longest matching path
        apps = [a for a in apps if path.startswith(a.path)]
        application = None
        for app in apps:
            if not application or len(app.path) > len(application.path):
                application = app
        if not application:
            return HttpResponseNotFound("No app")
        remaining_path = path[len(application.path) + 1:]
        if not remaining_path:
            return get_models(request, response, application)

        models = remaining_path.split('/')
        # Find the model instance and possibly return its details
        model = application.models.get(models.pop(0), None)
        if len(models) == 0:
            return get_model(request, response, model)

        try:
            # Execute the operation (if it can be found)
            operation_name = models.pop(0)
            operation = model.operations[operation_name]
            return operation.operation(request, response, application.path,
                                       model.name, *models)
        except KeyError:
            return HttpResponseNotFound("No op")
Exemple #8
0
"""
    Django Async management commands.
"""

try:
    from slumber.server.meta import applications
    applications()
except ImportError: # pragma: no cover
    pass
Exemple #9
0
 def setUp(self):
     # Ensure we bootstrap Slumber's server side
     applications()