def document_edit(request, document_id, response_format='html'): "Document edit page" document = get_object_or_404(Document, pk=document_id) if not request.user.get_profile().has_permission(document, mode='w'): return user_denied(request, message="You don't have access to this Document") if request.POST: if not 'cancel' in request.POST: form = DocumentForm( request.user.get_profile(), None, request.POST, instance=document) if form.is_valid(): document = form.save() return HttpResponseRedirect(reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect(reverse('documents_document_view', args=[document.id])) else: form = DocumentForm( request.user.get_profile(), None, instance=document) context = _get_default_context(request) context.update({'form': form, 'document': document}) return render_to_response('documents/document_edit', context, context_instance=RequestContext(request), response_format=response_format)
def document_add_typed(request, folder_id=None, response_format='html'): "Document add to preselected folder" folder = None if folder_id: folder = get_object_or_404(Folder, pk=folder_id) if not request.user.get_profile().has_permission(folder, mode='x'): folder = None document = Document() if request.POST: if not 'cancel' in request.POST: form = DocumentForm( request.user.get_profile(), folder_id, request.POST, instance=document) if form.is_valid(): document = form.save() document.set_user_from_request(request) return HttpResponseRedirect(reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect(reverse('document_index')) else: form = DocumentForm(request.user.get_profile(), folder_id) context = _get_default_context(request) context.update({'form': form, 'folder': folder}) return render_to_response('documents/document_add_typed', context, context_instance=RequestContext(request), response_format=response_format)
def document_edit(request, document_id, response_format='html'): "Document edit page" document = get_object_or_404(Document, pk=document_id) if not request.user.get_profile().has_permission(document, mode='w'): return user_denied(request, message="You don't have access to this Document") if request.POST: if not 'cancel' in request.POST: form = DocumentForm(request.user.get_profile(), None, request.POST, instance=document) if form.is_valid(): document = form.save() return HttpResponseRedirect( reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect( reverse('documents_document_view', args=[document.id])) else: form = DocumentForm(request.user.get_profile(), None, instance=document) context = _get_default_context(request) context.update({'form': form, 'document': document}) return render_to_response('documents/document_edit', context, context_instance=RequestContext(request), response_format=response_format)
def document_add_typed(request, folder_id=None, response_format='html'): "Document add to preselected folder" folder = None if folder_id: folder = get_object_or_404(Folder, pk=folder_id) if not request.user.get_profile().has_permission(folder, mode='x'): folder = None document = Document() if request.POST: if not 'cancel' in request.POST: form = DocumentForm(request.user.get_profile(), folder_id, request.POST, instance=document) if form.is_valid(): document = form.save() document.set_user_from_request(request) return HttpResponseRedirect( reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect(reverse('document_index')) else: form = DocumentForm(request.user.get_profile(), folder_id) context = _get_default_context(request) context.update({'form': form, 'folder': folder}) return render_to_response('documents/document_add_typed', context, context_instance=RequestContext(request), response_format=response_format)
def document_add(request, response_format='html'): "new document form" if request.POST: if not 'cancel' in request.POST: document = Document() form = DocumentForm(request.user.get_profile(), None, request.POST, instance=document) if form.is_valid(): document = form.save() document.set_user_from_request(request) return HttpResponseRedirect( reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect(reverse('document_index')) else: form = DocumentForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('documents/document_add', context, context_instance=RequestContext(request), response_format=response_format)
def document_add(request, response_format='html'): "new document form" if request.POST: if not 'cancel' in request.POST: document = Document() form = DocumentForm(request.user.get_profile(), None, request.POST, instance=document) if form.is_valid(): document = form.save() document.set_user_from_request(request) return HttpResponseRedirect(reverse('documents_document_view', args=[document.id])) else: return HttpResponseRedirect(reverse('document_index')) else: form = DocumentForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('documents/document_add', context, context_instance=RequestContext(request), response_format=response_format)