Example #1
0
def smart_link_instance_view(request, document_id, smart_link_pk):
    document = get_object_or_404(Document, pk=document_id)
    smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)

    try:
        Permission.objects.check_permissions(request.user,
                                             [PERMISSION_SMART_LINK_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_SMART_LINK_VIEW,
                                         request.user, smart_link)

    try:
        object_list = smart_link.get_linked_document_for(document)
    except Exception as exception:
        object_list = []

        if request.user.is_staff or request.user.is_superuser:
            messages.error(request,
                           _('Smart link query error: %s' % exception))

    return document_list(request,
                         title=_('Documents in smart link: %s') %
                         smart_link.get_dynamic_title(document),
                         object_list=object_list,
                         extra_context={'object': document})
Example #2
0
def smart_link_instance_view(request, document_id, smart_link_pk):
    document = get_object_or_404(Document, pk=document_id)
    smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)

    try:
        Permission.objects.check_permissions(request.user, [PERMISSION_SMART_LINK_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_SMART_LINK_VIEW, request.user, smart_link)

    try:
        object_list = smart_link.get_linked_document_for(document)
    except Exception as exception:
        object_list = []

        if request.user.is_staff or request.user.is_superuser:
            messages.error(request, _('Smart link query error: %s' % exception))

    return document_list(
        request,
        title=_('Documents in smart link: %s') % smart_link.get_dynamic_title(document),
        object_list=object_list,
        extra_context={
            'object': document
        }
    )
Example #3
0
def tag_tagged_item_list(request, tag_id):
    tag = get_object_or_404(Tag, pk=tag_id)

    return document_list(request,
                         object_list=Document.objects.filter(tags__in=[tag]),
                         title=_('documents with the tag "%s"') % tag,
                         extra_context={
                             'object': tag,
                             'object_name': _(u'tag'),
                         })
Example #4
0
def tag_tagged_item_list(request, tag_id):
    tag = get_object_or_404(Tag, pk=tag_id)

    return document_list(
        request,
        object_list=Document.objects.filter(tags__in=[tag]),
        title=_('documents with the tag "%s"') % tag,
        extra_context={
            'object': tag,
            'object_name': _(u'tag'),
        }
    )
Example #5
0
def index_instance_node_view(request, index_instance_node_pk):
    """
    Show an instance node and it's content, whether is other child nodes
    of documents
    """
    index_instance = get_object_or_404(IndexInstanceNode,
                                       pk=index_instance_node_pk)
    index_instance_list = [
        index for index in index_instance.get_children().order_by('value')
    ]
    breadcrumbs = get_breadcrumbs(index_instance)

    try:
        Permission.objects.check_permissions(
            request.user, [PERMISSION_DOCUMENT_INDEXING_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_DOCUMENT_INDEXING_VIEW,
                                         request.user, index_instance.index)

    title = mark_safe(_(u'contents for index: %s') % breadcrumbs)

    if index_instance:
        if index_instance.index_template_node.link_documents:
            # Document list, use the document_list view for consistency
            return document_list(request,
                                 title=title,
                                 object_list=index_instance.documents.all(),
                                 extra_context={'object': index_instance})

    return render_to_response('generic_list.html', {
        'object_list':
        index_instance_list,
        'extra_columns_preffixed':
        [{
            'name': _(u'node'),
            'attribute': encapsulate(lambda x: index_instance_item_link(x))
        }, {
            'name':
            _(u'items'),
            'attribute':
            encapsulate(lambda x: x.documents.count() if x.index_template_node.
                        link_documents else x.get_children().count())
        }],
        'title':
        title,
        'hide_links':
        True,
        'hide_object':
        True,
        'object':
        index_instance
    },
                              context_instance=RequestContext(request))
Example #6
0
def index_instance_list(request, index_id=None):
    check_permissions(request.user, [PERMISSION_DOCUMENT_INDEXING_VIEW])

    if index_id:
        index_instance = get_object_or_404(IndexInstance, pk=index_id)
        index_instance_list = [
            index for index in index_instance.get_children().order_by('value')
        ]
        breadcrumbs = get_breadcrumbs(index_instance)
        if index_instance.documents.count():
            for document in index_instance.documents.all().order_by(
                    'file_filename'):
                index_instance_list.append(document)
    else:
        index_instance_list = IndexInstance.objects.filter(parent=None)
        breadcrumbs = get_instance_link()
        index_instance = None

    title = mark_safe(_(u'contents for index: %s') % breadcrumbs)

    if index_instance:
        if index_instance.index.link_documents:
            # Document list, use the document_list view for consistency
            return document_list(request,
                                 title=title,
                                 object_list=index_instance_list,
                                 extra_context={'object': index_instance})

    return render_to_response('generic_list.html', {
        'object_list':
        index_instance_list,
        'extra_columns_preffixed':
        [{
            'name': _(u'index'),
            'attribute': encapsulate(lambda x: index_instance_item_link(x))
        }, {
            'name':
            _(u'items'),
            'attribute':
            encapsulate(lambda x: x.documents.count() if x.index.link_documents
                        else x.get_children().count())
        }],
        'title':
        title,
        'hide_links':
        True,
        'hide_object':
        True,
        'object':
        index_instance
    },
                              context_instance=RequestContext(request))
Example #7
0
def folder_view(request, folder_id):
    folder = get_object_or_404(Folder, pk=folder_id)

    try:
        Permission.objects.check_permissions(request.user, [PERMISSION_FOLDER_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_FOLDER_VIEW, request.user, folder)

    context = {"hide_links": True, "multi_select_as_buttons": True, "object": folder, "object_name": _(u"folder")}

    return document_list(
        request, object_list=folder.documents, title=_(u"documents in folder: %s") % folder, extra_context=context
    )
Example #8
0
def smart_link_instance_view(request, document_id, smart_link_pk):
    check_permissions(request.user, [PERMISSION_SMART_LINK_VIEW])

    document = get_object_or_404(Document, pk=document_id)
    smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
    object_list, errors = SmartLink.objects.get_smart_link_instances_for(
        document, smart_link)

    return document_list(request,
                         title=_(u'documents in smart link: %(group)s') %
                         {'group': object_list['title']},
                         object_list=object_list['documents'],
                         extra_context={'object': document})
Example #9
0
def tag_tagged_item_list(request, tag_id):
    tag = get_object_or_404(Tag, pk=tag_id)
    object_list = [tagged_item.content_object for tagged_item in tag.taggit_taggeditem_items.all()]

    return document_list(
        request,
        object_list=object_list,
        title=_('documents with the tag "%s"') % tag,
        extra_context={
            'object': tag,
            'object_name': _(u'tag'),
        }
    )
Example #10
0
def checkout_list(request):
    return document_list(
        request,
        object_list=DocumentCheckout.objects.checked_out_documents(),
        title=_('Documents checked out'),
        extra_context={
            'extra_columns': [
                {'name': _('Checkout user'), 'attribute': encapsulate(lambda document: get_object_name(document.checkout_info().user_object, display_object_type=False))},
                {'name': _('Checkout time and date'), 'attribute': encapsulate(lambda document: document.checkout_info().checkout_datetime)},
                {'name': _('Checkout expiration'), 'attribute': encapsulate(lambda document: document.checkout_info().expiration_datetime)},
            ],
        }
    )
Example #11
0
def tag_tagged_item_list(request, tag_id):
    tag = get_object_or_404(Tag, pk=tag_id)
    object_list = [
        tagged_item.content_object
        for tagged_item in tag.taggit_taggeditem_items.all()
    ]

    return document_list(request,
                         object_list=object_list,
                         title=_('documents with the tag "%s"') % tag,
                         extra_context={
                             'object': tag,
                             'object_name': _(u'tag'),
                         })
Example #12
0
def document_group_view(request, document_id, document_group_id):
    document = get_object_or_404(Document, pk=document_id)
    document_group = get_object_or_404(DocumentGroup, pk=document_group_id)
    object_list, errors = DocumentGroup.objects.get_groups_for(document, document_group)

    return document_list(
        request,
        title=_(u'documents in group: %(group)s') % {
            'group': object_list['title']
        },
        object_list=object_list['documents'],
        extra_context={
            'object': document
        }
    )
Example #13
0
def index_instance_node_view(request, index_instance_node_pk):
    """
    Show an instance node and it's content, whether is other child nodes
    of documents
    """
    index_instance = get_object_or_404(IndexInstanceNode, pk=index_instance_node_pk)
    index_instance_list = [index for index in index_instance.get_children().order_by("value")]
    breadcrumbs = get_breadcrumbs(index_instance)

    try:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_INDEXING_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_DOCUMENT_INDEXING_VIEW, request.user, index_instance.index)

    title = mark_safe(_(u"contents for index: %s") % breadcrumbs)

    if index_instance:
        if index_instance.index_template_node.link_documents:
            # Document list, use the document_list view for consistency
            return document_list(
                request,
                title=title,
                object_list=index_instance.documents.all(),
                extra_context={"object": index_instance},
            )

    return render_to_response(
        "generic_list.html",
        {
            "object_list": index_instance_list,
            "extra_columns_preffixed": [
                {"name": _(u"node"), "attribute": encapsulate(lambda x: index_instance_item_link(x))},
                {
                    "name": _(u"items"),
                    "attribute": encapsulate(
                        lambda x: x.documents.count()
                        if x.index_template_node.link_documents
                        else x.get_children().count()
                    ),
                },
            ],
            "title": title,
            "hide_links": True,
            "hide_object": True,
            "object": index_instance,
        },
        context_instance=RequestContext(request),
    )
Example #14
0
def index_instance_list(request, index_id=None):
    check_permissions(request.user, [PERMISSION_DOCUMENT_INDEXING_VIEW])

    if index_id:
        index_instance = get_object_or_404(IndexInstance, pk=index_id)
        index_instance_list = [index for index in index_instance.get_children().order_by('value')]
        breadcrumbs = get_breadcrumbs(index_instance)
        if index_instance.documents.count():
            for document in index_instance.documents.all().order_by('file_filename'):
                index_instance_list.append(document)
    else:
        index_instance_list = IndexInstance.objects.filter(parent=None)
        breadcrumbs = get_instance_link()
        index_instance = None

    title = mark_safe(_(u'contents for index: %s') % breadcrumbs)

    if index_instance:
        if index_instance.index.link_documents:
            # Document list, use the document_list view for consistency
            return document_list(
                request,
                title=title,
                object_list=index_instance_list,
                extra_context={
                    'object': index_instance
                }
            )

    return render_to_response('generic_list.html', {
        'object_list': index_instance_list,
        'extra_columns_preffixed': [
            {
                'name': _(u'index'),
                'attribute': encapsulate(lambda x: index_instance_item_link(x))
            },
            {
                'name': _(u'items'),
                'attribute': encapsulate(lambda x: x.documents.count() if x.index.link_documents else x.get_children().count() )
            }
        ],
        'title': title,
        'hide_links': True,
        'hide_object': True,
        'object': index_instance

    }, context_instance=RequestContext(request))
Example #15
0
def index_instance_node_view(request, index_instance_node_pk):
    """
    Show an instance node and it's content, whether is other child nodes
    of documents
    """
    index_instance = get_object_or_404(IndexInstanceNode, pk=index_instance_node_pk)
    index_instance_list = [index for index in index_instance.get_children().order_by('value')]
    breadcrumbs = get_breadcrumbs(index_instance)

    try:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_INDEXING_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_DOCUMENT_INDEXING_VIEW, request.user, index_instance.index)

    title = mark_safe(_(u'contents for index: %s') % breadcrumbs)

    if index_instance:
        if index_instance.index_template_node.link_documents:
            # Document list, use the document_list view for consistency
            return document_list(
                request,
                title=title,
                object_list=index_instance.documents.all(),
                extra_context={
                    'object': index_instance
                }
            )

    return render_to_response('generic_list.html', {
        'object_list': index_instance_list,
        'extra_columns_preffixed': [
            {
                'name': _(u'node'),
                'attribute': encapsulate(lambda x: index_instance_item_link(x))
            },
            {
                'name': _(u'items'),
                'attribute': encapsulate(lambda x: x.documents.count() if x.index_template_node.link_documents else x.get_children().count())
            }
        ],
        'title': title,
        'hide_links': True,
        'hide_object': True,
        'object': index_instance

    }, context_instance=RequestContext(request))
Example #16
0
def smart_link_instance_view(request, document_id, smart_link_pk):
    check_permissions(request.user, [PERMISSION_SMART_LINK_VIEW])

    document = get_object_or_404(Document, pk=document_id)
    smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)
    object_list, errors = SmartLink.objects.get_smart_link_instances_for(document, smart_link)

    return document_list(
        request,
        title=_(u'documents in smart link: %(group)s') % {
            'group': object_list['title']
        },
        object_list=object_list['documents'],
        extra_context={
            'object': document
        }
    )
Example #17
0
def folder_view(request, folder_id):
    folder = get_object_or_404(Folder, pk=folder_id)

    try:
        Permission.objects.check_permissions(request.user,
                                             [PERMISSION_FOLDER_VIEW])
    except PermissionDenied:
        AccessEntry.objects.check_access(PERMISSION_FOLDER_VIEW, request.user,
                                         folder)

    context = {
        'hide_links': True,
        'multi_select_as_buttons': True,
        'object': folder,
        'object_name': _(u'folder'),
    }

    return document_list(request,
                         object_list=folder.documents,
                         title=_(u'documents in folder: %s') % folder,
                         extra_context=context)
Example #18
0
def documents_missing_required_metadata(request):
    pre_object_list = Document.objects.filter(
        document_type__metadata__required=True, metadata__value__isnull=True)

    try:
        Permission.objects.check_permissions(request.user,
                                             [PERMISSION_DOCUMENT_VIEW])
    except PermissionDenied:
        # If user doesn't have global permission, get a list of document
        # for which he/she does hace access use it to filter the
        # provided object_list
        object_list = AccessEntry.objects.filter_objects_by_access(
            PERMISSION_DOCUMENT_VIEW, request.user, pre_object_list)
    else:
        object_list = pre_object_list

    context = {
        'object_list': object_list,
        'title': _('Documents missing required metadata'),
        'hide_links': True,
    }

    return document_list(request, extra_context=context)
Example #19
0
def documents_missing_required_metadata(request):
    pre_object_list = Document.objects.filter(document_type__metadata__required=True, metadata__value__isnull=True)

    try:
        Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
    except PermissionDenied:
        # If user doesn't have global permission, get a list of document
        # for which he/she does hace access use it to filter the
        # provided object_list
        object_list = AccessEntry.objects.filter_objects_by_access(
            PERMISSION_DOCUMENT_VIEW, request.user, pre_object_list)
    else:
        object_list = pre_object_list

    context = {
        'object_list': object_list,
        'title': _('Documents missing required metadata'),
        'hide_links': True,
    }

    return document_list(
        request,
        extra_context=context
    )