예제 #1
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """

    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            return parse_xmlrpc_request(request)
        parse_distutils_request(request)
        action = request.POST.get(':action','')
    else:
        action = request.GET.get(':action','')
    
    if not action:
        if fallback_view is None:
            fallback_view = conf.FALLBACK_VIEW
            if isinstance(fallback_view, basestring):
                module, func_name = fallback_view.rsplit('.', 1)
                fallback_view = getattr(__import__(module, {}, {}, [func_name]), func_name)
                conf.FALLBACK_VIEW = fallback_view
        return fallback_view(request, **kwargs)
    
    if not action in conf.ACTION_VIEWS:
        logger.info('unknown action: %s' % (action,))
        return HttpResponseNotAllowed(conf.ACTION_VIEW.keys())
    
    view_func = conf.ACTION_VIEWS[action]
    if isinstance(view_func, basestring):
        module, func_name = view_func.rsplit('.', 1)
        view_func = getattr(__import__(module, {}, {}, [func_name]), func_name)
        conf.ACTION_VIEWS[action] = view_func
    
    return view_func(request, **kwargs)
예제 #2
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """

    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            return parse_xmlrpc_request(request)
        parse_distutils_request(request)
        action = request.POST.get(':action', '')
    else:
        action = request.GET.get(':action', '')

    if not action:
        if fallback_view is None:
            fallback_view = conf.FALLBACK_VIEW
            if isinstance(fallback_view, basestring):
                module, func_name = fallback_view.rsplit('.', 1)
                fallback_view = getattr(
                    __import__(module, {}, {}, [func_name]), func_name)
                conf.FALLBACK_VIEW = fallback_view
        return fallback_view(request, **kwargs)

    if not action in conf.ACTION_VIEWS:
        logger.info('unknown action: %s' % (action, ))
        return HttpResponseNotAllowed(conf.ACTION_VIEW.keys())

    view_func = conf.ACTION_VIEWS[action]
    if isinstance(view_func, basestring):
        module, func_name = view_func.rsplit('.', 1)
        view_func = getattr(__import__(module, {}, {}, [func_name]), func_name)
        conf.ACTION_VIEWS[action] = view_func

    return view_func(request, **kwargs)
예제 #3
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """
    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            log.debug('XMLRPC request received')
            return parse_xmlrpc_request(request)
        log.debug('Distutils request received')
        parse_distutils_request(request)
        action = request.POST.get(':action', '')
        action = action.strip()
    else:
        action = request.GET.get(':action', '')
        action = action.strip()

    if not action:
        log.debug('No action in root view')
        if fallback_view is None:
            fallback_view = import_item(FALLBACK_VIEW)
        return fallback_view.as_view()(request, **kwargs)

    if action not in ACTION_VIEWS:
        log.error('Invalid action encountered: %s' % (action,))
        return HttpResponseNotAllowed(ACTION_VIEWS.keys())

    log.debug('Applying configured action view for %s' % (action,))
    action_view = import_item(ACTION_VIEWS[action])
    return action_view(request, **kwargs)
예제 #4
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """
    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            log.debug('XMLRPC request received')
            return parse_xmlrpc_request(request)
        log.debug('Distutils request received')
        parse_distutils_request(request)
        action = request.POST.get(':action', '')
    else:
        action = request.GET.get(':action', '')

    if not action:
        log.debug('No action in root view')
        if fallback_view is None:
            fallback_view = settings.DJANGOPYPI_FALLBACK_VIEW
        return fallback_view(request, **kwargs)

    if not action in settings.DJANGOPYPI_ACTION_VIEWS:
        log.error('Invalid action encountered: %s' % (action, ))
        return HttpResponseNotAllowed(settings.DJANGOPYPI_ACTION_VIEW.keys())

    log.debug('Applying configured action view for %s' % (action, ))
    return settings.DJANGOPYPI_ACTION_VIEWS[action](request, **kwargs)
예제 #5
0
def simple(request, template_name="djangopypi/simple.html"):
    if request.method == "POST":
        post_data, files = parse_distutils_request(request)
        action_name = post_data.get(":action")
        if action_name not in ACTIONS:
            return HttpResponseNotImplemented("The action %s is not implemented" % action_name)
        return ACTIONS[action_name](request, post_data, files)

    dists = Project.objects.all().order_by("name")
    context = RequestContext(request, {"dists": dists, "title": "Package Index"})

    return render_to_response(template_name, context_instance=context)
예제 #6
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """

    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            return parse_xmlrpc_request(request)
        parse_distutils_request(request)
        action = request.POST.get(':action', '')
    else:
        action = request.GET.get(':action', '')

    if not action:
        if fallback_view is None:
            fallback_view = settings.DJANGOPYPI_FALLBACK_VIEW
        return fallback_view(request, **kwargs)

    if not action in settings.DJANGOPYPI_ACTION_VIEWS:
        print 'unknown action: %s' % (action, )
        return HttpResponseNotAllowed(settings.DJANGOPYPI_ACTION_VIEW.keys())

    return settings.DJANGOPYPI_ACTION_VIEWS[action](request, **kwargs)
예제 #7
0
def root(request, fallback_view=None, **kwargs):
    """ Root view of the package index, handle incoming actions from distutils
    or redirect to a more user friendly view """

    if request.method == 'POST':
        if request.META['CONTENT_TYPE'] == 'text/xml':
            return parse_xmlrpc_request(request)
        parse_distutils_request(request)
        action = request.POST.get(':action','')
    else:
        action = request.GET.get(':action','')
    
    if not action:
        if fallback_view is None:
            fallback_view = settings.DJANGOPYPI_FALLBACK_VIEW
        return fallback_view(request, **kwargs)
    
    if not action in settings.DJANGOPYPI_ACTION_VIEWS:
        print 'unknown action: %s' % (action,)
        return HttpResponseNotAllowed(settings.DJANGOPYPI_ACTION_VIEW.keys())
    
    return settings.DJANGOPYPI_ACTION_VIEWS[action](request, **kwargs)
예제 #8
0
def simple(request, template_name="djangopypi/simple.html"):
    if request.method == "POST":
        post_data, files = parse_distutils_request(request)
        action_name = post_data.get(":action")
        if action_name not in ACTIONS:
            return HttpResponseNotImplemented(
                "The action %s is not implemented" % action_name)
        return ACTIONS[action_name](request, post_data, files)

    dists = Project.objects.all().order_by("name")
    context = RequestContext(request, {
        "dists": dists,
        "title": 'Package Index',
    })

    return render_to_response(template_name, context_instance=context)