Exemplo n.º 1
0
def move_node_view(request):
    position_mapping = {'before': 'left', 'after': 'right',
                        'inside': 'first-child'}
    position = request.GET['position']
    if position not in position_mapping:
        raise SuspiciousOperation
    position = position_mapping[position]

    try:
        target = Node.objects.get(pk=request.GET['target'])
    except Node.DoesNotExist:
        raise SuspiciousOperation
    target_portal = target.get_root().portal

    request.portal = target_portal
    if not is_portal_admin(request):
        raise SuspiciousOperation
    if position != 'first-child' and target.is_root_node():
        raise SuspiciousOperation

    try:
        node = Node.objects.get(pk=request.GET['node'])
    except Node.DoesNotExist:
        raise SuspiciousOperation
    if node.get_root().portal != target_portal:
        raise SuspiciousOperation

    try:
        node.move_to(target, position)
    except (InvalidMove, IntegrityError):
        raise SuspiciousOperation

    return HttpResponse()
Exemplo n.º 2
0
def move_node_view(request):
    position_mapping = {'before': 'left', 'after': 'right',
                        'inside': 'first-child'}
    position = request.GET['position']
    if position not in position_mapping:
        raise SuspiciousOperation
    position = position_mapping[position]

    try:
        target = Node.objects.get(pk=request.GET['target'])
    except Node.DoesNotExist:
        raise SuspiciousOperation
    target_portal = target.get_root().portal

    request.portal = target_portal
    if not is_portal_admin(request):
        raise SuspiciousOperation
    if position != 'first-child' and target.is_root_node():
        raise SuspiciousOperation

    try:
        node = Node.objects.get(pk=request.GET['node'])
    except Node.DoesNotExist:
        raise SuspiciousOperation
    if node.get_root().portal != target_portal:
        raise SuspiciousOperation

    try:
        node.move_to(target, position)
    except (InvalidMove, IntegrityError):
        raise SuspiciousOperation

    return HttpResponse()
Exemplo n.º 3
0
    def render(request, match):
        redirect_url = match.group(1).strip()
        if six.moves.urllib.parse.urlparse(redirect_url).netloc:
            return "[[Redirect: only relative URLs allowed]]"

        return render_to_string('portals/widgets/redirect.html',
                                {'redirect_url': redirect_url,
                                 'is_portal_admin': is_portal_admin(request)})
Exemplo n.º 4
0
def _portal_view(request, portal, portal_path):
    if 'action' in request.GET:
        action = request.GET['action']
    else:
        action = DEFAULT_ACTION_NAME

    request.portal = portal
    request.action = action
    request.is_portal_admin = is_portal_admin(request)

    if action in node_actions:
        request.current_node = resolve_path(request.portal, portal_path)
        request.current_lang_version = request.current_node.get_lang_version(request)
        view = node_actions[action]
    elif action in portal_actions:
        view = portal_actions[action]
    else:
        raise Http404

    return view(request)
Exemplo n.º 5
0
def _portal_view(request, portal, portal_path):
    if 'action' in request.GET:
        action = request.GET['action']
    else:
        action = DEFAULT_ACTION_NAME

    request.portal = portal
    request.action = action
    request.is_portal_admin = is_portal_admin(request)

    if action in node_actions:
        request.current_node = resolve_path(request.portal, portal_path)
        request.current_lang_version = request.current_node.get_lang_version(
            request)
        view = node_actions[action]
    elif action in portal_actions:
        view = portal_actions[action]
    else:
        raise Http404

    return view(request)