Exemplo n.º 1
0
def document_edit(request, document_id):
    check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_PROPERTIES_EDIT])
            
    document = get_object_or_404(Document, pk=document_id)
    if request.method == 'POST':
        form = DocumentForm_edit(request.POST, initial={'document_type':document.document_type})
        if form.is_valid():
            try:
                document_delete_fs_links(document)
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(reverse('document_list'))

            document.file_filename = form.cleaned_data['new_filename']

            if 'document_type_available_filenames' in form.cleaned_data:
                if form.cleaned_data['document_type_available_filenames']:
                    document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
                
            document.save()
            
            messages.success(request, _(u'Document %s edited successfully.') % document)
            
            try:
                document_create_fs_links(document)
                messages.success(request, _(u'Document filesystem links updated successfully.'))                
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(document.get_absolute_url())
                
            return HttpResponseRedirect(document.get_absolute_url())
Exemplo n.º 2
0
def document_edit_metadata(request, document_id):
    check_permissions(request.user, "documents", [PERMISSION_DOCUMENT_METADATA_EDIT])

    document = get_object_or_404(Document, pk=document_id)

    initial = []
    for item in DocumentTypeMetadataType.objects.filter(document_type=document.document_type):
        initial.append(
            {
                "metadata_type": item.metadata_type,
                "document_type": document.document_type,
                "value": document.documentmetadata_set.get(metadata_type=item.metadata_type).value
                if document.documentmetadata_set.filter(metadata_type=item.metadata_type)
                else None,
            }
        )
    # for metadata in document.documentmetadata_set.all():
    #    initial.append({
    #        'metadata_type':metadata.metadata_type,
    #        'document_type':document.document_type,
    #        'value':metadata.value,
    #    })

    formset = MetadataFormSet(initial=initial)
    if request.method == "POST":
        formset = MetadataFormSet(request.POST)
        if formset.is_valid():
            save_metadata_list(formset.cleaned_data, document)
            try:
                document_delete_fs_links(document)
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(reverse("document_list"))

            messages.success(request, _(u"Metadata for document %s edited successfully.") % document)

            try:
                warnings = document_create_fs_links(document)

                if request.user.is_staff or request.user.is_superuser:
                    for warning in warnings:
                        messages.warning(request, warning)

                messages.success(request, _(u"Document filesystem links updated successfully."))
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(document.get_absolute_url())

            return HttpResponseRedirect(document.get_absolute_url())
Exemplo n.º 3
0
def document_delete(request, document_id):
    check_permissions(request.user, "documents", [PERMISSION_DOCUMENT_DELETE])

    document = get_object_or_404(Document, pk=document_id)

    previous = request.POST.get("previous", request.GET.get("previous", request.META.get("HTTP_REFERER", None)))

    if request.method == "POST":
        try:
            document_delete_fs_links(document)
            document.delete()
            messages.success(request, _(u"Document deleted successfully."))
            return HttpResponseRedirect(reverse("document_list"))
        except Exception, e:
            messages.error(request, _(u"Document delete error: %s") % e)
            return HttpResponseRedirect(previous)
Exemplo n.º 4
0
def document_delete(request, document_id):
    check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_DELETE])
            
    document = get_object_or_404(Document, pk=document_id)

    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))

    if request.method == 'POST':
        try:
            document_delete_fs_links(document)
            document.delete()
            messages.success(request, _(u'Document deleted successfully.'))
            return HttpResponseRedirect(reverse('document_list'))
        except Exception, e:
            messages.error(request, _(u'Document delete error: %s') % e)
            return HttpResponseRedirect(previous)
Exemplo n.º 5
0
def document_edit_metadata(request, document_id):
    check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_METADATA_EDIT])
            
    document = get_object_or_404(Document, pk=document_id)

    initial=[]
    for item in DocumentTypeMetadataType.objects.filter(document_type=document.document_type):
        initial.append({
            'metadata_type':item.metadata_type,
            'document_type':document.document_type,
            'value':document.documentmetadata_set.get(metadata_type=item.metadata_type).value if document.documentmetadata_set.filter(metadata_type=item.metadata_type) else None
        })
    #for metadata in document.documentmetadata_set.all():
    #    initial.append({
    #        'metadata_type':metadata.metadata_type,
    #        'document_type':document.document_type,
    #        'value':metadata.value,
    #    })    

    formset = MetadataFormSet(initial=initial)
    if request.method == 'POST':
        formset = MetadataFormSet(request.POST)
        if formset.is_valid():
            save_metadata_list(formset.cleaned_data, document)
            try:
                document_delete_fs_links(document)
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(reverse('document_list'))
           
            messages.success(request, _(u'Metadata for document %s edited successfully.') % document)
            
            try:
                warnings = document_create_fs_links(document)

                if request.user.is_staff or request.user.is_superuser:
                    for warning in warnings:
                        messages.warning(request, warning)                

                messages.success(request, _(u'Document filesystem links updated successfully.'))                
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(document.get_absolute_url())
                
            return HttpResponseRedirect(document.get_absolute_url())
Exemplo n.º 6
0
def document_edit(request, document_id):
    check_permissions(request.user, "documents", [PERMISSION_DOCUMENT_PROPERTIES_EDIT])

    document = get_object_or_404(Document, pk=document_id)
    if request.method == "POST":
        form = DocumentForm_edit(request.POST, initial={"document_type": document.document_type})
        if form.is_valid():
            try:
                document_delete_fs_links(document)
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(reverse("document_list"))

            document.file_filename = form.cleaned_data["new_filename"]

            if "document_type_available_filenames" in form.cleaned_data:
                if form.cleaned_data["document_type_available_filenames"]:
                    document.file_filename = form.cleaned_data["document_type_available_filenames"].filename

            document.save()

            messages.success(request, _(u"Document %s edited successfully.") % document)

            try:
                warnings = document_create_fs_links(document)

                if request.user.is_staff or request.user.is_superuser:
                    for warning in warnings:
                        messages.warning(request, warning)

                messages.success(request, _(u"Document filesystem links updated successfully."))
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(document.get_absolute_url())

            return HttpResponseRedirect(document.get_absolute_url())
Exemplo n.º 7
0
def document_edit(request, document_id):
    check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_PROPERTIES_EDIT])
            
    document = get_object_or_404(Document, pk=document_id)
    if request.method == 'POST':
        form = DocumentForm_edit(request.POST, initial={'document_type':document.document_type})
        if form.is_valid():
            try:
                document_delete_fs_links(document)
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(reverse('document_list'))

            document.file_filename = form.cleaned_data['new_filename']

            if 'document_type_available_filenames' in form.cleaned_data:
                if form.cleaned_data['document_type_available_filenames']:
                    document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
                
            document.save()
            
            messages.success(request, _(u'Document %s edited successfully.') % document)
            
            try:
                warnings = document_create_fs_links(document)

                if request.user.is_staff or request.user.is_superuser:
                    for warning in warnings:
                        messages.warning(request, warning)

                messages.success(request, _(u'Document filesystem links updated successfully.'))                
            except Exception, e:
                messages.error(request, e)
                return HttpResponseRedirect(document.get_absolute_url())
                
            return HttpResponseRedirect(document.get_absolute_url())