Beispiel #1
0
    def ready(self):
        super(DocumentsApp, self).ready()

        APIEndPoint(app=self, version_string='1')

        DeletedDocument = self.get_model('DeletedDocument')
        Document = self.get_model('Document')
        DocumentPage = self.get_model('DocumentPage')
        DocumentType = self.get_model('DocumentType')
        DocumentTypeFilename = self.get_model('DocumentTypeFilename')
        DocumentVersion = self.get_model('DocumentVersion')

        MissingItem(
            label=_('Create a document type'),
            description=_(
                'Every uploaded document must be assigned a document type, '
                'it is the basic way Mayan EDMS categorizes documents.'
            ), condition=lambda: not DocumentType.objects.exists(),
            view='documents:document_type_list'
        )

        ModelAttribute(
            Document, label=_('Label'), name='label', type_name='field'
        )

        ModelAttribute(
            Document,
            description=_('The MIME type of any of the versions of a document'),
            label=_('MIME type'), name='versions__mimetype', type_name='field'
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_document_delete, permission_document_download,
                permission_document_edit, permission_document_new_version,
                permission_document_print, permission_document_properties_edit,
                permission_document_restore, permission_document_trash,
                permission_document_version_revert, permission_document_view,
                permission_events_view, permission_transformation_create,
                permission_transformation_delete,
                permission_transformation_edit, permission_transformation_view,
            )
        )

        ModelPermission.register(
            model=DocumentType, permissions=(permission_document_create,)
        )

        ModelPermission.register_proxy(
            source=Document, model=DocumentType,
        )

        ModelPermission.register_inheritance(
            model=Document, related='document_type',
        )

        ModelPermission.register_inheritance(
            model=DocumentVersion, related='document',
        )

        ModelPermission.register_inheritance(
            model=DocumentPage, related='document',
        )

        SourceColumn(
            source=Document, label=_('Thumbnail'),
            func=lambda context: document_thumbnail(
                context['object'], gallery_name='documents:document_list',
                size=setting_thumbnail_size.value,
                title=getattr(context['object'], 'label', None),
            )
        )
        SourceColumn(
            source=Document, label=_('Type'), attribute='document_type'
        )

        SourceColumn(
            source=DocumentType, label=_('Documents'),
            func=lambda context: context['object'].get_document_count(
                user=context['request'].user
            )
        )

        SourceColumn(
            source=DocumentTypeFilename, label=_('Enabled'),
            func=lambda context: two_state_template(context['object'].enabled)
        )

        SourceColumn(
            source=DeletedDocument, label=_('Thumbnail'),
            func=lambda context: document_thumbnail(
                context['object'],
                gallery_name='documents:delete_document_list',
                size=setting_thumbnail_size.value,
                title=getattr(context['object'], 'label', None),
                disable_title_link=True
            )
        )
        SourceColumn(
            source=DeletedDocument, label=_('Type'), attribute='document_type'
        )
        SourceColumn(
            source=DeletedDocument, label=_('Date time trashed'),
            attribute='deleted_date_time'
        )

        SourceColumn(
            source=DocumentVersion, label=_('Time and date'),
            attribute='timestamp'
        )
        SourceColumn(
            source=DocumentVersion, label=_('MIME type'),
            attribute='mimetype'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Encoding'),
            attribute='encoding'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Comment'),
            attribute='comment'
        )

        app.conf.CELERYBEAT_SCHEDULE.update(
            {
                'task_check_delete_periods': {
                    'task': 'documents.tasks.task_check_delete_periods',
                    'schedule': timedelta(
                        seconds=CHECK_DELETE_PERIOD_INTERVAL
                    ),
                },
                'task_check_trash_periods': {
                    'task': 'documents.tasks.task_check_trash_periods',
                    'schedule': timedelta(seconds=CHECK_TRASH_PERIOD_INTERVAL),
                },
                'task_delete_stubs': {
                    'task': 'documents.tasks.task_delete_stubs',
                    'schedule': timedelta(seconds=DELETE_STALE_STUBS_INTERVAL),
                },
            }
        )

        app.conf.CELERY_QUEUES.extend(
            (
                Queue(
                    'converter', Exchange('converter'),
                    routing_key='converter', delivery_mode=1
                ),
                Queue(
                    'documents_periodic', Exchange('documents_periodic'),
                    routing_key='documents_periodic', delivery_mode=1
                ),
                Queue('uploads', Exchange('uploads'), routing_key='uploads'),
            )
        )

        app.conf.CELERY_ROUTES.update(
            {
                'documents.tasks.task_check_delete_periods': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_check_trash_periods': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_delete_stubs': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_clear_image_cache': {
                    'queue': 'tools'
                },
                'documents.tasks.task_get_document_page_image': {
                    'queue': 'converter'
                },
                'documents.tasks.task_update_page_count': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_upload_new_version': {
                    'queue': 'uploads'
                },
            }
        )

        menu_front_page.bind_links(
            links=(
                link_document_list_recent, link_document_list,
                link_document_list_deleted
            )
        )
        menu_setup.bind_links(links=(link_document_type_setup,))
        menu_tools.bind_links(links=(link_clear_image_cache,))

        # Document type links
        menu_object.bind_links(
            links=(
                link_document_type_edit, link_document_type_filename_list,
                link_acl_list, link_document_type_delete
            ), sources=(DocumentType,)
        )
        menu_object.bind_links(
            links=(
                link_document_type_filename_edit,
                link_document_type_filename_delete
            ), sources=(DocumentTypeFilename,)
        )
        menu_secondary.bind_links(
            links=(link_document_type_list, link_document_type_create),
            sources=(
                DocumentType, 'documents:document_type_create',
                'documents:document_type_list'
            )
        )
        menu_sidebar.bind_links(
            links=(link_document_type_filename_create,),
            sources=(
                DocumentTypeFilename, 'documents:document_type_filename_list',
                'documents:document_type_filename_create'
            )
        )
        menu_sidebar.bind_links(
            links=(link_trash_can_empty,),
            sources=(
                'documents:document_list_deleted', 'documents:trash_can_empty'
            )
        )

        # Document object links
        menu_object.bind_links(
            links=(
                link_document_edit, link_document_document_type_edit,
                link_document_print, link_document_trash,
                link_document_download, link_document_clear_transformations,
                link_document_update_page_count
            ), sources=(Document,)
        )
        menu_object.bind_links(
            links=(link_document_restore, link_document_delete),
            sources=(DeletedDocument,)
        )

        # Document facet links
        menu_facet.bind_links(links=(link_acl_list,), sources=(Document,))
        menu_facet.bind_links(
            links=(link_document_preview,), sources=(Document,), position=0
        )
        menu_facet.bind_links(
            links=(link_document_properties,), sources=(Document,), position=2
        )
        menu_facet.bind_links(
            links=(link_events_for_object, link_document_version_list,),
            sources=(Document,), position=2
        )
        menu_facet.bind_links(links=(link_document_pages,), sources=(Document,))

        # Document actions
        menu_object.bind_links(
            links=(
                link_document_version_revert, link_document_version_download
            ),
            sources=(DocumentVersion,)
        )
        menu_multi_item.bind_links(
            links=(
                link_document_multiple_clear_transformations,
                link_document_multiple_trash, link_document_multiple_download,
                link_document_multiple_update_page_count,
                link_document_multiple_document_type_edit
            ), sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(
                link_document_multiple_restore, link_document_multiple_delete
            ), sources=(DeletedDocument,)
        )

        # Document pages
        menu_facet.bind_links(
            links=(
                link_document_page_rotate_left,
                link_document_page_rotate_right, link_document_page_zoom_in,
                link_document_page_zoom_out, link_document_page_view_reset
            ), sources=('documents:document_page_view',)
        )
        menu_facet.bind_links(
            links=(link_document_page_return, link_document_page_view),
            sources=(DocumentPage,)
        )
        menu_facet.bind_links(
            links=(
                link_document_page_navigation_first,
                link_document_page_navigation_previous,
                link_document_page_navigation_next,
                link_document_page_navigation_last, link_transformation_list
            ), sources=(DocumentPage,)
        )
        menu_object.bind_links(
            links=(link_transformation_list,), sources=(DocumentPage,)
        )

        namespace = StatisticNamespace(slug='documents', label=_('Documents'))
        namespace.add_statistic(
            slug='new-documents-per-month',
            label=_('New documents per month'),
            func=new_documents_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='new-document-versions-per-month',
            label=_('New document versions per month'),
            func=new_document_versions_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='new-document-pages-per-month',
            label=_('New document pages per month'),
            func=new_document_pages_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-documents-at-each-month',
            label=_('Total documents at each month'),
            func=total_document_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-document-versions-at-each-month',
            label=_('Total document versions at each month'),
            func=total_document_version_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-document-pages-at-each-month',
            label=_('Total document pages at each month'),
            func=total_document_page_per_month,
            renderer=CharJSLine,
            minute='0'
        )

        post_initial_setup.connect(
            create_default_document_type,
            dispatch_uid='create_default_document_type'
        )

        registry.register(DeletedDocument)
        registry.register(Document)
Beispiel #2
0
class_permissions(Document, [
    PERMISSION_DOCUMENT_PROPERTIES_EDIT,
    PERMISSION_DOCUMENT_EDIT,
    PERMISSION_DOCUMENT_VIEW,
    PERMISSION_DOCUMENT_DELETE,
    PERMISSION_DOCUMENT_DOWNLOAD,
    PERMISSION_DOCUMENT_TRANSFORM,
    PERMISSION_DOCUMENT_NEW_VERSION,
    PERMISSION_DOCUMENT_VERSION_REVERT,
    PERMISSION_HISTORY_VIEW
])

document_search = SearchModel('documents', 'Document')
document_search.add_model_field('document_type__name', label=_(u'Document type'))
document_search.add_model_field('versions__mimetype', label=_(u'MIME type'))
document_search.add_model_field('versions__filename', label=_(u'Filename'))
document_search.add_model_field('metadata__metadata_type__name', label=_(u'Metadata type'))
document_search.add_model_field('metadata__value', label=_(u'Metadata value'))
document_search.add_model_field('versions__pages__content', label=_(u'Content'))
document_search.add_model_field('description', label=_(u'Description'))
document_search.add_model_field('tags__name', label=_(u'Tags'))
document_search.add_related_field('comments', 'Comment', 'comment', 'object_pk', label=_(u'Comments'))

namespace = StatisticNamespace(name='documents', label=_(u'Documents'))
namespace.add_statistic(DocumentStatistics(name='document_stats', label=_(u'Document tendencies')))
namespace.add_statistic(DocumentUsageStatistics(name='document_usage', label=_(u'Document usage')))

endpoint = APIEndPoint('documents')
endpoint.register_urls(api_urls)
endpoint.add_endpoint('document-list')
Beispiel #3
0
])

document_search = SearchModel('documents', 'Document')
document_search.add_model_field('document_type__name',
                                label=_(u'Document type'))
document_search.add_model_field('versions__mimetype', label=_(u'MIME type'))
document_search.add_model_field('versions__filename', label=_(u'Filename'))
document_search.add_model_field('metadata__metadata_type__name',
                                label=_(u'Metadata type'))
document_search.add_model_field('metadata__value', label=_(u'Metadata value'))
document_search.add_model_field('versions__pages__content',
                                label=_(u'Content'))
document_search.add_model_field('description', label=_(u'Description'))
document_search.add_model_field('tags__name', label=_(u'Tags'))
document_search.add_related_field('comments',
                                  'Comment',
                                  'comment',
                                  'object_pk',
                                  label=_(u'Comments'))

namespace = StatisticNamespace(name='documents', label=_(u'Documents'))
namespace.add_statistic(
    DocumentStatistics(name='document_stats', label=_(u'Document tendencies')))
namespace.add_statistic(
    DocumentUsageStatistics(name='document_usage', label=_(u'Document usage')))

endpoint = APIEndPoint('documents')
endpoint.register_urls(api_urls)
endpoint.add_endpoint('document-list',
                      _(u'Returns a list of all the documents.'))
Beispiel #4
0
            except AlreadyQueued:
                pass


@receiver(post_syncdb, dispatch_uid='create_default_queue', sender=ocr_models)
def create_default_queue_signal_handler(sender, **kwargs):
    default_queue, created = DocumentQueue.objects.get_or_create(name='default')


def reset_queue_documents():
    try:
        default_queue = DocumentQueue.objects.get(name='default')
    except (DatabaseError, DocumentQueue.DoesNotExist):
        pass
    else:
        default_queue.queuedocument_set.filter(state=QUEUEDOCUMENT_STATE_PROCESSING).update(state=QUEUEDOCUMENT_STATE_PENDING)


register_interval_job('task_process_document_queues', _(u'Checks the OCR queue for pending documents.'), task_process_document_queues, seconds=QUEUE_PROCESSING_INTERVAL)

register_tool(ocr_tool_link)

class_permissions(Document, [
    PERMISSION_OCR_DOCUMENT,
])

reset_queue_documents()

namespace = StatisticNamespace(name='ocr', label=_(u'OCR'))
namespace.add_statistic(OCRStatistics(name='ocr_stats', label=_(u'OCR queue statistics')))
Beispiel #5
0
    def ready(self):
        super(DocumentsApp, self).ready()

        APIEndPoint(app=self, version_string='1')

        MissingItem(
            label=_('Create a document type'),
            description=_(
                'Every uploaded document must be assigned a document type, '
                'it is the basic way Mayan EDMS categorizes documents.'
            ), condition=lambda: not DocumentType.objects.exists(),
            view='documents:document_type_list'
        )

        ModelAttribute(
            Document, label=_('Label'), name='label', type_name='field'
        )

        ModelAttribute(
            Document,
            description=_('The MIME type of any of the versions of a document'),
            label=_('MIME type'), name='versions__mimetype', type_name='field'
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_document_delete, permission_document_download,
                permission_document_edit, permission_document_new_version,
                permission_document_print, permission_document_properties_edit,
                permission_document_trash, permission_document_version_revert,
                permission_document_view, permission_events_view,
                permission_transformation_create,
                permission_transformation_delete,
                permission_transformation_edit, permission_transformation_view,
            )
        )

        ModelPermission.register_proxy(
            source=Document, model=DocumentType,
        )

        ModelPermission.register_inheritance(
            model=Document, related='document_type',
        )

        ModelPermission.register_inheritance(
            model=DocumentVersion, related='document',
        )

        ModelPermission.register_inheritance(
            model=DocumentPage, related='document',
        )

        SourceColumn(
            source=Document, label=_('Thumbnail'),
            func=lambda context: document_thumbnail(
                context['object'], gallery_name='documents:document_list',
                size=setting_thumbnail_size.value,
                title=getattr(context['object'], 'label', None),
            )
        )
        SourceColumn(
            source=Document, label=_('Type'), attribute='document_type'
        )

        SourceColumn(
            source=DocumentType, label=_('Documents'),
            func=lambda context: context['object'].get_document_count(
                user=context['request'].user
            )
        )

        SourceColumn(
            source=DocumentTypeFilename, label=_('Enabled'),
            func=lambda context: two_state_template(context['object'].enabled)
        )

        SourceColumn(
            source=DeletedDocument, label=_('Thumbnail'),
            func=lambda context: document_thumbnail(
                context['object'],
                gallery_name='documents:delete_document_list',
                size=setting_thumbnail_size.value,
                title=getattr(context['object'], 'label', None),
                disable_title_link=True
            )
        )
        SourceColumn(
            source=DeletedDocument, label=_('Type'), attribute='document_type'
        )
        SourceColumn(
            source=DeletedDocument, label=_('Date time trashed'),
            attribute='deleted_date_time'
        )

        SourceColumn(
            source=DocumentVersion, label=_('Time and date'),
            attribute='timestamp'
        )
        SourceColumn(
            source=DocumentVersion, label=_('MIME type'),
            attribute='mimetype'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Encoding'),
            attribute='encoding'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Comment'),
            attribute='comment'
        )

        app.conf.CELERYBEAT_SCHEDULE.update(
            {
                'task_check_delete_periods': {
                    'task': 'documents.tasks.task_check_delete_periods',
                    'schedule': timedelta(
                        seconds=CHECK_DELETE_PERIOD_INTERVAL
                    ),
                },
                'task_check_trash_periods': {
                    'task': 'documents.tasks.task_check_trash_periods',
                    'schedule': timedelta(seconds=CHECK_TRASH_PERIOD_INTERVAL),
                },
                'task_delete_stubs': {
                    'task': 'documents.tasks.task_delete_stubs',
                    'schedule': timedelta(seconds=DELETE_STALE_STUBS_INTERVAL),
                },
            }
        )

        app.conf.CELERY_QUEUES.extend(
            (
                Queue(
                    'converter', Exchange('converter'),
                    routing_key='converter', delivery_mode=1
                ),
                Queue(
                    'documents_periodic', Exchange('documents_periodic'),
                    routing_key='documents_periodic', delivery_mode=1
                ),
                Queue('uploads', Exchange('uploads'), routing_key='uploads'),
            )
        )

        app.conf.CELERY_ROUTES.update(
            {
                'documents.tasks.task_check_delete_periods': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_check_trash_periods': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_delete_stubs': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_clear_image_cache': {
                    'queue': 'tools'
                },
                'documents.tasks.task_get_document_page_image': {
                    'queue': 'converter'
                },
                'documents.tasks.task_update_page_count': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_upload_new_version': {
                    'queue': 'uploads'
                },
            }
        )

        menu_front_page.bind_links(
            links=(
                link_document_list_recent, link_document_list,
                link_document_list_deleted
            )
        )
        menu_setup.bind_links(links=(link_document_type_setup,))
        menu_tools.bind_links(links=(link_clear_image_cache,))

        # Document type links
        menu_object.bind_links(
            links=(
                link_document_type_edit, link_document_type_filename_list,
                link_acl_list, link_document_type_delete
            ), sources=(DocumentType,)
        )
        menu_object.bind_links(
            links=(
                link_document_type_filename_edit,
                link_document_type_filename_delete
            ), sources=(DocumentTypeFilename,)
        )
        menu_secondary.bind_links(
            links=(link_document_type_list, link_document_type_create),
            sources=(
                DocumentType, 'documents:document_type_create',
                'documents:document_type_list'
            )
        )
        menu_sidebar.bind_links(
            links=(link_document_type_filename_create,),
            sources=(
                DocumentTypeFilename, 'documents:document_type_filename_list',
                'documents:document_type_filename_create'
            )
        )
        menu_sidebar.bind_links(
            links=(link_trash_can_empty,),
            sources=(
                'documents:document_list_deleted', 'documents:trash_can_empty'
            )
        )

        # Document object links
        menu_object.bind_links(
            links=(
                link_document_edit, link_document_document_type_edit,
                link_document_print, link_document_trash,
                link_document_download, link_document_clear_transformations,
                link_document_update_page_count
            ), sources=(Document,)
        )
        menu_object.bind_links(
            links=(link_document_restore, link_document_delete),
            sources=(DeletedDocument,)
        )

        # Document facet links
        menu_facet.bind_links(links=(link_acl_list,), sources=(Document,))
        menu_facet.bind_links(
            links=(link_document_preview,), sources=(Document,), position=0
        )
        menu_facet.bind_links(
            links=(link_document_properties,), sources=(Document,), position=2
        )
        menu_facet.bind_links(
            links=(link_events_for_object, link_document_version_list,),
            sources=(Document,), position=2
        )
        menu_facet.bind_links(links=(link_document_pages,), sources=(Document,))

        # Document actions
        menu_object.bind_links(
            links=(
                link_document_version_revert, link_document_version_download
            ),
            sources=(DocumentVersion,)
        )
        menu_multi_item.bind_links(
            links=(
                link_document_multiple_clear_transformations,
                link_document_multiple_trash, link_document_multiple_download,
                link_document_multiple_update_page_count,
                link_document_multiple_document_type_edit
            ), sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(
                link_document_multiple_restore, link_document_multiple_delete
            ), sources=(DeletedDocument,)
        )

        # Document pages
        menu_facet.bind_links(
            links=(
                link_document_page_rotate_left,
                link_document_page_rotate_right, link_document_page_zoom_in,
                link_document_page_zoom_out, link_document_page_view_reset
            ), sources=('documents:document_page_view',)
        )
        menu_facet.bind_links(
            links=(link_document_page_return, link_document_page_view),
            sources=(DocumentPage,)
        )
        menu_facet.bind_links(
            links=(
                link_document_page_navigation_first,
                link_document_page_navigation_previous,
                link_document_page_navigation_next,
                link_document_page_navigation_last, link_transformation_list
            ), sources=(DocumentPage,)
        )
        menu_object.bind_links(
            links=(link_transformation_list,), sources=(DocumentPage,)
        )

        namespace = StatisticNamespace(slug='documents', label=_('Documents'))
        namespace.add_statistic(
            slug='new-documents-per-month',
            label=_('New documents per month'),
            func=new_documents_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='new-document-versions-per-month',
            label=_('New document versions per month'),
            func=new_document_versions_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='new-document-pages-per-month',
            label=_('New document pages per month'),
            func=new_document_pages_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-documents-at-each-month',
            label=_('Total documents at each month'),
            func=total_document_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-document-versions-at-each-month',
            label=_('Total document versions at each month'),
            func=total_document_version_per_month,
            renderer=CharJSLine,
            minute='0'
        )
        namespace.add_statistic(
            slug='total-document-pages-at-each-month',
            label=_('Total document pages at each month'),
            func=total_document_page_per_month,
            renderer=CharJSLine,
            minute='0'
        )

        post_initial_setup.connect(
            create_default_document_type,
            dispatch_uid='create_default_document_type'
        )

        registry.register(DeletedDocument)
        registry.register(Document)
Beispiel #6
0
        DocumentQueue.objects.get_or_create(name='default')


def reset_queue_documents():
    try:
        default_queue = DocumentQueue.objects.get(name='default')
    except (DatabaseError, DocumentQueue.DoesNotExist):
        pass
    else:
        default_queue.queuedocument_set.filter(
            state=QUEUEDOCUMENT_STATE_PROCESSING).update(
                state=QUEUEDOCUMENT_STATE_PENDING)


register_interval_job('task_process_document_queues',
                      _(u'Checks the OCR queue for pending documents.'),
                      task_process_document_queues,
                      seconds=QUEUE_PROCESSING_INTERVAL)

register_tool(ocr_tool_link)

class_permissions(Document, [
    PERMISSION_OCR_DOCUMENT,
])

reset_queue_documents()

namespace = StatisticNamespace(name='ocr', label=_(u'OCR'))
namespace.add_statistic(
    OCRStatistics(name='ocr_stats', label=_(u'OCR queue statistics')))