Ejemplo n.º 1
0
def render(request, identifier):
    try:
        node = Node(identifier, user=request.user)
    except ObjectDoesNotExist:
        node = None

    if not node or not node.is_file():
        try:
            permalink = Permalink.objects.get(name=identifier)
        except Permalink.DoesNotExist:
            permalink = None

        if not permalink or (permalink.valid_since
                             and permalink.valid_since > now()):
            from django.http import Http404
            raise Http404

        node = Node(nodeobj=permalink.file, user=request.user)
        rev = permalink.revision if permalink.revision else permalink.file.current_revision

    else:
        rev = node.model.current_revision

    if not node.can_view():
        if request.user.is_authenticated():
            from django.core.exceptions import PermissionDenied
            raise PermissionDenied
        else:
            from django.contrib.auth.views import redirect_to_login
            return redirect_to_login(request.path)

    text = rev.text
    if text.format == BlobText.MARKDOWN:
        from core.formatting import render_document
        rendered_text = render_document(text.text)
    elif text.format == BlobText.HTML:
        rendered_text = text
    else:  # text.format == BlobText.TEXT:
        rendered_text = r'<blockquote>%s</blockquote>' % text.text

    return render_request(request, 'docs/render.html', {
        'node': node,
        'text': rendered_text,
    })
Ejemplo n.º 2
0
def render(request, identifier):
	try:
		node = Node(identifier, user=request.user)
	except ObjectDoesNotExist:
		node = None

	if not node or not node.is_file():
		try:
			permalink = Permalink.objects.get(name=identifier)
		except Permalink.DoesNotExist:
			permalink = None

		if not permalink or (permalink.valid_since and permalink.valid_since > now()):
			from django.http import Http404
			raise Http404

		node = Node(nodeobj=permalink.file, user=request.user)
		rev = permalink.revision if permalink.revision else permalink.file.current_revision

	else:
		rev = node.model.current_revision

	if not node.can_view():
		if request.user.is_authenticated():
			from django.core.exceptions import PermissionDenied
			raise PermissionDenied
		else:
			from django.contrib.auth.views import redirect_to_login
			return redirect_to_login(request.path)

	text = rev.text
	if text.format == BlobText.MARKDOWN:
		from core.formatting import render_document
		rendered_text = render_document(text.text)
	elif text.format == BlobText.HTML:
		rendered_text = text
	else: # text.format == BlobText.TEXT:
		rendered_text = r'<blockquote>%s</blockquote>' % text.text

	return render_request(request, 'docs/render.html', {
		'node': node,
		'text': rendered_text,
	})
Ejemplo n.º 3
0
def create(request):
    if request.method == 'POST':
        kind = request.POST.get('type')
        name = request.POST.get('name')
        at = request.POST.get('at')

        if not (kind and name and at):
            return bad_request(request, {'error': 'invalid_args'})

        try:
            parent = Node(at, user=request.user)
        except ObjectDoesNotExist:
            return bad_request(request, {'error': 'invalid_node'})

        if not parent.is_folder():
            return bad_request(request, {'error': 'node_is_not_a_folder'})

        if not parent.can_edit():
            from django.core.exceptions import PermissionDenied
            raise PermissionDenied
        # Warning: removed creation restrictions on <ALLOW * EDIT> folder. Careful.

        if parent.is_archived():
            return bad_request(request, {'error': 'node_archived'})

        if kind == 'file':
            r = create_revision(request)
            if not r:
                return bad_request(request, {'error': 'content_required'})
            f = File()
            f.current_revision = r
        elif kind == 'folder':
            f = Folder()
        else:
            return bad_request(request, {'error': 'invalid_type'})

        f.parent = parent.model
        f.name = name
        f.save()

        node = Node(nodeobj=f, user=request.user)

        if request.is_ajax():
            result = {
                'status': 'success',
                'nid': node.nid(),
                'timestamp': f.last_modified,
            }
            if node.is_file():
                result['revision'] = r.id
            return render(request, result)
        else:
            return redirect('docs:view', node.nid())

    elif request.is_ajax():
        return not_allowed(request, ['POST'])

    else:
        try:
            parent = Node(request.GET.get('at'), user=request.user)
        except (TypeError, ObjectDoesNotExist):
            parent = None

        if not parent or not parent.is_folder():
            return redirect('docs:main')

        if not parent.can_edit():
            if not request.user.is_authenticated():
                from django.contrib.auth.views import redirect_to_login
                return redirect_to_login(request.path)
            else:
                from django.core.exceptions import PermissionDenied
                raise PermissionDenied

        return render(request, 'docs/create.html', {'parent': parent})
Ejemplo n.º 4
0
def create(request):
	if request.method == 'POST':
		kind = request.POST.get('type')
		name = request.POST.get('name')
		at = request.POST.get('at')

		if not (kind and name and at):
			return bad_request(request, {'error': 'invalid_args'})

		try:
			parent = Node(at, user=request.user)
		except ObjectDoesNotExist:
			return bad_request(request, {'error': 'invalid_node'})

		if not parent.is_folder():
			return bad_request(request, {'error': 'node_is_not_a_folder'})

		if not parent.can_edit():
			from django.core.exceptions import PermissionDenied
			raise PermissionDenied
		# Warning: removed creation restrictions on <ALLOW * EDIT> folder. Careful.
		
		if parent.is_archived():
			return bad_request(request, {'error': 'node_archived'})

		if kind == 'file':
			r = create_revision(request)
			if not r:
				return bad_request(request, {'error': 'content_required'})		
			f = File()
			f.current_revision = r
		elif kind == 'folder':
			f = Folder()
		else:
			return bad_request(request, {'error': 'invalid_type'})

		f.parent = parent.model
		f.name = name
		f.save()

		node = Node(nodeobj=f, user=request.user)

		if request.is_ajax():
			result = {
				'status': 'success',
				'nid': node.nid(),
				'timestamp': f.last_modified,
			}
			if node.is_file():
				result['revision'] = r.id
			return render(request, result)
		else:
			return redirect('docs:view', node.nid())

	elif request.is_ajax():
		return not_allowed(request, ['POST'])

	else:
		try:
			parent = Node(request.GET.get('at'), user=request.user)
		except (TypeError, ObjectDoesNotExist):
			parent = None

		if not parent or not parent.is_folder():
			return redirect('docs:main')

		if not parent.can_edit():
			if not request.user.is_authenticated():
				from django.contrib.auth.views import redirect_to_login
				return redirect_to_login(request.path)
			else:
				from django.core.exceptions import PermissionDenied
				raise PermissionDenied

		return render(request, 'docs/create.html', {'parent': parent})