Exemplo n.º 1
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()

        ModelPermission.register(
            model=Document, permissions=(
                permission_comment_create, permission_comment_delete,
                permission_comment_view
            )
        )

        SourceColumn(source=Comment, label=_('Date'), attribute='submit_date')
        SourceColumn(
            source=Comment, label=_('User'),
            func=lambda context: context['object'].user.get_full_name() if context['object'].user.get_full_name() else context['object'].user
        )
        SourceColumn(source=Comment, label=_('Comment'), attribute='comment')

        menu_sidebar.bind_links(
            links=(link_comment_add,),
            sources=(
                'comments:comments_for_document', 'comments:comment_add',
                'comments:comment_delete', 'comments:comment_multiple_delete'
            )
        )
        menu_object.bind_links(
            links=(link_comment_delete,), sources=(Comment,)
        )
        menu_facet.bind_links(
            links=(link_comments_for_document,), sources=(Document,)
        )
Exemplo n.º 2
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')

        Comment = self.get_model('Comment')

        ModelPermission.register(model=Document,
                                 permissions=(permission_comment_create,
                                              permission_comment_delete,
                                              permission_comment_view))

        SourceColumn(source=Comment, label=_('Date'), attribute='submit_date')
        SourceColumn(
            source=Comment,
            label=_('User'),
            func=lambda context: context['object'].user.get_full_name()
            if context['object'].user.get_full_name() else context['object'
                                                                   ].user)
        SourceColumn(source=Comment, label=_('Comment'), attribute='comment')

        menu_sidebar.bind_links(links=(link_comment_add, ),
                                sources=('comments:comments_for_document',
                                         'comments:comment_add',
                                         'comments:comment_delete',
                                         'comments:comment_multiple_delete'))
        menu_object.bind_links(links=(link_comment_delete, ),
                               sources=(Comment, ))
        menu_facet.bind_links(links=(link_comments_for_document, ),
                              sources=(Document, ))
Exemplo n.º 3
0
    def ready(self):
        super(SmartSettingsApp, self).ready()

        Namespace.initialize()

        SourceColumn(source=Namespace,
                     label=_('Setting count'),
                     func=lambda context: len(context['object'].settings))
        SourceColumn(source=Setting,
                     label=_('Name'),
                     func=lambda context: setting_widget(context['object']))
        SourceColumn(source=Setting,
                     label=_('Value'),
                     attribute='serialized_value')
        SourceColumn(source=Setting,
                     label=_('Overrided by environment variable?'),
                     func=lambda context: _('Yes')
                     if context['object'].environment_variable else _('No'))

        menu_object.bind_links(links=(link_namespace_detail, ),
                               sources=(Namespace, ))
        menu_object.bind_links(links=(link_setting_edit, ),
                               sources=(Setting, ))
        menu_sidebar.bind_links(links=(link_namespace_root_list, ),
                                sources=(
                                    Namespace,
                                    Setting,
                                    'settings:namespace_list',
                                ))
        menu_setup.bind_links(links=(link_namespace_list, ))

        Setting.save_last_known_good()
Exemplo n.º 4
0
    def ready(self):
        super(SmartSettingsApp, self).ready()

        Namespace.initialize()

        SourceColumn(
            source=Namespace, label=_('Setting count'),
            func=lambda context: len(context['object'].settings)
        )
        SourceColumn(
            source=Setting, label=_('Name'),
            func=lambda context: setting_widget(context['object'])
        )
        SourceColumn(
            source=Setting, label=_('Value'), attribute='serialized_value'
        )
        SourceColumn(
            source=Setting, label=_('Overrided by environment variable?'),
            func=lambda context: _('Yes') if context['object'].environment_variable else _('No')
        )

        menu_object.bind_links(
            links=(link_namespace_detail,), sources=(Namespace,)
        )
        menu_object.bind_links(
            links=(link_setting_edit,), sources=(Setting,)
        )
        menu_sidebar.bind_links(
            links=(link_namespace_root_list,), sources=(
                Namespace, Setting, 'settings:namespace_list',
            )
        )
        menu_setup.bind_links(links=(link_namespace_list,))

        Setting.save_last_known_good()
Exemplo n.º 5
0
    def ready(self):
        super(ConverterApp, self).ready()

        Transformation = self.get_model('Transformation')

        SourceColumn(source=Transformation, label=_('Order'), attribute='order')
        SourceColumn(
            source=Transformation, label=_('Transformation'),
            func=lambda context: force_text(context['object'])
        )
        SourceColumn(
            source=Transformation, label=_('Arguments'), attribute='arguments'
        )

        menu_object.bind_links(
            links=(link_transformation_edit, link_transformation_delete),
            sources=(Transformation,)
        )
        menu_sidebar.bind_links(
            links=(link_transformation_create,), sources=(Transformation,)
        )
        menu_sidebar.bind_links(
            links=(link_transformation_create,),
            sources=(
                'converter:transformation_create',
                'converter:transformation_list'
            )
        )
Exemplo n.º 6
0
    def ready(self):
        super(DocumentSignaturesApp, self).ready()

        DocumentVersion.register_post_save_hook(
            1, document_version_post_save_hook)
        DocumentVersion.register_pre_open_hook(1, document_pre_open_hook)

        ModelPermission.register(model=Document,
                                 permissions=(
                                     permission_document_verify,
                                     permission_signature_delete,
                                     permission_signature_download,
                                     permission_signature_upload,
                                 ))

        menu_facet.bind_links(links=(link_document_verify, ),
                              sources=(Document, ))
        menu_sidebar.bind_links(
            links=(link_document_signature_upload,
                   link_document_signature_download,
                   link_document_signature_delete),
            sources=('signatures:document_verify',
                     'signatures:document_signature_upload',
                     'signatures:document_signature_download',
                     'signatures:document_signature_delete'))
Exemplo n.º 7
0
    def ready(self):
        super(LinkingApp, self).ready()

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

        Document = apps.get_model(app_label='documents', model_name='Document')

        ResolvedSmartLink = self.get_model('ResolvedSmartLink')
        SmartLink = self.get_model('SmartLink')
        SmartLinkCondition = self.get_model('SmartLinkCondition')

        ModelPermission.register(model=SmartLink,
                                 permissions=(permission_acl_edit,
                                              permission_acl_view,
                                              permission_smart_link_delete,
                                              permission_smart_link_edit,
                                              permission_smart_link_view))

        SourceColumn(source=ResolvedSmartLink,
                     label=_('Label'),
                     func=lambda context: context['object'].get_dynamic_label(
                         context['document']))

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

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

        menu_facet.bind_links(links=(link_smart_link_instances_for_document, ),
                              sources=(Document, ))
        menu_object.bind_links(links=(link_smart_link_condition_edit,
                                      link_smart_link_condition_delete),
                               sources=(SmartLinkCondition, ))
        menu_object.bind_links(links=(link_smart_link_edit,
                                      link_smart_link_document_types,
                                      link_smart_link_condition_list,
                                      link_acl_list, link_smart_link_delete),
                               sources=(SmartLink, ))
        menu_object.bind_links(links=(link_smart_link_instance_view, ),
                               sources=(ResolvedSmartLink, ))
        menu_secondary.bind_links(links=(link_smart_link_list,
                                         link_smart_link_create),
                                  sources=(SmartLink,
                                           'linking:smart_link_list',
                                           'linking:smart_link_create'))
        menu_setup.bind_links(links=(link_smart_link_setup, ))
        menu_sidebar.bind_links(
            links=(link_smart_link_condition_create, ),
            sources=('linking:smart_link_condition_list',
                     'linking:smart_link_condition_create',
                     'linking:smart_link_condition_edit',
                     'linking:smart_link_condition_delete'))
Exemplo n.º 8
0
    def ready(self):
        super(ConverterApp, self).ready()

        Package(label='Pillow',
                license_text='''
The Python Imaging Library (PIL) is

    Copyright (c) 1997-2011 by Secret Labs AB
    Copyright (c) 1995-2011 by Fredrik Lundh

By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions:

Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        ''')

        SourceColumn(source=Transformation,
                     label=_('Order'),
                     attribute='order')
        SourceColumn(source=Transformation,
                     label=_('Transformation'),
                     func=lambda context: unicode(context['object']))
        SourceColumn(source=Transformation,
                     label=_('Arguments'),
                     attribute='arguments')

        menu_object.bind_links(links=(link_transformation_edit,
                                      link_transformation_delete),
                               sources=(Transformation, ))
        menu_sidebar.bind_links(links=(link_transformation_create, ),
                                sources=(Transformation, ))
        menu_sidebar.bind_links(links=(link_transformation_create, ),
                                sources=('converter:transformation_create',
                                         'converter:transformation_list'))
Exemplo n.º 9
0
    def ready(self):
        super(CheckoutsApp, self).ready()

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

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentCheckout = self.get_model('DocumentCheckout')

        Document.add_to_class('check_in',
                              lambda document, user=None: DocumentCheckout.
                              objects.check_in_document(document, user))
        Document.add_to_class(
            'checkout_info', lambda document: DocumentCheckout.objects.
            document_checkout_info(document))
        Document.add_to_class(
            'checkout_state', lambda document: DocumentCheckout.objects.
            document_checkout_state(document))
        Document.add_to_class(
            'is_checked_out', lambda document: DocumentCheckout.objects.
            is_document_checked_out(document))

        ModelPermission.register(
            model=Document,
            permissions=(permission_document_checkout,
                         permission_document_checkin,
                         permission_document_checkin_override,
                         permission_document_checkout_detail_view))

        app.conf.CELERYBEAT_SCHEDULE.update({
            'task_check_expired_check_outs': {
                'task': 'checkouts.tasks.task_check_expired_check_outs',
                'schedule':
                timedelta(seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL),
            },
        })

        app.conf.CELERY_QUEUES.append(
            Queue('checkouts_periodic',
                  Exchange('checkouts_periodic'),
                  routing_key='checkouts_periodic',
                  delivery_mode=1), )

        app.conf.CELERY_ROUTES.update({
            'checkouts.tasks.task_check_expired_check_outs': {
                'queue': 'checkouts_periodic'
            },
        })

        menu_facet.bind_links(links=(link_checkout_info, ),
                              sources=(Document, ))
        menu_main.bind_links(links=(link_checkout_list, ))
        menu_sidebar.bind_links(links=(link_checkout_document,
                                       link_checkin_document),
                                sources=('checkouts:checkout_info',
                                         'checkouts:checkout_document',
                                         'checkouts:checkin_document'))
Exemplo n.º 10
0
    def ready(self):
        super(DynamicSearchApp, self).ready()

        menu_facet.bind_links(links=(link_search, link_search_advanced),
                              sources=('search:search',
                                       'search:search_advanced',
                                       'search:results'))
        menu_sidebar.bind_links(links=(link_search_again, ),
                                sources=('search:results', ))
Exemplo n.º 11
0
    def ready(self):
        super(DjangoGPGApp, self).ready()

        APIEndPoint(app=self, version_string='1')
        Key = self.get_model('Key')

        ModelPermission.register(
            model=Key, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_key_delete, permission_key_download,
                permission_key_sign, permission_key_view
            )
        )

        SourceColumn(source=Key, label=_('Key ID'), attribute='key_id')
        SourceColumn(source=Key, label=_('User ID'), attribute='user_id')

        SourceColumn(source=KeyStub, label=_('Key ID'), attribute='key_id')
        SourceColumn(source=KeyStub, label=_('Type'), attribute='key_type')
        SourceColumn(
            source=KeyStub, label=_('Creation date'), attribute='date'
        )
        SourceColumn(
            source=KeyStub, label=_('Expiration date'),
            func=lambda context: context['object'].expires or _('No expiration')
        )
        SourceColumn(source=KeyStub, label=_('Length'), attribute='length')
        SourceColumn(
            source=KeyStub, label=_('User ID'),
            func=lambda context: ', '.join(context['object'].user_id)
        )

        menu_object.bind_links(links=(link_key_detail,), sources=(Key,))
        menu_object.bind_links(links=(link_key_receive,), sources=(KeyStub,))

        menu_object.bind_links(
            links=(link_acl_list, link_key_delete, link_key_download,),
            sources=(Key,)
        )
        menu_setup.bind_links(links=(link_key_setup,))
        menu_facet.bind_links(
            links=(link_private_keys, link_public_keys),
            sources=(
                'django_gpg:key_public_list', 'django_gpg:key_private_list',
                'django_gpg:key_query', 'django_gpg:key_query_results', Key,
                KeyStub
            )
        )
        menu_sidebar.bind_links(
            links=(link_key_query, link_key_upload),
            sources=(
                'django_gpg:key_public_list', 'django_gpg:key_private_list',
                'django_gpg:key_query', 'django_gpg:key_query_results', Key,
                KeyStub
            )
        )
Exemplo n.º 12
0
    def ready(self):
        super(DynamicSearchApp, self).ready()

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

        menu_facet.bind_links(
            links=(link_search, link_search_advanced),
            sources=("search:search", "search:search_advanced", "search:results"),
        )
        menu_sidebar.bind_links(links=(link_search_again,), sources=("search:results",))
Exemplo n.º 13
0
    def ready(self):
        super(DjangoGPGApp, self).ready()

        Key = self.get_model('Key')

        ModelPermission.register(
            model=Key, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_key_delete, permission_key_download,
                permission_key_sign, permission_key_view
            )
        )

        SourceColumn(source=Key, label=_('Key ID'), attribute='key_id')
        SourceColumn(source=Key, label=_('User ID'), attribute='user_id')

        SourceColumn(source=KeyStub, label=_('Key ID'), attribute='key_id')
        SourceColumn(source=KeyStub, label=_('Type'), attribute='key_type')
        SourceColumn(
            source=KeyStub, label=_('Creation date'), attribute='date'
        )
        SourceColumn(
            source=KeyStub, label=_('Expiration date'),
            func=lambda context: context['object'].expires or _('No expiration')
        )
        SourceColumn(source=KeyStub, label=_('Length'), attribute='length')
        SourceColumn(
            source=KeyStub, label=_('User ID'),
            func=lambda context: ', '.join(context['object'].user_id)
        )

        menu_object.bind_links(links=(link_key_detail,), sources=(Key,))
        menu_object.bind_links(links=(link_key_receive,), sources=(KeyStub,))

        menu_object.bind_links(
            links=(link_acl_list, link_key_delete, link_key_download,),
            sources=(Key,)
        )
        menu_setup.bind_links(links=(link_key_setup,))
        menu_facet.bind_links(
            links=(link_private_keys, link_public_keys),
            sources=(
                'django_gpg:key_public_list', 'django_gpg:key_private_list',
                'django_gpg:key_query', 'django_gpg:key_query_results',
                'django_gpg:key_upload', Key, KeyStub
            )
        )
        menu_sidebar.bind_links(
            links=(link_key_query, link_key_upload),
            sources=(
                'django_gpg:key_public_list', 'django_gpg:key_private_list',
                'django_gpg:key_query', 'django_gpg:key_query_results',
                'django_gpg:key_upload', Key, KeyStub
            )
        )
Exemplo n.º 14
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()

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

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        Comment = self.get_model('Comment')

        ModelEventType.register(
            model=Document, event_types=(
                event_document_comment_create, event_document_comment_delete
            )
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_comment_create, permission_comment_delete,
                permission_comment_view
            )
        )

        SourceColumn(source=Comment, label=_('Date'), attribute='submit_date')
        SourceColumn(
            source=Comment, label=_('User'),
            func=lambda context: context['object'].user.get_full_name() if context['object'].user.get_full_name() else context['object'].user
        )
        SourceColumn(source=Comment, label=_('Comment'), attribute='comment')

        document_page_search.add_model_field(
            field='document_version__document__comments__comment',
            label=_('Comments')
        )
        document_search.add_model_field(
            field='comments__comment',
            label=_('Comments')
        )

        menu_sidebar.bind_links(
            links=(link_comment_add,),
            sources=(
                'comments:comments_for_document', 'comments:comment_add',
                'comments:comment_delete', 'comments:comment_multiple_delete'
            )
        )
        menu_object.bind_links(
            links=(link_comment_delete,), sources=(Comment,)
        )
        menu_facet.bind_links(
            links=(link_comments_for_document,), sources=(Document,)
        )
Exemplo n.º 15
0
    def ready(self):
        super(FoldersApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentFolder = self.get_model('DocumentFolder')
        Folder = self.get_model('Folder')

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

        Document.add_to_class(
            'document_folders',
            lambda document: DocumentFolder.objects.filter(documents=document))

        ModelPermission.register(
            model=Document,
            permissions=(permission_folder_add_document,
                         permission_folder_remove_document))

        ModelPermission.register(
            model=Folder,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_folder_delete, permission_folder_edit,
                         permission_folder_view))

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

        menu_facet.bind_links(links=(link_document_folder_list, ),
                              sources=(Document, ))

        menu_folders.bind_links(links=(link_folder_list, link_folder_create))

        menu_main.bind_links(links=(menu_folders, ), position=98)
        menu_multi_item.bind_links(
            links=(link_folder_add_multiple_documents,
                   link_multiple_document_folder_remove),
            sources=(Document, ))
        menu_object.bind_links(links=(link_folder_view, ),
                               sources=(DocumentFolder, ))
        menu_object.bind_links(links=(link_folder_view, link_folder_edit,
                                      link_acl_list, link_folder_delete),
                               sources=(Folder, ))
        menu_sidebar.bind_links(links=(link_folder_add_document,
                                       link_document_folder_remove),
                                sources=('folders:document_folder_list',
                                         'folders:folder_add_document',
                                         'folders:document_folder_remove'))
Exemplo n.º 16
0
    def ready(self):
        super(DynamicSearchApp, self).ready()

        menu_facet.bind_links(
            links=(link_search, link_search_advanced),
            sources=(
                'search:search', 'search:search_advanced', 'search:results'
            )
        )
        menu_sidebar.bind_links(
            links=(link_search_again,), sources=('search:results',)
        )
Exemplo n.º 17
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        Comment = self.get_model('Comment')

        ModelEventType.register(
            model=Document, event_types=(
                event_document_comment_create, event_document_comment_delete
            )
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_comment_create, permission_comment_delete,
                permission_comment_view
            )
        )

        SourceColumn(source=Comment, label=_('Date'), attribute='submit_date')
        SourceColumn(
            source=Comment, label=_('User'),
            func=lambda context: context['object'].user.get_full_name() if context['object'].user.get_full_name() else context['object'].user
        )
        SourceColumn(source=Comment, label=_('Comment'), attribute='comment')

        document_page_search.add_model_field(
            field='document_version__document__comments__comment',
            label=_('Comments')
        )
        document_search.add_model_field(
            field='comments__comment',
            label=_('Comments')
        )

        menu_sidebar.bind_links(
            links=(link_comment_add,),
            sources=(
                'comments:comments_for_document', 'comments:comment_add',
                'comments:comment_delete', 'comments:comment_multiple_delete'
            )
        )
        menu_object.bind_links(
            links=(link_comment_delete,), sources=(Comment,)
        )
        menu_facet.bind_links(
            links=(link_comments_for_document,), sources=(Document,)
        )
Exemplo n.º 18
0
    def ready(self):
        super(CabinetsApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentCabinet = self.get_model('DocumentCabinet')
        Cabinet = self.get_model('Cabinet')

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

        Document.add_to_class(
            'document_cabinets', lambda document: DocumentCabinet.objects.
            filter(documents=document))

        ModelPermission.register(
            model=Document,
            permissions=(permission_cabinet_add_document,
                         permission_cabinet_remove_document))

        ModelPermission.register(
            model=Cabinet,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_cabinet_delete, permission_cabinet_edit,
                         permission_cabinet_view))

        menu_facet.bind_links(links=(link_document_cabinet_list, ),
                              sources=(Document, ))

        menu_cabinets.bind_links(links=(link_cabinet_list,
                                        link_cabinet_create))

        menu_main.bind_links(links=(menu_cabinets, ), position=98)

        menu_multi_item.bind_links(
            links=(link_cabinet_add_multiple_documents,
                   link_multiple_document_cabinet_remove),
            sources=(Document, ))
        menu_object.bind_links(links=(link_cabinet_view, ),
                               sources=(DocumentCabinet, ))
        menu_object.bind_links(links=(link_cabinet_view, link_cabinet_edit,
                                      link_custom_acl_list,
                                      link_cabinet_delete),
                               sources=(Cabinet, ))
        menu_sidebar.bind_links(links=(link_cabinet_child_add, ),
                                sources=(Cabinet, ))
        menu_sidebar.bind_links(links=(link_cabinet_add_document,
                                       link_document_cabinet_remove),
                                sources=('cabinets:document_cabinet_list',
                                         'cabinets:cabinet_add_document',
                                         'cabinets:document_cabinet_remove'))
Exemplo n.º 19
0
    def ready(self):
        super(ACLsApp, self).ready()

        SourceColumn(source=AccessControlList,
                     label=_('Permissions'),
                     attribute='get_permission_titles')
        SourceColumn(source=AccessControlList,
                     label=_('Role'),
                     attribute='role')

        menu_object.bind_links(links=(link_acl_permissions, link_acl_delete),
                               sources=(AccessControlList, ))
        menu_sidebar.bind_links(links=(link_acl_new, ),
                                sources=('acls:acl_list', ))
Exemplo n.º 20
0
    def ready(self):
        super(DynamicSearchApp, self).ready()

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

        menu_facet.bind_links(
            links=(link_search, link_search_advanced),
            sources=(
                'search:search', 'search:search_advanced', 'search:results'
            )
        )
        menu_sidebar.bind_links(
            links=(link_search_again,), sources=('search:results',)
        )
Exemplo n.º 21
0
    def ready(self):
        super(ACLsApp, self).ready()

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

        AccessControlList = self.get_model('AccessControlList')

        SourceColumn(source=AccessControlList,
                     label=_('Permissions'),
                     attribute='get_permission_titles')
        SourceColumn(source=AccessControlList,
                     label=_('Role'),
                     attribute='role')

        menu_object.bind_links(links=(link_acl_permissions, link_acl_delete),
                               sources=(AccessControlList, ))
        menu_sidebar.bind_links(links=(link_acl_create, ),
                                sources=('acls:acl_list', ))
Exemplo n.º 22
0
    def ready(self):
        super(ACLsApp, self).ready()

        SourceColumn(
            source=AccessControlList, label=_('Permissions'),
            attribute='get_permission_titles'
        )
        SourceColumn(
            source=AccessControlList, label=_('Role'), attribute='role'
        )

        menu_object.bind_links(
            links=(link_acl_permissions, link_acl_delete),
            sources=(AccessControlList,)
        )
        menu_sidebar.bind_links(
            links=(link_acl_new,), sources=('acls:acl_list',)
        )
Exemplo n.º 23
0
    def ready(self):
        super(ConverterApp, self).ready()

        Package(label='Pillow', license_text='''
The Python Imaging Library (PIL) is

    Copyright (c) 1997-2011 by Secret Labs AB
    Copyright (c) 1995-2011 by Fredrik Lundh

By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions:

Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        ''')

        SourceColumn(source=Transformation, label=_('Order'), attribute='order')
        SourceColumn(
            source=Transformation, label=_('Transformation'),
            func=lambda context: unicode(context['object'])
        )
        SourceColumn(
            source=Transformation, label=_('Arguments'), attribute='arguments'
        )

        menu_object.bind_links(
            links=(link_transformation_edit, link_transformation_delete),
            sources=(Transformation,)
        )
        menu_sidebar.bind_links(
            links=(link_transformation_create,), sources=(Transformation,)
        )
        menu_sidebar.bind_links(
            links=(link_transformation_create,),
            sources=(
                'converter:transformation_create',
                'converter:transformation_list'
            )
        )
Exemplo n.º 24
0
    def ready(self):
        super(ACLsApp, self).ready()

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

        AccessControlList = self.get_model('AccessControlList')

        SourceColumn(
            source=AccessControlList, label=_('Permissions'),
            attribute='get_permission_titles'
        )
        SourceColumn(
            source=AccessControlList, label=_('Role'), attribute='role'
        )

        menu_object.bind_links(
            links=(link_acl_permissions, link_acl_delete),
            sources=(AccessControlList,)
        )
        menu_sidebar.bind_links(
            links=(link_acl_create,), sources=('acls:acl_list',)
        )
Exemplo n.º 25
0
    def ready(self):
        super(ConverterApp, self).ready()

        Transformation = self.get_model('Transformation')

        SourceColumn(source=Transformation,
                     label=_('Order'),
                     attribute='order')
        SourceColumn(source=Transformation,
                     label=_('Transformation'),
                     func=lambda context: unicode(context['object']))
        SourceColumn(source=Transformation,
                     label=_('Arguments'),
                     attribute='arguments')

        menu_object.bind_links(links=(link_transformation_edit,
                                      link_transformation_delete),
                               sources=(Transformation, ))
        menu_sidebar.bind_links(links=(link_transformation_create, ),
                                sources=(Transformation, ))
        menu_sidebar.bind_links(links=(link_transformation_create, ),
                                sources=('converter:transformation_create',
                                         'converter:transformation_list'))
Exemplo n.º 26
0
    def ready(self):
        super(CabinetsApp, self).ready()
        from actstream import registry

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        DocumentCabinet = self.get_model('DocumentCabinet')
        Cabinet = self.get_model('Cabinet')

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

        # Add explicit order_by as DocumentCabinet ordering Meta option has no
        # effect.
        Document.add_to_class(
            'document_cabinets',
            lambda document: DocumentCabinet.objects.filter(documents=document).order_by('parent__label', 'label')
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_cabinet_add_document,
                permission_cabinet_remove_document
            )
        )

        ModelPermission.register(
            model=Cabinet, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_cabinet_delete, permission_cabinet_edit,
                permission_cabinet_view, permission_cabinet_add_document,
                permission_cabinet_remove_document
            )
        )
        ModelPermission.register_inheritance(
            model=Cabinet, related='get_root',
        )

        SourceColumn(
            source=Document, label=_('Cabinets'),
            func=lambda context: widget_document_cabinets(
                document=context['object'], user=context['request'].user
            ), order=1
        )

        document_page_search.add_model_field(
            field='document_version__document__cabinets__label',
            label=_('Cabinets')
        )
        document_search.add_model_field(
            field='cabinets__label', label=_('Cabinets')
        )

        menu_facet.bind_links(
            links=(link_document_cabinet_list,), sources=(Document,)
        )

        menu_cabinets.bind_links(
            links=(
                link_cabinet_list, link_cabinet_create
            )
        )

        menu_main.bind_links(links=(menu_cabinets,), position=98)

        menu_multi_item.bind_links(
            links=(
                link_cabinet_add_multiple_documents,
                link_multiple_document_cabinet_remove
            ), sources=(Document,)
        )
        menu_object.bind_links(
            links=(
                link_cabinet_view,
            ), sources=(DocumentCabinet, )
        )
        menu_object.bind_links(
            links=(
                link_cabinet_view, link_cabinet_edit,
                link_custom_acl_list, link_cabinet_delete
            ), sources=(Cabinet,)
        )
        menu_sidebar.bind_links(
            links=(link_cabinet_child_add,), sources=(Cabinet,)
        )
        menu_sidebar.bind_links(
            links=(link_cabinet_add_document, link_document_cabinet_remove),
            sources=(
                'cabinets:document_cabinet_list',
                'cabinets:cabinet_add_document',
                'cabinets:document_cabinet_remove'
            )
        )

        registry.register(Cabinet)
Exemplo n.º 27
0
    def ready(self):
        super(CheckoutsApp, self).ready()

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )
        DocumentVersion = apps.get_model(
            app_label='documents', model_name='DocumentVersion'
        )

        DocumentCheckout = self.get_model('DocumentCheckout')

        Document.add_to_class(
            'check_in',
            lambda document, user=None: DocumentCheckout.objects.check_in_document(document, user)
        )
        Document.add_to_class(
            'checkout_info',
            lambda document: DocumentCheckout.objects.document_checkout_info(
                document
            )
        )
        Document.add_to_class(
            'checkout_state',
            lambda document: DocumentCheckout.objects.document_checkout_state(
                document
            )
        )
        Document.add_to_class(
            'is_checked_out',
            lambda document: DocumentCheckout.objects.is_document_checked_out(
                document
            )
        )

        ModelEventType.register(
            model=Document, event_types=(
                event_document_auto_check_in, event_document_check_in,
                event_document_check_out, event_document_forceful_check_in
            )
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_document_checkout,
                permission_document_checkin,
                permission_document_checkin_override,
                permission_document_checkout_detail_view
            )
        )

        app.conf.CELERYBEAT_SCHEDULE.update(
            {
                'task_check_expired_check_outs': {
                    'task': 'checkouts.tasks.task_check_expired_check_outs',
                    'schedule': timedelta(
                        seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL
                    ),
                },
            }
        )

        app.conf.CELERY_QUEUES.append(
            Queue(
                'checkouts_periodic', Exchange('checkouts_periodic'),
                routing_key='checkouts_periodic', delivery_mode=1
            ),
        )

        app.conf.CELERY_ROUTES.update(
            {
                'checkouts.tasks.task_check_expired_check_outs': {
                    'queue': 'checkouts_periodic'
                },
            }
        )

        dashboard_main.add_widget(
            widget=DashboardWidgetTotalCheckouts, order=-1
        )

        menu_facet.bind_links(links=(link_checkout_info,), sources=(Document,))
        menu_main.bind_links(links=(link_checkout_list,), position=98)
        menu_sidebar.bind_links(
            links=(link_checkout_document, link_checkin_document),
            sources=(
                'checkouts:checkout_info', 'checkouts:checkout_document',
                'checkouts:checkin_document'
            )
        )

        pre_save.connect(
            check_new_version_creation,
            dispatch_uid='check_new_version_creation',
            sender=DocumentVersion
        )
Exemplo n.º 28
0
    def ready(self):
        super(SourcesApp, self).ready()

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

        MissingItem(
            label=_('Create a document source'),
            description=_(
                'Document sources are the way in which new documents are '
                'feed to Mayan EDMS, create at least a web form source to '
                'be able to upload documents from a browser.'
            ),
            condition=lambda: not Source.objects.exists(),
            view='sources:setup_source_list'
        )

        SourceColumn(
            source=StagingFile,
            label=_('Created'),
            func=lambda context: context['object'].get_date_time_created()
        )

        SourceColumn(
            source=StagingFile,
            label=_('Thumbnail'),
            func=lambda context: staging_file_thumbnail(
                context['object'],
                gallery_name='sources:staging_list',
                title=context['object'].filename, size='100'
            )
        )

        SourceColumn(
            source=SourceLog,
            label=_('Date time'),
            func=lambda context: context['object'].datetime
        )
        SourceColumn(
            source=SourceLog,
            label=_('Message'),
            func=lambda context: context['object'].message
        )

        app.conf.CELERY_QUEUES.extend(
            (
                Queue(
                    'sources', Exchange('sources'), routing_key='sources'
                ),
                Queue(
                    'sources_periodic', Exchange('sources_periodic'),
                    routing_key='sources_periodic', delivery_mode=1
                ),
            )
        )

        app.conf.CELERY_ROUTES.update(
            {
                'sources.tasks.task_check_interval_source': {
                    'queue': 'sources_periodic'
                },
                'sources.tasks.task_source_handle_upload': {
                    'queue': 'sources'
                },
                'sources.tasks.task_upload_document': {
                    'queue': 'sources'
                },
            }
        )

        menu_front_page.bind_links(links=(link_document_create_multiple,))
        menu_object.bind_links(
            links=(link_document_create_siblings,), sources=(Document,)
        )
        menu_object.bind_links(
            links=(
                link_setup_source_edit, link_setup_source_delete,
                link_transformation_list, link_setup_source_logs
            ), sources=(
                POP3Email, IMAPEmail, StagingFolderSource, WatchFolderSource,
                WebFormSource
            )
        )
        menu_object.bind_links(
            links=(link_staging_file_delete,), sources=(StagingFile,)
        )
        menu_secondary.bind_links(
            links=(
                link_setup_sources, link_setup_source_create_webform,
                link_setup_source_create_staging_folder,
                link_setup_source_create_pop3_email,
                link_setup_source_create_imap_email,
                link_setup_source_create_watch_folder
            ), sources=(
                POP3Email, IMAPEmail, StagingFolderSource, WatchFolderSource,
                WebFormSource, 'sources:setup_source_list',
                'sources:setup_source_create'
            )
        )
        menu_setup.bind_links(links=(link_setup_sources,))
        menu_sidebar.bind_links(
            links=(link_upload_version,),
            sources=(
                'documents:document_version_list', 'documents:upload_version',
                'documents:document_version_revert'
            )
        )

        post_upgrade.connect(
            initialize_periodic_tasks,
            dispatch_uid='initialize_periodic_tasks'
        )
        post_initial_setup.connect(
            create_default_document_source,
            dispatch_uid='create_default_document_source'
        )
        post_version_upload.connect(
            copy_transformations_to_version,
            dispatch_uid='copy_transformations_to_version'
        )
Exemplo n.º 29
0
    def ready(self):
        super(MetadataApp, self).ready()

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )
        DocumentPageResult = apps.get_model(
            app_label='documents', model_name='DocumentPageResult'
        )

        DocumentType = apps.get_model(
            app_label='documents', model_name='DocumentType'
        )

        DocumentMetadata = self.get_model('DocumentMetadata')
        DocumentTypeMetadataType = self.get_model('DocumentTypeMetadataType')
        MetadataType = self.get_model('MetadataType')

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

        Document.add_to_class(
            'metadata_value_of', DocumentMetadataHelper.constructor
        )

        Filter(
            label=_('Documents missing required metadata'),
            slug='documents-no-required-metadata',
            filter_kwargs=[
                {
                    'document_type__metadata__required': True,
                },
                {
                    'metadata__value__isnull': True
                },
                {
                    'is_stub': False
                }
            ], model=Document, object_permission=permission_document_view,
            hide_links=True
        )

        Filter(
            label=_('Documents missing optional metadata'),
            slug='documents-no-optional-metadata',
            filter_kwargs=[
                {
                    'document_type__metadata__required': False,
                },
                {
                    'metadata__value__isnull': True
                },
                {
                    'is_stub': False
                }
            ], model=Document, object_permission=permission_document_view,
            hide_links=True
        )

        ModelAttribute(
            Document, 'metadata', type_name='related',
            description=_(
                'Queryset containing a MetadataType instance reference and a '
                'value for that metadata type'
            )
        )
        ModelAttribute(
            Document, 'metadata__metadata_type__name',
            label=_('Metadata type name'), type_name='query'
        )
        ModelAttribute(
            Document, 'metadata__value', label=_('Metadata type value'),
            type_name='query'
        )
        ModelAttribute(
            Document, 'metadata_value_of', label=_('Value of a metadata'),
            description=_(
                'Return the value of a specific document metadata'
            ),
            type_name=['property', 'indexing']
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_metadata_document_add,
                permission_metadata_document_edit,
                permission_metadata_document_remove,
                permission_metadata_document_view,
            )
        )

        SourceColumn(
            source=Document, label=_('Metadata'),
            func=lambda context: get_metadata_string(context['object'])
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Metadata'),
            func=lambda context: get_metadata_string(
                context['object'].document
            )
        )

        SourceColumn(
            source=DocumentMetadata, label=_('Value'),
            attribute='value'
        )
        SourceColumn(
            source=DocumentMetadata, label=_('Required'),
            func=lambda context: two_state_template(
                context['object'].is_required
            )
        )

        app.conf.CELERY_QUEUES.append(
            Queue('metadata', Exchange('metadata'), routing_key='metadata'),
        )

        app.conf.CELERY_ROUTES.update(
            {
                'metadata.tasks.task_remove_metadata_type': {
                    'queue': 'metadata'
                },
                'metadata.tasks.task_add_required_metadata_type': {
                    'queue': 'metadata'
                },
            }
        )

        document_search.add_model_field(
            field='metadata__metadata_type__name', label=_('Metadata type')
        )
        document_search.add_model_field(
            field='metadata__value', label=_('Metadata value')
        )

        document_page_search.add_model_field(
            field='document_version__document__metadata__metadata_type__name',
            label=_('Metadata type')
        )
        document_page_search.add_model_field(
            field='document_version__document__metadata__value',
            label=_('Metadata value')
        )

        menu_facet.bind_links(links=(link_metadata_view,), sources=(Document,))
        menu_multi_item.bind_links(
            links=(
                link_metadata_multiple_add, link_metadata_multiple_edit,
                link_metadata_multiple_remove
            ), sources=(Document,)
        )
        menu_object.bind_links(
            links=(
                link_setup_document_type_metadata_types,
            ), sources=(DocumentType,)
        )
        menu_object.bind_links(
            links=(
                link_setup_metadata_type_edit,
                link_setup_metadata_type_document_types,
                link_setup_metadata_type_delete
            ), sources=(MetadataType,)
        )
        menu_secondary.bind_links(
            links=(
                link_setup_metadata_type_list,
                link_setup_metadata_type_create
            ), sources=(
                MetadataType, 'metadata:setup_metadata_type_list',
                'metadata:setup_metadata_type_create'
            )
        )
        menu_setup.bind_links(links=(link_setup_metadata_type_list,))
        menu_sidebar.bind_links(
            links=(
                link_metadata_add, link_metadata_edit, link_metadata_remove
            ), sources=(
                'metadata:metadata_add', 'metadata:metadata_edit',
                'metadata:metadata_remove', 'metadata:metadata_view'
            )
        )

        post_delete.connect(
            post_document_type_metadata_type_delete,
            dispatch_uid='metadata_post_document_type_metadata_type_delete',
            sender=DocumentTypeMetadataType
        )
        post_document_type_change.connect(
            post_document_type_change_metadata,
            dispatch_uid='metadata_post_document_type_change_metadata',
            sender=Document
        )
        post_save.connect(
            post_document_type_metadata_type_add,
            dispatch_uid='metadata_post_document_type_metadata_type_add',
            sender=DocumentTypeMetadataType
        )

        # Index updating

        post_delete.connect(
            handler_index_document,
            dispatch_uid='metadata_handler_index_document_delete',
            sender=DocumentMetadata
        )
        post_save.connect(
            handler_index_document,
            dispatch_uid='metadata_handler_index_document_save',
            sender=DocumentMetadata
        )
Exemplo n.º 30
0
    def ready(self):
        super(FoldersApp, self).ready()

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

        Document.add_to_class(
            'document_folders',
            lambda document: DocumentFolder.objects.filter(documents=document)
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_folder_add_document,
                permission_folder_remove_document
            )
        )

        ModelPermission.register(
            model=Folder, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_folder_delete, permission_folder_edit,
                permission_folder_view
            )
        )

        SourceColumn(
            source=Folder, label=_('Created'), attribute='datetime_created'
        )
        SourceColumn(source=Folder, label=_('User'), attribute='user')
        SourceColumn(
            source=Folder, label=_('Documents'),
            func=lambda context: context['object'].get_document_count(
                user=context['request'].user
            )
        )

        menu_facet.bind_links(
            links=(link_document_folder_list,), sources=(Document,)
        )
        menu_main.bind_links(links=(link_folder_list,))
        menu_multi_item.bind_links(
            links=(link_folder_add_multiple_documents,), sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(link_folder_document_multiple_remove,),
            sources=('folders:folder_view',)
        )
        menu_object.bind_links(
            links=(
                link_folder_view,
            ), sources=(DocumentFolder, )
        )
        menu_object.bind_links(
            links=(
                link_folder_view, link_folder_edit, link_acl_list,
                link_folder_delete
            ), sources=(Folder,)
        )
        menu_secondary.bind_links(
            links=(link_folder_list, link_folder_create),
            sources=(Folder, 'folders:folder_list', 'folders:folder_create')
        )
        menu_sidebar.bind_links(
            links=(link_folder_add_document,),
            sources=(
                'folders:document_folder_list', 'folders:folder_add_document'
            )
        )
Exemplo n.º 31
0
    def ready(self):
        super(DocumentSignaturesApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentVersion = apps.get_model(app_label='documents',
                                         model_name='DocumentVersion')

        Key = apps.get_model(app_label='django_gpg', model_name='Key')

        EmbeddedSignature = self.get_model('EmbeddedSignature')

        SignatureBaseModel = self.get_model('SignatureBaseModel')

        DocumentVersion.register_post_save_hook(
            order=1, func=EmbeddedSignature.objects.create)
        DocumentVersion.register_pre_open_hook(
            order=1, func=EmbeddedSignature.objects.open_signed)

        ModelPermission.register(
            model=Document,
            permissions=(
                permission_document_version_sign_detached,
                permission_document_version_sign_embedded,
                permission_document_version_signature_delete,
                permission_document_version_signature_download,
                permission_document_version_signature_view,
                permission_document_version_signature_upload,
            ))

        SourceColumn(source=SignatureBaseModel,
                     label=_('Date'),
                     attribute='date')
        SourceColumn(source=SignatureBaseModel,
                     label=_('Key ID'),
                     attribute='get_key_id')
        SourceColumn(
            source=SignatureBaseModel,
            label=_('Signature ID'),
            func=lambda context: context['object'].signature_id or _('None'))
        SourceColumn(
            source=SignatureBaseModel,
            label=_('Type'),
            func=lambda context: SignatureBaseModel.objects.get_subclass(
                pk=context['object'].pk).get_signature_type_display())

        app.conf.CELERY_QUEUES.append(
            Queue('signatures',
                  Exchange('signatures'),
                  routing_key='signatures'), )

        app.conf.CELERY_ROUTES.update({
            'document_signatures.tasks.task_verify_key_signatures': {
                'queue': 'signatures'
            },
            'document_signatures.tasks.task_unverify_key_signatures': {
                'queue': 'signatures'
            },
            'document_signatures.tasks.task_verify_document_version': {
                'queue': 'signatures'
            },
            'document_signatures.tasks.task_verify_missing_embedded_signature':
            {
                'queue': 'tools'
            },
        })

        menu_facet.bind_links(links=(link_document_signature_list, ),
                              sources=(Document, ))
        menu_object.bind_links(
            links=(link_document_version_signature_list,
                   link_document_version_signature_detached_create,
                   link_document_version_signature_embedded_create),
            sources=(DocumentVersion, ))
        menu_object.bind_links(links=(
            link_document_version_signature_details,
            link_document_version_signature_download,
            link_document_version_signature_delete,
        ),
                               sources=(SignatureBaseModel, ))
        menu_sidebar.bind_links(
            links=(link_document_version_signature_upload, ),
            sources=(DocumentVersion, ))
        menu_tools.bind_links(
            links=(link_all_document_version_signature_verify, ))

        post_delete.connect(unverify_key_signatures,
                            dispatch_uid='unverify_key_signatures',
                            sender=Key)
        post_upgrade.connect(
            verify_missing_embedded_signature,
            dispatch_uid='verify_missing_embedded_signature',
        )
        post_save.connect(verify_key_signatures,
                          dispatch_uid='verify_key_signatures',
                          sender=Key)
Exemplo n.º 32
0
    def ready(self):
        super(CabinetsApp, self).ready()
        from actstream import registry

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentCabinet = self.get_model('DocumentCabinet')
        Cabinet = self.get_model('Cabinet')

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

        # Add explicit order_by as DocumentCabinet ordering Meta option has no
        # effect.
        Document.add_to_class(
            'document_cabinets', lambda document: DocumentCabinet.objects.
            filter(documents=document).order_by('parent__label', 'label'))

        ModelPermission.register(
            model=Document,
            permissions=(permission_cabinet_add_document,
                         permission_cabinet_remove_document))

        ModelPermission.register(
            model=Cabinet,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_cabinet_delete, permission_cabinet_edit,
                         permission_cabinet_view,
                         permission_cabinet_add_document,
                         permission_cabinet_remove_document))
        ModelPermission.register_inheritance(
            model=Cabinet,
            related='get_root',
        )

        SourceColumn(
            source=Document,
            label=_('Cabinets'),
            func=lambda context: widget_document_cabinets(
                document=context['object'], user=context['request'].user),
            order=1)

        document_page_search.add_model_field(
            field='document_version__document__cabinets__label',
            label=_('Cabinets'))
        document_search.add_model_field(field='cabinets__label',
                                        label=_('Cabinets'))

        menu_facet.bind_links(links=(link_document_cabinet_list, ),
                              sources=(Document, ))

        menu_cabinets.bind_links(links=(link_cabinet_list,
                                        link_cabinet_create))

        menu_main.bind_links(links=(menu_cabinets, ), position=98)

        menu_multi_item.bind_links(
            links=(link_cabinet_add_multiple_documents,
                   link_multiple_document_cabinet_remove),
            sources=(Document, ))
        menu_object.bind_links(links=(link_cabinet_view, ),
                               sources=(DocumentCabinet, ))
        menu_object.bind_links(links=(link_cabinet_view, link_cabinet_edit,
                                      link_custom_acl_list,
                                      link_cabinet_delete),
                               sources=(Cabinet, ))
        menu_sidebar.bind_links(links=(link_cabinet_child_add, ),
                                sources=(Cabinet, ))
        menu_sidebar.bind_links(links=(link_cabinet_add_document,
                                       link_document_cabinet_remove),
                                sources=('cabinets:document_cabinet_list',
                                         'cabinets:cabinet_add_document',
                                         'cabinets:document_cabinet_remove'))

        registry.register(Cabinet)
Exemplo n.º 33
0
    def ready(self):
        super(TagsApp, self).ready()
        from actstream import registry

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        DocumentPageResult = apps.get_model(
            app_label='documents', model_name='DocumentPageResult'
        )

        DocumentTag = self.get_model('DocumentTag')
        Tag = self.get_model('Tag')

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

        Document.add_to_class(
            'attached_tags',
            lambda document: DocumentTag.objects.filter(documents=document)
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_tag_attach, permission_tag_remove,
                permission_tag_view
            )
        )

        ModelPermission.register(
            model=Tag, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_tag_attach, permission_tag_delete,
                permission_tag_edit, permission_tag_remove,
                permission_tag_view
            )
        )

        SourceColumn(
            source=DocumentTag, label=_('Preview'),
            func=lambda context: widget_single_tag(context['object'])
        )

        SourceColumn(
            source=Document, label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'], user=context['request'].user
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'].document,
                user=context['request'].user
            )
        )

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

        document_page_search.add_model_field(
            field='document_version__document__tags__label', label=_('Tags')
        )
        document_search.add_model_field(field='tags__label', label=_('Tags'))

        menu_facet.bind_links(
            links=(link_tag_document_list,), sources=(Document,)
        )

        menu_tags.bind_links(
            links=(
                link_tag_list, link_tag_create
            )
        )

        menu_main.bind_links(links=(menu_tags,), position=98)

        menu_multi_item.bind_links(
            links=(
                link_multiple_documents_attach_tag,
                link_multiple_documents_tag_remove
            ),
            sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(link_tag_multiple_delete,), sources=(Tag,)
        )
        menu_object.bind_links(
            links=(
                link_tag_tagged_item_list, link_tag_edit, link_acl_list,
                link_tag_delete
            ),
            sources=(Tag,)
        )
        menu_sidebar.bind_links(
            links=(link_tag_attach, link_single_document_multiple_tag_remove),
            sources=(
                'tags:tag_attach', 'tags:document_tags',
                'tags:single_document_multiple_tag_remove'
            )
        )
        registry.register(Tag)
Exemplo n.º 34
0
    def ready(self):
        super(MetadataApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')
        DocumentPageResult = apps.get_model(app_label='documents',
                                            model_name='DocumentPageResult')

        DocumentType = apps.get_model(app_label='documents',
                                      model_name='DocumentType')

        DocumentMetadata = self.get_model('DocumentMetadata')
        DocumentTypeMetadataType = self.get_model('DocumentTypeMetadataType')
        MetadataType = self.get_model('MetadataType')

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

        Document.add_to_class('metadata_value_of',
                              DocumentMetadataHelper.constructor)

        Filter(label=_('Documents missing required metadata'),
               slug='documents-no-required-metadata',
               filter_kwargs=[{
                   'document_type__metadata__required': True,
               }, {
                   'metadata__value__isnull': True
               }, {
                   'is_stub': False
               }],
               model=Document,
               object_permission=permission_document_view,
               hide_links=True)

        Filter(label=_('Documents missing optional metadata'),
               slug='documents-no-optional-metadata',
               filter_kwargs=[{
                   'document_type__metadata__required': False,
               }, {
                   'metadata__value__isnull': True
               }, {
                   'is_stub': False
               }],
               model=Document,
               object_permission=permission_document_view,
               hide_links=True)

        ModelAttribute(
            Document,
            'metadata',
            type_name='related',
            description=_(
                'Queryset containing a MetadataType instance reference and a '
                'value for that metadata type'))
        ModelAttribute(Document,
                       'metadata__metadata_type__name',
                       label=_('Metadata type name'),
                       type_name='query')
        ModelAttribute(Document,
                       'metadata__value',
                       label=_('Metadata type value'),
                       type_name='query')
        ModelAttribute(
            Document,
            'metadata_value_of',
            label=_('Value of a metadata'),
            description=_('Return the value of a specific document metadata'),
            type_name=['property', 'indexing'])

        ModelPermission.register(model=Document,
                                 permissions=(
                                     permission_metadata_document_add,
                                     permission_metadata_document_edit,
                                     permission_metadata_document_remove,
                                     permission_metadata_document_view,
                                 ))

        SourceColumn(
            source=Document,
            label=_('Metadata'),
            func=lambda context: get_metadata_string(context['object']))

        SourceColumn(source=DocumentPageResult,
                     label=_('Metadata'),
                     func=lambda context: get_metadata_string(context['object']
                                                              .document))

        SourceColumn(source=DocumentMetadata,
                     label=_('Value'),
                     attribute='value')
        SourceColumn(source=DocumentMetadata,
                     label=_('Required'),
                     func=lambda context: two_state_template(context['object'].
                                                             is_required))

        app.conf.CELERY_QUEUES.append(
            Queue('metadata', Exchange('metadata'), routing_key='metadata'), )

        app.conf.CELERY_ROUTES.update({
            'metadata.tasks.task_remove_metadata_type': {
                'queue': 'metadata'
            },
            'metadata.tasks.task_add_required_metadata_type': {
                'queue': 'metadata'
            },
        })

        document_search.add_model_field(field='metadata__metadata_type__name',
                                        label=_('Metadata type'))
        document_search.add_model_field(field='metadata__value',
                                        label=_('Metadata value'))

        document_page_search.add_model_field(
            field='document_version__document__metadata__metadata_type__name',
            label=_('Metadata type'))
        document_page_search.add_model_field(
            field='document_version__document__metadata__value',
            label=_('Metadata value'))

        menu_facet.bind_links(links=(link_metadata_view, ),
                              sources=(Document, ))
        menu_multi_item.bind_links(links=(link_metadata_multiple_add,
                                          link_metadata_multiple_edit,
                                          link_metadata_multiple_remove),
                                   sources=(Document, ))
        menu_object.bind_links(
            links=(link_setup_document_type_metadata,
                   link_setup_document_type_metadata_required),
            sources=(DocumentType, ))
        menu_object.bind_links(links=(link_setup_metadata_type_edit,
                                      link_setup_metadata_type_delete),
                               sources=(MetadataType, ))
        menu_secondary.bind_links(
            links=(link_setup_metadata_type_list,
                   link_setup_metadata_type_create),
            sources=(MetadataType, 'metadata:setup_metadata_type_list',
                     'metadata:setup_metadata_type_create'))
        menu_setup.bind_links(links=(link_setup_metadata_type_list, ))
        menu_sidebar.bind_links(
            links=(link_metadata_add, link_metadata_edit,
                   link_metadata_remove),
            sources=('metadata:metadata_add', 'metadata:metadata_edit',
                     'metadata:metadata_remove', 'metadata:metadata_view'))

        post_delete.connect(
            post_document_type_metadata_type_delete,
            dispatch_uid='post_document_type_metadata_type_delete',
            sender=DocumentTypeMetadataType)
        post_document_type_change.connect(
            post_post_document_type_change_metadata,
            dispatch_uid='post_post_document_type_change_metadata',
            sender=Document)
        post_save.connect(post_document_type_metadata_type_add,
                          dispatch_uid='post_document_type_metadata_type_add',
                          sender=DocumentTypeMetadataType)
Exemplo n.º 35
0
    def ready(self):
        super(DocumentStatesApp, self).ready()

        Action = apps.get_model(
            app_label='actstream', model_name='Action'
        )
        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )
        ErrorLogEntry = apps.get_model(
            app_label='common', model_name='ErrorLogEntry'
        )

        Workflow = self.get_model('Workflow')
        WorkflowInstance = self.get_model('WorkflowInstance')
        WorkflowInstanceLogEntry = self.get_model('WorkflowInstanceLogEntry')
        WorkflowRuntimeProxy = self.get_model('WorkflowRuntimeProxy')
        WorkflowState = self.get_model('WorkflowState')
        WorkflowStateAction = self.get_model('WorkflowStateAction')
        WorkflowStateRuntimeProxy = self.get_model('WorkflowStateRuntimeProxy')
        WorkflowTransition = self.get_model('WorkflowTransition')
        WorkflowTransitionTriggerEvent = self.get_model(
            'WorkflowTransitionTriggerEvent'
        )

        Document.add_to_class(
            'workflow', DocumentStateHelper.constructor
        )

        ErrorLogEntry.objects.register(model=WorkflowStateAction)

        WorkflowAction.initialize()

        ModelAttribute(
            model=Document,
            name='workflow.< workflow internal name >.get_current_state',
            label=_('Current state of a workflow'), description=_(
                'Return the current state of the selected workflow'
            )
        )
        ModelAttribute(
            model=Document,
            name='workflow.< workflow internal name >.get_current_state.completion',
            label=_('Current state of a workflow'), description=_(
                'Return the completion value of the current state of the '
                'selected workflow'
            )
        )

        ModelPermission.register(
            model=Document, permissions=(permission_workflow_view,)
        )
        ModelPermission.register(
            model=Workflow, permissions=(
                permission_error_log_view, permission_workflow_delete,
                permission_workflow_edit, permission_workflow_transition,
                permission_workflow_view,
            )
        )

        ModelPermission.register_inheritance(
            model=WorkflowInstance, related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowInstanceLogEntry,
            related='workflow_instance__workflow',
        )
        ModelPermission.register(
            model=WorkflowTransition,
            permissions=(permission_workflow_transition,)
        )

        ModelPermission.register_inheritance(
            model=WorkflowState, related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowStateAction, related='state__workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowTransition, related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowTransitionTriggerEvent,
            related='transition__workflow',
        )

        SourceColumn(
            source=Workflow, label=_('Label'), attribute='label'
        )
        SourceColumn(
            source=Workflow, label=_('Internal name'),
            attribute='internal_name'
        )
        SourceColumn(
            source=Workflow, label=_('Initial state'),
            func=lambda context: context['object'].get_initial_state() or _('None')
        )

        SourceColumn(
            source=WorkflowInstance, label=_('Current state'),
            attribute='get_current_state'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('User'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'user', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Last transition'),
            attribute='get_last_transition'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Date and time'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'datetime', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Completion'),
            func=lambda context: getattr(
                context['object'].get_current_state(), 'completion', _('None')
            )
        )

        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Date and time'),
            attribute='datetime'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('User'), attribute='user'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Transition'),
            attribute='transition'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Comment'),
            attribute='comment'
        )

        SourceColumn(
            source=WorkflowState, label=_('Is initial state?'),
            func=lambda context: TwoStateWidget(
                state=context['object'].initial
            ).render()
        )
        SourceColumn(
            source=WorkflowState, label=_('Completion'), attribute='completion'
        )

        SourceColumn(
            source=WorkflowStateAction, label=_('Label'), attribute='label'
        )
        SourceColumn(
            source=WorkflowStateAction, label=_('Enabled?'),
            func=lambda context: TwoStateWidget(
                state=context['object'].enabled
            ).render()
        )
        SourceColumn(
            source=WorkflowStateAction, label=_('When?'),
            attribute='get_when_display'
        )
        SourceColumn(
            source=WorkflowStateAction, label=_('Action type'),
            attribute='get_class_label'
        )

        SourceColumn(
            source=WorkflowTransition, label=_('Origin state'),
            attribute='origin_state'
        )
        SourceColumn(
            source=WorkflowTransition, label=_('Destination state'),
            attribute='destination_state'
        )
        SourceColumn(
            source=WorkflowTransition, label=_('Triggers'),
            func=lambda context: widget_transition_events(
                transition=context['object']
            )
        )

        app.conf.CELERY_QUEUES.extend(
            (
                Queue(
                    'document_states', Exchange('document_states'),
                    routing_key='document_states'
                ),
            )
        )

        app.conf.CELERY_ROUTES.update(
            {
                'document_states.tasks.task_launch_all_workflows': {
                    'queue': 'document_states'
                },
            }
        )

        menu_facet.bind_links(
            links=(link_document_workflow_instance_list,), sources=(Document,)
        )
        menu_main.bind_links(links=(link_workflow_list,), position=10)
        menu_object.bind_links(
            links=(
                link_setup_workflow_states, link_setup_workflow_transitions,
                link_setup_workflow_document_types, link_setup_workflow_edit,
                link_acl_list, link_workflow_preview,
                link_setup_workflow_delete
            ), sources=(Workflow,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_state_edit,
                link_setup_workflow_state_action_list,
                link_setup_workflow_state_delete
            ), sources=(WorkflowState,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_transition_edit,
                link_workflow_instance_transition_events, link_acl_list,
                link_setup_workflow_transition_delete
            ), sources=(WorkflowTransition,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_instance_detail,
                link_workflow_instance_transition
            ), sources=(WorkflowInstance,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_document_list, link_workflow_state_list,
            ), sources=(WorkflowRuntimeProxy,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_state_document_list,
            ), sources=(WorkflowStateRuntimeProxy,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_state_action_edit,
                link_object_error_list,
                link_setup_workflow_state_action_delete,
            ), sources=(WorkflowStateAction,)
        )

        menu_secondary.bind_links(
            links=(link_setup_workflow_list, link_setup_workflow_create),
            sources=(
                Workflow, 'document_states:setup_workflow_create',
                'document_states:setup_workflow_list'
            )
        )
        menu_secondary.bind_links(
            links=(link_workflow_list,),
            sources=(
                WorkflowRuntimeProxy,
            )
        )
        menu_secondary.bind_links(
            links=(link_setup_workflow_state_action_selection,),
            sources=(
                WorkflowState,
            )
        )
        menu_setup.bind_links(links=(link_setup_workflow_list,))
        menu_sidebar.bind_links(
            links=(
                link_setup_workflow_state_create,
                link_setup_workflow_transition_create
            ), sources=(Workflow,)
        )
        menu_tools.bind_links(links=(link_tool_launch_all_workflows,))

        post_save.connect(
            launch_workflow, dispatch_uid='launch_workflow', sender=Document
        )

        # Index updating

        post_save.connect(
            handler_index_document,
            dispatch_uid='handler_index_document_save',
            sender=WorkflowInstanceLogEntry
        )
        post_save.connect(
            handler_trigger_transition,
            dispatch_uid='document_states_handler_trigger_transition',
            sender=Action
        )
Exemplo n.º 36
0
    def ready(self):
        super(TagsApp, self).ready()
        from actstream import registry

        from .wizard_steps import WizardStepTags  # NOQA

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentPageResult = apps.get_model(app_label='documents',
                                            model_name='DocumentPageResult')

        DocumentTag = self.get_model('DocumentTag')
        Tag = self.get_model('Tag')

        Document.add_to_class(
            'attached_tags',
            lambda document: DocumentTag.objects.filter(documents=document))

        ModelPermission.register(model=Document,
                                 permissions=(permission_tag_attach,
                                              permission_tag_remove,
                                              permission_tag_view))

        ModelPermission.register(
            model=Tag,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_tag_attach, permission_tag_delete,
                         permission_tag_edit, permission_tag_remove,
                         permission_tag_view))

        SourceColumn(source=DocumentTag, attribute='label')
        SourceColumn(source=DocumentTag, attribute='get_preview_widget')

        SourceColumn(
            source=Document,
            label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'], user=context['request'].user))

        SourceColumn(source=DocumentPageResult,
                     label=_('Tags'),
                     func=lambda context: widget_document_tags(
                         document=context['object'].document,
                         user=context['request'].user))

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

        document_page_search.add_model_field(
            field='document_version__document__tags__label', label=_('Tags'))
        document_search.add_model_field(field='tags__label', label=_('Tags'))

        menu_facet.bind_links(links=(link_tag_document_list, ),
                              sources=(Document, ))

        menu_tags.bind_links(links=(link_tag_list, link_tag_create))

        menu_main.bind_links(links=(menu_tags, ), position=98)

        menu_multi_item.bind_links(links=(link_multiple_documents_attach_tag,
                                          link_multiple_documents_tag_remove),
                                   sources=(Document, ))
        menu_multi_item.bind_links(links=(link_tag_multiple_delete, ),
                                   sources=(Tag, ))
        menu_object.bind_links(links=(link_tag_tagged_item_list, link_tag_edit,
                                      link_acl_list, link_tag_delete),
                               sources=(Tag, ))
        menu_sidebar.bind_links(
            links=(link_tag_attach, link_single_document_multiple_tag_remove),
            sources=('tags:tag_attach', 'tags:document_tags',
                     'tags:single_document_multiple_tag_remove'))
        registry.register(Tag)

        # Index update

        m2m_changed.connect(handler_index_document,
                            dispatch_uid='tags_handler_index_document',
                            sender=Tag.documents.through)

        pre_delete.connect(handler_tag_pre_delete,
                           dispatch_uid='tags_handler_tag_pre_delete',
                           sender=Tag)
Exemplo n.º 37
0
    def ready(self):
        super(DjangoGPGApp, self).ready()

        Package(label='python-gnupg',
                license_text='''
Copyright (c) 2008-2014 by Vinay Sajip.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * The name(s) of the copyright holder(s) may not be used to endorse or
      promote products derived from this software without specific prior
      written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        ''')

        SourceColumn(source=Key, label=_('ID'), attribute='key_id')
        SourceColumn(source=Key,
                     label=_('Owner'),
                     func=lambda context: ', '.join(context['object'].uids))

        SourceColumn(source=KeyStub,
                     label=_('ID'),
                     func=lambda context: '...{0}'.format(context['object'].
                                                          key_id[-16:]))
        SourceColumn(source=KeyStub, label=_('Type'), attribute='key_type')
        SourceColumn(source=KeyStub,
                     label=_('Creation date'),
                     func=lambda context: datetime.fromtimestamp(
                         int(context['object'].date)))
        SourceColumn(source=KeyStub,
                     label=_('Expiration date'),
                     func=lambda context: datetime.fromtimestamp(
                         int(context['object'].expires))
                     if context['object'].expires else _('No expiration'))
        SourceColumn(source=KeyStub, label=_('Length'), attribute='length')
        SourceColumn(source=KeyStub,
                     label=_('Identities'),
                     func=lambda context: ', '.join(context['object'].uids))

        menu_object.bind_links(links=(link_key_delete, ), sources=(Key, ))
        menu_object.bind_links(links=(link_key_receive, ), sources=(KeyStub, ))
        menu_setup.bind_links(links=(link_key_setup, ))
        menu_sidebar.bind_links(links=(link_public_keys, link_key_query),
                                sources=(
                                    'django_gpg:key_delete',
                                    'django_gpg:key_public_list',
                                    'django_gpg:key_query',
                                    'django_gpg:key_query_results',
                                ))
Exemplo n.º 38
0
    def ready(self):
        super(CheckoutsApp, self).ready()

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

        Document.add_to_class(
            'check_in',
            lambda document, user=None: DocumentCheckout.objects.check_in_document(document, user)
        )
        Document.add_to_class(
            'checkout_info',
            lambda document: DocumentCheckout.objects.document_checkout_info(
                document
            )
        )
        Document.add_to_class(
            'checkout_state',
            lambda document: DocumentCheckout.objects.document_checkout_state(
                document
            )
        )
        Document.add_to_class(
            'is_checked_out',
            lambda document: DocumentCheckout.objects.is_document_checked_out(
                document
            )
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_document_checkout,
                permission_document_checkin,
                permission_document_checkin_override,
            )
        )

        app.conf.CELERYBEAT_SCHEDULE.update(
            {
                'task_check_expired_check_outs': {
                    'task': 'checkouts.tasks.task_check_expired_check_outs',
                    'schedule': timedelta(
                        seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL
                    ),
                },
            }
        )

        app.conf.CELERY_QUEUES.append(
            Queue(
                'checkouts_periodic', Exchange('checkouts_periodic'),
                routing_key='checkouts_periodic', delivery_mode=1
            ),
        )

        app.conf.CELERY_ROUTES.update(
            {
                'checkouts.tasks.task_check_expired_check_outs': {
                    'queue': 'checkouts_periodic'
                },
            }
        )

        menu_facet.bind_links(links=(link_checkout_info,), sources=(Document,))
        menu_main.bind_links(links=(link_checkout_list,))
        menu_sidebar.bind_links(
            links=(link_checkout_document, link_checkin_document),
            sources=(
                'checkouts:checkout_info', 'checkouts:checkout_document',
                'checkouts:checkin_document'
            )
        )
Exemplo n.º 39
0
    def ready(self):
        super(MetadataApp, self).ready()

        from .wizard_steps import WizardStepMetadata  # NOQA

        Document = apps.get_model(app_label='documents', model_name='Document')
        DocumentPageResult = apps.get_model(app_label='documents',
                                            model_name='DocumentPageResult')

        DocumentType = apps.get_model(app_label='documents',
                                      model_name='DocumentType')

        DocumentMetadata = self.get_model('DocumentMetadata')
        DocumentTypeMetadataType = self.get_model('DocumentTypeMetadataType')
        MetadataType = self.get_model('MetadataType')

        Document.add_to_class('metadata_value_of',
                              DocumentMetadataHelper.constructor)

        ModelAttribute(
            Document,
            'metadata',
            type_name='related',
            description=_(
                'Queryset containing a MetadataType instance reference and a '
                'value for that metadata type'))
        ModelAttribute(Document,
                       'metadata__metadata_type__name',
                       label=_('Metadata type name'),
                       type_name='query')
        ModelAttribute(Document,
                       'metadata__value',
                       label=_('Metadata type value'),
                       type_name='query')
        ModelAttribute(
            Document,
            'metadata_value_of',
            label=_('Value of a metadata'),
            description=_('Return the value of a specific document metadata'),
            type_name=['property', 'indexing'])

        ModelPermission.register(model=Document,
                                 permissions=(
                                     permission_metadata_document_add,
                                     permission_metadata_document_edit,
                                     permission_metadata_document_remove,
                                     permission_metadata_document_view,
                                 ))
        ModelPermission.register(model=MetadataType,
                                 permissions=(permission_metadata_type_delete,
                                              permission_metadata_type_edit,
                                              permission_metadata_type_view))

        SourceColumn(
            source=Document,
            label=_('Metadata'),
            func=lambda context: get_metadata_string(context['object']))

        SourceColumn(source=DocumentPageResult,
                     label=_('Metadata'),
                     func=lambda context: get_metadata_string(context['object']
                                                              .document))

        SourceColumn(source=DocumentMetadata,
                     label=_('Value'),
                     attribute='value')
        SourceColumn(source=DocumentMetadata,
                     label=_('Required'),
                     func=lambda context: two_state_template(context['object'].
                                                             is_required))

        app.conf.CELERY_QUEUES.append(
            Queue('metadata', Exchange('metadata'), routing_key='metadata'), )

        app.conf.CELERY_ROUTES.update({
            'metadata.tasks.task_remove_metadata_type': {
                'queue': 'metadata'
            },
            'metadata.tasks.task_add_required_metadata_type': {
                'queue': 'metadata'
            },
        })

        document_search.add_model_field(field='metadata__metadata_type__name',
                                        label=_('Metadata type'))
        document_search.add_model_field(field='metadata__value',
                                        label=_('Metadata value'))

        document_page_search.add_model_field(
            field='document_version__document__metadata__metadata_type__name',
            label=_('Metadata type'))
        document_page_search.add_model_field(
            field='document_version__document__metadata__value',
            label=_('Metadata value'))

        menu_facet.bind_links(links=(link_metadata_view, ),
                              sources=(Document, ))
        menu_multi_item.bind_links(links=(link_metadata_multiple_add,
                                          link_metadata_multiple_edit,
                                          link_metadata_multiple_remove),
                                   sources=(Document, ))
        menu_object.bind_links(
            links=(link_setup_document_type_metadata_types, ),
            sources=(DocumentType, ))
        menu_object.bind_links(links=(link_setup_metadata_type_edit,
                                      link_setup_metadata_type_document_types,
                                      link_setup_metadata_type_delete),
                               sources=(MetadataType, ))
        menu_secondary.bind_links(
            links=(link_setup_metadata_type_list,
                   link_setup_metadata_type_create),
            sources=(MetadataType, 'metadata:setup_metadata_type_list',
                     'metadata:setup_metadata_type_create'))
        menu_setup.bind_links(links=(link_setup_metadata_type_list, ))
        menu_sidebar.bind_links(
            links=(link_metadata_add, link_metadata_edit,
                   link_metadata_remove),
            sources=('metadata:metadata_add', 'metadata:metadata_edit',
                     'metadata:metadata_remove', 'metadata:metadata_view'))

        post_delete.connect(
            post_document_type_metadata_type_delete,
            dispatch_uid='metadata_post_document_type_metadata_type_delete',
            sender=DocumentTypeMetadataType)
        post_document_type_change.connect(
            post_document_type_change_metadata,
            dispatch_uid='metadata_post_document_type_change_metadata',
            sender=Document)
        post_save.connect(
            post_document_type_metadata_type_add,
            dispatch_uid='metadata_post_document_type_metadata_type_add',
            sender=DocumentTypeMetadataType)

        # Index updating

        post_delete.connect(
            handler_index_document,
            dispatch_uid='metadata_handler_index_document_delete',
            sender=DocumentMetadata)
        post_save.connect(handler_index_document,
                          dispatch_uid='metadata_handler_index_document_save',
                          sender=DocumentMetadata)
Exemplo n.º 40
0
    def ready(self):
        super(TagsApp, self).ready()
        from actstream import registry

        from .wizard_steps import WizardStepTags  # NOQA

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        DocumentPageResult = apps.get_model(
            app_label='documents', model_name='DocumentPageResult'
        )

        DocumentTag = self.get_model('DocumentTag')
        Tag = self.get_model('Tag')

        Document.add_to_class(
            'attached_tags',
            lambda document: DocumentTag.objects.filter(documents=document)
        )

        ModelEventType.register(
            model=Tag, event_types=(
                event_tag_attach, event_tag_created, event_tag_edited,
                event_tag_remove
            )
        )

        ModelField(
            Document, name='tags__label'
        )
        ModelField(
            Document, name='tags__color'
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_tag_attach, permission_tag_remove,
                permission_tag_view
            )
        )

        ModelPermission.register(
            model=Tag, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_events_view, permission_tag_attach,
                permission_tag_delete, permission_tag_edit,
                permission_tag_remove, permission_tag_view,
            )
        )

        SourceColumn(
            source=DocumentTag, attribute='label'
        )
        SourceColumn(
            source=DocumentTag, attribute='get_preview_widget'
        )

        SourceColumn(
            source=Document, label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'], user=context['request'].user
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'].document,
                user=context['request'].user
            )
        )

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

        document_page_search.add_model_field(
            field='document_version__document__tags__label', label=_('Tags')
        )
        document_search.add_model_field(field='tags__label', label=_('Tags'))

        menu_facet.bind_links(
            links=(link_tag_document_list,), sources=(Document,)
        )

        menu_tags.bind_links(
            links=(
                link_tag_list, link_tag_create
            )
        )

        menu_main.bind_links(links=(menu_tags,), position=98)

        menu_multi_item.bind_links(
            links=(
                link_multiple_documents_attach_tag,
                link_multiple_documents_tag_remove
            ),
            sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(link_tag_multiple_delete,), sources=(Tag,)
        )
        menu_object.bind_links(
            links=(
                link_tag_tagged_item_list, link_tag_edit, link_acl_list,
                link_events_for_object,
                link_object_event_types_user_subcriptions_list,
                link_tag_delete
            ),
            sources=(Tag,)
        )
        menu_sidebar.bind_links(
            links=(link_tag_attach, link_single_document_multiple_tag_remove),
            sources=(
                'tags:tag_attach', 'tags:document_tags',
                'tags:single_document_multiple_tag_remove'
            )
        )
        registry.register(Tag)

        # Index update

        m2m_changed.connect(
            handler_index_document,
            dispatch_uid='tags_handler_index_document',
            sender=Tag.documents.through
        )

        pre_delete.connect(
            handler_tag_pre_delete,
            dispatch_uid='tags_handler_tag_pre_delete',
            sender=Tag
        )
Exemplo n.º 41
0
    def ready(self):
        super(DjangoGPGApp, self).ready()

        Package(label='python-gnupg', license_text='''
Copyright (c) 2008-2014 by Vinay Sajip.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * The name(s) of the copyright holder(s) may not be used to endorse or
      promote products derived from this software without specific prior
      written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        ''')

        SourceColumn(source=Key, label=_('ID'), attribute='key_id')
        SourceColumn(
            source=Key, label=_('Owner'),
            func=lambda context: ', '.join(context['object'].uids)
        )

        SourceColumn(
            source=KeyStub, label=_('ID'),
            func=lambda context: '...{0}'.format(context['object'].key_id[-16:])
        )
        SourceColumn(source=KeyStub, label=_('Type'), attribute='key_type')
        SourceColumn(
            source=KeyStub, label=_('Creation date'),
            func=lambda context: datetime.fromtimestamp(
                int(context['object'].date)
            )
        )
        SourceColumn(
            source=KeyStub, label=_('Expiration date'),
            func=lambda context: datetime.fromtimestamp(int(context['object'].expires)) if context['object'].expires else _('No expiration')
        )
        SourceColumn(source=KeyStub, label=_('Length'), attribute='length')
        SourceColumn(
            source=KeyStub, label=_('Identities'),
            func=lambda context: ', '.join(context['object'].uids)
        )

        menu_object.bind_links(links=(link_key_delete,), sources=(Key,))
        menu_object.bind_links(links=(link_key_receive,), sources=(KeyStub,))
        menu_setup.bind_links(links=(link_key_setup,))
        menu_sidebar.bind_links(
            links=(link_public_keys, link_key_query),
            sources=(
                'django_gpg:key_delete', 'django_gpg:key_public_list',
                'django_gpg:key_query', 'django_gpg:key_query_results',
            )
        )
Exemplo n.º 42
0
    def ready(self):
        super(DocumentSignaturesApp, self).ready()

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        DocumentVersion = apps.get_model(
            app_label='documents', model_name='DocumentVersion'
        )

        Key = apps.get_model(
            app_label='django_gpg', model_name='Key'
        )

        EmbeddedSignature = self.get_model('EmbeddedSignature')

        SignatureBaseModel = self.get_model('SignatureBaseModel')

        DocumentVersion.register_post_save_hook(
            order=1, func=EmbeddedSignature.objects.create
        )
        DocumentVersion.register_pre_open_hook(
            order=1, func=EmbeddedSignature.objects.open_signed
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_document_version_sign_detached,
                permission_document_version_sign_embedded,
                permission_document_version_signature_delete,
                permission_document_version_signature_download,
                permission_document_version_signature_view,
                permission_document_version_signature_upload,
            )
        )

        SourceColumn(
            source=SignatureBaseModel, label=_('Date'), attribute='date'
        )
        SourceColumn(
            source=SignatureBaseModel, label=_('Key ID'),
            attribute='get_key_id'
        )
        SourceColumn(
            source=SignatureBaseModel, label=_('Signature ID'),
            func=lambda context: context['object'].signature_id or _('None')
        )
        SourceColumn(
            source=SignatureBaseModel, label=_('Type'),
            func=lambda context: SignatureBaseModel.objects.get_subclass(
                pk=context['object'].pk
            ).get_signature_type_display()
        )

        app.conf.CELERY_QUEUES.append(
            Queue(
                'signatures', Exchange('signatures'), routing_key='signatures'
            ),
        )

        app.conf.CELERY_ROUTES.update(
            {
                'document_signatures.tasks.task_verify_key_signatures': {
                    'queue': 'signatures'
                },
                'document_signatures.tasks.task_unverify_key_signatures': {
                    'queue': 'signatures'
                },
                'document_signatures.tasks.task_verify_document_version': {
                    'queue': 'signatures'
                },
                'document_signatures.tasks.task_verify_missing_embedded_signature': {
                    'queue': 'tools'
                },
            }
        )

        menu_facet.bind_links(
            links=(link_document_signature_list,), sources=(Document,)
        )
        menu_facet.bind_links(
            links=(
                link_document_version_signature_list,
            ), position=9, sources=(DocumentVersion,)
        )

        menu_object.bind_links(
            links=(
                link_document_version_signature_detached_create,
                link_document_version_signature_embedded_create
            ), sources=(DocumentVersion,)
        )
        menu_object.bind_links(
            links=(
                link_document_version_signature_details,
                link_document_version_signature_download,
                link_document_version_signature_delete,
            ), sources=(SignatureBaseModel,)
        )
        menu_sidebar.bind_links(
            links=(
                link_document_version_signature_upload,
            ), sources=(DocumentVersion,)
        )
        menu_tools.bind_links(
            links=(link_all_document_version_signature_verify,)
        )

        post_delete.connect(
            unverify_key_signatures,
            dispatch_uid='unverify_key_signatures',
            sender=Key
        )
        post_upgrade.connect(
            verify_missing_embedded_signature,
            dispatch_uid='verify_missing_embedded_signature',
        )
        post_save.connect(
            verify_key_signatures,
            dispatch_uid='verify_key_signatures',
            sender=Key
        )
Exemplo n.º 43
0
    def ready(self):
        super(DocumentStatesApp, self).ready()

        Action = apps.get_model(app_label='actstream', model_name='Action')
        Document = apps.get_model(app_label='documents', model_name='Document')
        ErrorLogEntry = apps.get_model(app_label='common',
                                       model_name='ErrorLogEntry')

        Workflow = self.get_model('Workflow')
        WorkflowInstance = self.get_model('WorkflowInstance')
        WorkflowInstanceLogEntry = self.get_model('WorkflowInstanceLogEntry')
        WorkflowRuntimeProxy = self.get_model('WorkflowRuntimeProxy')
        WorkflowState = self.get_model('WorkflowState')
        WorkflowStateAction = self.get_model('WorkflowStateAction')
        WorkflowStateRuntimeProxy = self.get_model('WorkflowStateRuntimeProxy')
        WorkflowTransition = self.get_model('WorkflowTransition')
        WorkflowTransitionTriggerEvent = self.get_model(
            'WorkflowTransitionTriggerEvent')

        Document.add_to_class('workflow', DocumentStateHelper.constructor)

        ErrorLogEntry.objects.register(model=WorkflowStateAction)

        WorkflowAction.initialize()

        ModelAttribute(
            model=Document,
            name='workflow.< workflow internal name >.get_current_state',
            label=_('Current state of a workflow'),
            description=_('Return the current state of the selected workflow'))
        ModelAttribute(
            model=Document,
            name=
            'workflow.< workflow internal name >.get_current_state.completion',
            label=_('Current state of a workflow'),
            description=_(
                'Return the completion value of the current state of the '
                'selected workflow'))

        ModelPermission.register(model=Document,
                                 permissions=(permission_workflow_view, ))
        ModelPermission.register(model=Workflow,
                                 permissions=(
                                     permission_error_log_view,
                                     permission_workflow_delete,
                                     permission_workflow_edit,
                                     permission_workflow_transition,
                                     permission_workflow_view,
                                 ))

        ModelPermission.register_inheritance(
            model=WorkflowInstance,
            related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowInstanceLogEntry,
            related='workflow_instance__workflow',
        )
        ModelPermission.register(
            model=WorkflowTransition,
            permissions=(permission_workflow_transition, ))

        ModelPermission.register_inheritance(
            model=WorkflowState,
            related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowStateAction,
            related='state__workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowTransition,
            related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowTransitionTriggerEvent,
            related='transition__workflow',
        )

        SourceColumn(source=Workflow, label=_('Label'), attribute='label')
        SourceColumn(source=Workflow,
                     label=_('Internal name'),
                     attribute='internal_name')
        SourceColumn(source=Workflow,
                     label=_('Initial state'),
                     func=lambda context: context['object'].get_initial_state(
                     ) or _('None'))

        SourceColumn(source=WorkflowInstance,
                     label=_('Current state'),
                     attribute='get_current_state')
        SourceColumn(
            source=WorkflowInstance,
            label=_('User'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'user', _('None')))
        SourceColumn(source=WorkflowInstance,
                     label=_('Last transition'),
                     attribute='get_last_transition')
        SourceColumn(
            source=WorkflowInstance,
            label=_('Date and time'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'datetime', _('None')))
        SourceColumn(
            source=WorkflowInstance,
            label=_('Completion'),
            func=lambda context: getattr(context['object'].get_current_state(),
                                         'completion', _('None')))

        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Date and time'),
                     attribute='datetime')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('User'),
                     attribute='user')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Transition'),
                     attribute='transition')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Comment'),
                     attribute='comment')

        SourceColumn(source=WorkflowState,
                     label=_('Is initial state?'),
                     func=lambda context: TwoStateWidget(state=context[
                         'object'].initial).render())
        SourceColumn(source=WorkflowState,
                     label=_('Completion'),
                     attribute='completion')

        SourceColumn(source=WorkflowStateAction,
                     label=_('Label'),
                     attribute='label')
        SourceColumn(source=WorkflowStateAction,
                     label=_('Enabled?'),
                     func=lambda context: TwoStateWidget(state=context[
                         'object'].enabled).render())
        SourceColumn(source=WorkflowStateAction,
                     label=_('When?'),
                     attribute='get_when_display')
        SourceColumn(source=WorkflowStateAction,
                     label=_('Action type'),
                     attribute='get_class_label')

        SourceColumn(source=WorkflowTransition,
                     label=_('Origin state'),
                     attribute='origin_state')
        SourceColumn(source=WorkflowTransition,
                     label=_('Destination state'),
                     attribute='destination_state')
        SourceColumn(source=WorkflowTransition,
                     label=_('Triggers'),
                     func=lambda context: widget_transition_events(
                         transition=context['object']))

        app.conf.CELERY_QUEUES.extend((Queue('document_states',
                                             Exchange('document_states'),
                                             routing_key='document_states'), ))

        app.conf.CELERY_ROUTES.update({
            'document_states.tasks.task_launch_all_workflows': {
                'queue': 'document_states'
            },
        })

        menu_facet.bind_links(links=(link_document_workflow_instance_list, ),
                              sources=(Document, ))
        menu_main.bind_links(links=(link_workflow_list, ), position=10)
        menu_object.bind_links(
            links=(link_setup_workflow_states, link_setup_workflow_transitions,
                   link_setup_workflow_document_types,
                   link_setup_workflow_edit, link_acl_list,
                   link_workflow_preview, link_setup_workflow_delete),
            sources=(Workflow, ))
        menu_object.bind_links(links=(link_setup_workflow_state_edit,
                                      link_setup_workflow_state_action_list,
                                      link_setup_workflow_state_delete),
                               sources=(WorkflowState, ))
        menu_object.bind_links(links=(link_setup_workflow_transition_edit,
                                      link_workflow_instance_transition_events,
                                      link_acl_list,
                                      link_setup_workflow_transition_delete),
                               sources=(WorkflowTransition, ))
        menu_object.bind_links(links=(link_workflow_instance_detail,
                                      link_workflow_instance_transition),
                               sources=(WorkflowInstance, ))
        menu_object.bind_links(links=(
            link_workflow_document_list,
            link_workflow_state_list,
        ),
                               sources=(WorkflowRuntimeProxy, ))
        menu_object.bind_links(links=(link_workflow_state_document_list, ),
                               sources=(WorkflowStateRuntimeProxy, ))
        menu_object.bind_links(links=(
            link_setup_workflow_state_action_edit,
            link_object_error_list,
            link_setup_workflow_state_action_delete,
        ),
                               sources=(WorkflowStateAction, ))

        menu_secondary.bind_links(
            links=(link_setup_workflow_list, link_setup_workflow_create),
            sources=(Workflow, 'document_states:setup_workflow_create',
                     'document_states:setup_workflow_list'))
        menu_secondary.bind_links(links=(link_workflow_list, ),
                                  sources=(WorkflowRuntimeProxy, ))
        menu_secondary.bind_links(
            links=(link_setup_workflow_state_action_selection, ),
            sources=(WorkflowState, ))
        menu_setup.bind_links(links=(link_setup_workflow_list, ))
        menu_sidebar.bind_links(links=(link_setup_workflow_state_create,
                                       link_setup_workflow_transition_create),
                                sources=(Workflow, ))
        menu_tools.bind_links(links=(link_tool_launch_all_workflows, ))

        post_save.connect(launch_workflow,
                          dispatch_uid='launch_workflow',
                          sender=Document)

        # Index updating

        post_save.connect(handler_index_document,
                          dispatch_uid='handler_index_document_save',
                          sender=WorkflowInstanceLogEntry)
        post_save.connect(
            handler_trigger_transition,
            dispatch_uid='document_states_handler_trigger_transition',
            sender=Action)
Exemplo n.º 44
0
    def ready(self):
        super(LinkingApp, self).ready()

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

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        ResolvedSmartLink = self.get_model('ResolvedSmartLink')
        SmartLink = self.get_model('SmartLink')
        SmartLinkCondition = self.get_model('SmartLinkCondition')

        ModelPermission.register(
            model=SmartLink, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_smart_link_delete, permission_smart_link_edit,
                permission_smart_link_view
            )
        )

        SourceColumn(
            source=ResolvedSmartLink, label=_('Label'),
            func=lambda context: context['object'].get_dynamic_label(
                context['document']
            )
        )

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

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

        menu_facet.bind_links(
            links=(link_smart_link_instances_for_document,),
            sources=(Document,)
        )
        menu_object.bind_links(
            links=(
                link_smart_link_condition_edit,
                link_smart_link_condition_delete
            ), sources=(SmartLinkCondition,)
        )
        menu_object.bind_links(
            links=(
                link_smart_link_edit, link_smart_link_document_types,
                link_smart_link_condition_list, link_acl_list,
                link_smart_link_delete
            ), sources=(SmartLink,)
        )
        menu_object.bind_links(
            links=(link_smart_link_instance_view,),
            sources=(ResolvedSmartLink,)
        )
        menu_secondary.bind_links(
            links=(link_smart_link_list, link_smart_link_create),
            sources=(
                SmartLink, 'linking:smart_link_list',
                'linking:smart_link_create'
            )
        )
        menu_setup.bind_links(links=(link_smart_link_setup,))
        menu_sidebar.bind_links(
            links=(link_smart_link_condition_create,),
            sources=(
                'linking:smart_link_condition_list',
                'linking:smart_link_condition_create',
                'linking:smart_link_condition_edit',
                'linking:smart_link_condition_delete'
            )
        )
Exemplo n.º 45
0
    def ready(self):
        super(DocumentsApp, self).ready()
        from actstream import registry

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

        DynamicSerializerField.add_serializer(
            klass=Document,
            serializer_class='documents.serializers.DocumentSerializer'
        )

        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'
        )

        ModelField(Document, name='description')
        ModelField(Document, name='date_added')
        ModelField(Document, name='deleted_date_time')
        ModelField(Document, name='document_type__label')
        ModelField(Document, name='in_trash')
        ModelField(Document, name='is_stub')
        ModelField(Document, name='label')
        ModelField(Document, name='language')
        ModelField(Document, name='uuid')
        ModelField(
            Document, name='versions__checksum'
        )
        ModelField(
            Document, label=_('Versions comment'), name='versions__comment'
        )
        ModelField(
            Document, label=_('Versions encoding'), name='versions__encoding'
        )
        ModelField(
            Document, label=_('Versions mime type'), name='versions__mimetype'
        )
        ModelField(
            Document, label=_('Versions timestamp'), name='versions__timestamp'
        )

        ModelEventType.register(
            model=DocumentType, event_types=(
                event_document_create,
                event_document_type_created,
                event_document_type_edited,
            )
        )
        ModelEventType.register(
            model=Document, event_types=(
                event_document_download, event_document_properties_edit,
                event_document_type_change, event_document_new_version,
                event_document_version_revert, event_document_view
            )
        )

        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_version_view, 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, permission_document_type_delete,
                permission_document_type_edit, permission_document_type_view
            )
        )

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

        ModelPermission.register_inheritance(
            model=Document, related='document_type',
        )
        ModelPermission.register_inheritance(
            model=DocumentPage, related='document_version__document',
        )
        ModelPermission.register_inheritance(
            model=DocumentPageResult, related='document_version__document',
        )
        ModelPermission.register_inheritance(
            model=DocumentTypeFilename, related='document_type',
        )
        ModelPermission.register_inheritance(
            model=DocumentVersion, related='document',
        )

        # Document and document page thumbnail widget
        document_page_thumbnail_widget = DocumentPageThumbnailWidget()

        # Document
        SourceColumn(
            source=Document, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )
        SourceColumn(
            source=Document, attribute='document_type'
        )
        SourceColumn(
            source=Document, label=_('Pages'),
            func=lambda context: widget_document_page_number(
                document=context['object']
            )
        )

        # DocumentPage
        SourceColumn(
            source=DocumentPage, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Type'),
            attribute='document_version.document.document_type'
        )

        # DocumentType
        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: TwoStateWidget(
                state=context['object'].enabled
            ).render()
        )

        # DeletedDocument
        SourceColumn(
            source=DeletedDocument, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DeletedDocument, attribute='document_type'
        )
        SourceColumn(
            source=DeletedDocument, attribute='deleted_date_time'
        )

        # DocumentVersion
        SourceColumn(
            source=DocumentVersion, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )
        SourceColumn(
            source=DocumentVersion, attribute='timestamp'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Pages'),
            func=lambda context: widget_document_version_page_number(
                document_version=context['object']
            )
        )
        SourceColumn(
            source=DocumentVersion, attribute='mimetype'
        )
        SourceColumn(
            source=DocumentVersion, attribute='encoding'
        )
        SourceColumn(
            source=DocumentVersion, attribute='comment'
        )

        # DuplicatedDocument
        SourceColumn(
            source=DuplicatedDocument, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object'].document
            )
        )
        SourceColumn(
            source=DuplicatedDocument, label=_('Duplicates'),
            func=lambda context: context['object'].documents.count()
        )

        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'),
                Queue(
                    'documents', Exchange('documents'), routing_key='documents'
                ),
            )
        )

        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_clean_empty_duplicate_lists': {
                    'queue': 'documents'
                },
                'documents.tasks.task_clear_image_cache': {
                    'queue': 'tools'
                },
                'documents.tasks.task_delete_document': {
                    'queue': 'documents'
                },
                'documents.tasks.task_delete_stubs': {
                    'queue': 'documents_periodic'
                },
                'documents.tasks.task_generate_document_page_image': {
                    'queue': 'converter'
                },
                'documents.tasks.task_scan_duplicates_all': {
                    'queue': 'tools'
                },
                'documents.tasks.task_scan_duplicates_for': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_update_page_count': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_upload_new_version': {
                    'queue': 'uploads'
                },
            }
        )

        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentsTotal, order=0
        )
        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentPagesTotal, order=1
        )
        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentsInTrash, order=2
        )
        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentsTypesTotal, order=3
        )
        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentsNewThisMonth, order=4
        )
        dashboard_main.add_widget(
            widget=DashboardWidgetDocumentsPagesNewThisMonth, order=5
        )

        menu_documents.bind_links(
            links=(
                link_document_list_recent_access,
                link_document_list_recent_added, link_document_list_favorites,
                link_document_list, link_document_list_deleted,
                link_duplicated_document_list,
            )
        )

        menu_main.bind_links(links=(menu_documents,), position=0)

        menu_setup.bind_links(links=(link_document_type_setup,))
        menu_tools.bind_links(
            links=(link_clear_image_cache, link_duplicated_document_scan)
        )

        # Document type links
        menu_object.bind_links(
            links=(
                link_document_type_edit, link_document_type_filename_list,
                link_acl_list, link_object_event_types_user_subcriptions_list,
                link_document_type_delete,
                link_events_for_object,
            ), 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_favorites_add, link_document_favorites_remove,
                link_document_edit, link_document_document_type_edit,
                link_document_print, link_document_trash,
                link_document_quick_download, link_document_download,
                link_document_clear_transformations,
                link_document_clone_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_document_duplicates_list, 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_object_event_types_user_subcriptions_list,
                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_favorites_add,
                link_document_multiple_favorites_remove,
                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.add_unsorted_source(source=DocumentPage)
        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,)
        )

        # Document versions
        menu_facet.bind_links(
            links=(
                link_document_version_return_document,
                link_document_version_return_list
            ), sources=(DocumentVersion,)
        )
        menu_facet.bind_links(
            links=(link_document_version_view,), sources=(DocumentVersion,)
        )

        post_delete.connect(
            dispatch_uid='handler_remove_empty_duplicates_lists',
            receiver=handler_remove_empty_duplicates_lists,
            sender=Document,
        )
        post_initial_setup.connect(
            create_default_document_type,
            dispatch_uid='create_default_document_type'
        )
        post_version_upload.connect(
            handler_scan_duplicates_for,
            dispatch_uid='handler_scan_duplicates_for',
        )

        registry.register(DeletedDocument)
        registry.register(Document)
        registry.register(DocumentType)
        registry.register(DocumentVersion)
Exemplo n.º 46
0
    def ready(self):
        super(CheckoutsApp, self).ready()

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

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )
        DocumentVersion = apps.get_model(
            app_label='documents', model_name='DocumentVersion'
        )

        DocumentCheckout = self.get_model('DocumentCheckout')

        Document.add_to_class(
            'check_in',
            lambda document, user=None: DocumentCheckout.objects.check_in_document(document, user)
        )
        Document.add_to_class(
            'checkout_info',
            lambda document: DocumentCheckout.objects.document_checkout_info(
                document
            )
        )
        Document.add_to_class(
            'checkout_state',
            lambda document: DocumentCheckout.objects.document_checkout_state(
                document
            )
        )
        Document.add_to_class(
            'is_checked_out',
            lambda document: DocumentCheckout.objects.is_document_checked_out(
                document
            )
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_document_checkout,
                permission_document_checkin,
                permission_document_checkin_override,
                permission_document_checkout_detail_view
            )
        )

        app.conf.CELERYBEAT_SCHEDULE.update(
            {
                'task_check_expired_check_outs': {
                    'task': 'checkouts.tasks.task_check_expired_check_outs',
                    'schedule': timedelta(
                        seconds=CHECK_EXPIRED_CHECK_OUTS_INTERVAL
                    ),
                },
            }
        )

        app.conf.CELERY_QUEUES.append(
            Queue(
                'checkouts_periodic', Exchange('checkouts_periodic'),
                routing_key='checkouts_periodic', delivery_mode=1
            ),
        )

        app.conf.CELERY_ROUTES.update(
            {
                'checkouts.tasks.task_check_expired_check_outs': {
                    'queue': 'checkouts_periodic'
                },
            }
        )

        dashboard_main.add_widget(order=-1, widget=widget_checkouts)

        menu_facet.bind_links(links=(link_checkout_info,), sources=(Document,))
        menu_main.bind_links(links=(link_checkout_list,), position=98)
        menu_sidebar.bind_links(
            links=(link_checkout_document, link_checkin_document),
            sources=(
                'checkouts:checkout_info', 'checkouts:checkout_document',
                'checkouts:checkin_document'
            )
        )

        pre_save.connect(
            check_new_version_creation,
            dispatch_uid='check_new_version_creation',
            sender=DocumentVersion
        )
Exemplo n.º 47
0
    def ready(self):
        super(DocumentStatesApp, self).ready()

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

        Document = apps.get_model(
            app_label='documents', model_name='Document'
        )

        Document.add_to_class(
            'workflow', DocumentStateHelper.constructor
        )

        Workflow = self.get_model('Workflow')
        WorkflowInstance = self.get_model('WorkflowInstance')
        WorkflowInstanceLogEntry = self.get_model('WorkflowInstanceLogEntry')
        WorkflowRuntimeProxy = self.get_model('WorkflowRuntimeProxy')
        WorkflowState = self.get_model('WorkflowState')
        WorkflowStateRuntimeProxy = self.get_model('WorkflowStateRuntimeProxy')
        WorkflowTransition = self.get_model('WorkflowTransition')

        ModelAttribute(
            Document, 'workflow.< workflow internal name >.get_current_state',
            label=_('Current state of a workflow'), description=_(
                'Return the current state of the selected workflow'
            ), type_name=['property', 'indexing']
        )
        ModelAttribute(
            Document,
            'workflow.< workflow internal name >.get_current_state.completion',
            label=_('Current state of a workflow'), description=_(
                'Return the completion value of the current state of the '
                'selected workflow'
            ), type_name=['property', 'indexing']
        )

        ModelPermission.register(
            model=Workflow, permissions=(permission_workflow_transition,)
        )

        ModelPermission.register(
            model=WorkflowTransition,
            permissions=(permission_workflow_transition,)
        )

        SourceColumn(
            source=Workflow, label=_('Label'), attribute='label'
        )
        SourceColumn(
            source=Workflow, label=_('Internal name'),
            attribute='internal_name'
        )
        SourceColumn(
            source=Workflow, label=_('Initial state'),
            func=lambda context: context['object'].get_initial_state() or _('None')
        )

        SourceColumn(
            source=WorkflowInstance, label=_('Current state'),
            attribute='get_current_state'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('User'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'user', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Last transition'),
            attribute='get_last_transition'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Date and time'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'datetime', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Completion'),
            func=lambda context: getattr(
                context['object'].get_current_state(), 'completion', _('None')
            )
        )

        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Date and time'),
            attribute='datetime'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('User'), attribute='user'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Transition'),
            attribute='transition'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Comment'),
            attribute='comment'
        )

        SourceColumn(
            source=WorkflowState, label=_('Is initial state?'),
            func=lambda context: two_state_template(context['object'].initial)
        )
        SourceColumn(
            source=WorkflowState, label=_('Completion'), attribute='completion'
        )

        SourceColumn(
            source=WorkflowTransition, label=_('Origin state'),
            attribute='origin_state'
        )
        SourceColumn(
            source=WorkflowTransition, label=_('Destination state'),
            attribute='destination_state'
        )

        app.conf.CELERY_QUEUES.extend(
            (
                Queue(
                    'document_states', Exchange('document_states'),
                    routing_key='document_states'
                ),
            )
        )

        app.conf.CELERY_ROUTES.update(
            {
                'document_states.tasks.task_launch_all_workflows': {
                    'queue': 'document_states'
                },
            }
        )

        menu_facet.bind_links(
            links=(link_document_workflow_instance_list,), sources=(Document,)
        )
        menu_main.bind_links(links=(link_workflow_list,), position=10)
        menu_object.bind_links(
            links=(
                link_setup_workflow_states, link_setup_workflow_transitions,
                link_setup_workflow_document_types, link_setup_workflow_edit,
                link_acl_list, link_setup_workflow_delete
            ), sources=(Workflow,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_state_edit,
                link_setup_workflow_state_delete
            ), sources=(WorkflowState,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_transition_edit, link_acl_list,
                link_setup_workflow_transition_delete
            ), sources=(WorkflowTransition,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_instance_detail,
                link_workflow_instance_transition
            ), sources=(WorkflowInstance,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_document_list, link_workflow_state_list,
            ), sources=(WorkflowRuntimeProxy,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_state_document_list,
            ), sources=(WorkflowStateRuntimeProxy,)
        )
        menu_secondary.bind_links(
            links=(link_setup_workflow_list, link_setup_workflow_create),
            sources=(
                Workflow, 'document_states:setup_workflow_create',
                'document_states:setup_workflow_list'
            )
        )
        menu_secondary.bind_links(
            links=(link_workflow_list,),
            sources=(
                WorkflowRuntimeProxy,
            )
        )
        menu_setup.bind_links(links=(link_setup_workflow_list,))
        menu_sidebar.bind_links(
            links=(
                link_setup_workflow_state_create,
                link_setup_workflow_transition_create
            ), sources=(Workflow,)
        )
        menu_tools.bind_links(links=(link_tool_launch_all_workflows,))

        post_save.connect(
            launch_workflow, dispatch_uid='launch_workflow', sender=Document
        )

        # Index updating

        post_save.connect(
            handler_index_document,
            dispatch_uid='handler_index_document_save',
            sender=WorkflowInstanceLogEntry
        )
Exemplo n.º 48
0
    def ready(self):
        super(TagsApp, self).ready()

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

        Document.add_to_class(
            'attached_tags',
            lambda document: DocumentTag.objects.filter(documents=document)
        )

        ModelPermission.register(
            model=Document, permissions=(
                permission_tag_attach, permission_tag_remove,
                permission_tag_view
            )
        )

        ModelPermission.register(
            model=Tag, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_tag_delete, permission_tag_edit,
                permission_tag_view,
            )
        )

        SourceColumn(
            source=DocumentTag, label=_('Preview'),
            func=lambda context: widget_single_tag(context['object'])
        )

        SourceColumn(
            source=Document, label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'], user=context['request'].user
            )
        )

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

        document_search.add_model_field(field='tags__label', label=_('Tags'))

        menu_facet.bind_links(
            links=(link_tag_document_list,), sources=(Document,)
        )
        menu_main.bind_links(links=(link_tag_list,))
        menu_multi_item.bind_links(
            links=(
                link_multiple_documents_attach_tag,
                link_multiple_documents_tag_remove
            ),
            sources=(Document,)
        )
        menu_multi_item.bind_links(
            links=(link_tag_multiple_delete,), sources=(Tag,)
        )
        menu_multi_item.bind_links(
            links=(link_single_document_multiple_tag_remove,),
            sources=(DocumentTag,)
        )
        menu_object.bind_links(
            links=(
                link_tag_tagged_item_list, link_tag_edit, link_acl_list,
                link_tag_delete
            ),
            sources=(Tag,)
        )
        menu_secondary.bind_links(
            links=(link_tag_list, link_tag_create),
            sources=(Tag, 'tags:tag_list', 'tags:tag_create')
        )
        menu_sidebar.bind_links(
            links=(link_tag_attach,),
            sources=(
                'tags:document_tags', 'tags:tag_remove',
                'tags:tag_multiple_remove', 'tags:tag_attach'
            )
        )
Exemplo n.º 49
0
    def ready(self):
        super(SourcesApp, self).ready()

        POP3Email = self.get_model('POP3Email')
        IMAPEmail = self.get_model('IMAPEmail')
        Source = self.get_model('Source')
        SourceLog = self.get_model('SourceLog')
        SaneScanner = self.get_model('SaneScanner')
        StagingFolderSource = self.get_model('StagingFolderSource')
        WatchFolderSource = self.get_model('WatchFolderSource')
        WebFormSource = self.get_model('WebFormSource')

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

        MissingItem(
            label=_('Create a document source'),
            description=_(
                'Document sources are the way in which new documents are '
                'feed to Mayan EDMS, create at least a web form source to '
                'be able to upload documents from a browser.'),
            condition=lambda: not Source.objects.exists(),
            view='sources:setup_source_list')

        SourceColumn(
            source=StagingFile,
            label=_('Created'),
            func=lambda context: context['object'].get_date_time_created())

        html_widget = StagingFileThumbnailWidget()
        SourceColumn(source=StagingFile,
                     label=_('Thumbnail'),
                     func=lambda context: html_widget.render(instance=context[
                         'object'], ))

        SourceColumn(source=SourceLog,
                     label=_('Date time'),
                     func=lambda context: context['object'].datetime)
        SourceColumn(source=SourceLog,
                     label=_('Message'),
                     func=lambda context: context['object'].message)

        app.conf.CELERY_QUEUES.extend((
            Queue('sources', Exchange('sources'), routing_key='sources'),
            Queue('sources_periodic',
                  Exchange('sources_periodic'),
                  routing_key='sources_periodic',
                  delivery_mode=1),
        ))

        app.conf.CELERY_ROUTES.update({
            'sources.tasks.task_check_interval_source': {
                'queue': 'sources_periodic'
            },
            'sources.tasks.task_source_handle_upload': {
                'queue': 'sources'
            },
            'sources.tasks.task_upload_document': {
                'queue': 'sources'
            },
        })
        menu_documents.bind_links(links=(link_document_create_multiple, ))

        menu_object.bind_links(
            links=(link_setup_source_edit, link_setup_source_delete,
                   link_transformation_list, link_setup_source_logs),
            sources=(POP3Email, IMAPEmail, SaneScanner, StagingFolderSource,
                     WatchFolderSource, WebFormSource))
        menu_object.bind_links(links=(link_staging_file_delete, ),
                               sources=(StagingFile, ))
        menu_object.bind_links(links=(link_setup_source_check_now, ),
                               sources=(
                                   IMAPEmail,
                                   POP3Email,
                                   WatchFolderSource,
                               ))
        menu_secondary.bind_links(
            links=(link_setup_sources, link_setup_source_create_webform,
                   link_setup_source_create_sane_scanner,
                   link_setup_source_create_staging_folder,
                   link_setup_source_create_pop3_email,
                   link_setup_source_create_imap_email,
                   link_setup_source_create_watch_folder),
            sources=(POP3Email, IMAPEmail, StagingFolderSource,
                     WatchFolderSource, WebFormSource,
                     'sources:setup_source_list',
                     'sources:setup_source_create'))
        menu_setup.bind_links(links=(link_setup_sources, ))
        menu_sidebar.bind_links(links=(link_upload_version, ),
                                sources=('documents:document_version_list',
                                         'documents:upload_version',
                                         'documents:document_version_revert'))

        post_upgrade.connect(initialize_periodic_tasks,
                             dispatch_uid='initialize_periodic_tasks')
        post_initial_setup.connect(
            create_default_document_source,
            dispatch_uid='create_default_document_source')
        post_version_upload.connect(
            copy_transformations_to_version,
            dispatch_uid='copy_transformations_to_version')
Exemplo n.º 50
0
    def ready(self):
        super(DocumentStatesApp, self).ready()

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

        Document = apps.get_model(app_label='documents', model_name='Document')

        Workflow = self.get_model('Workflow')
        WorkflowInstance = self.get_model('WorkflowInstance')
        WorkflowInstanceLogEntry = self.get_model('WorkflowInstanceLogEntry')
        WorkflowState = self.get_model('WorkflowState')
        WorkflowTransition = self.get_model('WorkflowTransition')

        ModelPermission.register(
            model=Workflow, permissions=(permission_workflow_transition, ))

        ModelPermission.register(
            model=WorkflowTransition,
            permissions=(permission_workflow_transition, ))

        SourceColumn(source=Workflow,
                     label=_('Initial state'),
                     func=lambda context: context['object'].get_initial_state(
                     ) or _('None'))

        SourceColumn(source=WorkflowInstance,
                     label=_('Current state'),
                     attribute='get_current_state')
        SourceColumn(
            source=WorkflowInstance,
            label=_('User'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'user', _('None')))
        SourceColumn(source=WorkflowInstance,
                     label=_('Last transition'),
                     attribute='get_last_transition')
        SourceColumn(
            source=WorkflowInstance,
            label=_('Date and time'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'datetime', _('None')))
        SourceColumn(
            source=WorkflowInstance,
            label=_('Completion'),
            func=lambda context: getattr(context['object'].get_current_state(),
                                         'completion', _('None')))

        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Date and time'),
                     attribute='datetime')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('User'),
                     attribute='user')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Transition'),
                     attribute='transition')
        SourceColumn(source=WorkflowInstanceLogEntry,
                     label=_('Comment'),
                     attribute='comment')

        SourceColumn(
            source=WorkflowState,
            label=_('Is initial state?'),
            func=lambda context: two_state_template(context['object'].initial))
        SourceColumn(source=WorkflowState,
                     label=_('Completion'),
                     attribute='completion')

        SourceColumn(source=WorkflowTransition,
                     label=_('Origin state'),
                     attribute='origin_state')
        SourceColumn(source=WorkflowTransition,
                     label=_('Destination state'),
                     attribute='destination_state')

        menu_facet.bind_links(links=(link_document_workflow_instance_list, ),
                              sources=(Document, ))
        menu_object.bind_links(links=(link_setup_workflow_states,
                                      link_setup_workflow_transitions,
                                      link_setup_workflow_document_types,
                                      link_setup_workflow_edit, link_acl_list,
                                      link_setup_workflow_delete),
                               sources=(Workflow, ))
        menu_object.bind_links(links=(link_setup_workflow_state_edit,
                                      link_setup_workflow_state_delete),
                               sources=(WorkflowState, ))
        menu_object.bind_links(links=(link_setup_workflow_transition_edit,
                                      link_acl_list,
                                      link_setup_workflow_transition_delete),
                               sources=(WorkflowTransition, ))
        menu_object.bind_links(links=(link_workflow_instance_detail,
                                      link_workflow_instance_transition),
                               sources=(WorkflowInstance, ))
        menu_secondary.bind_links(
            links=(link_setup_workflow_list, link_setup_workflow_create),
            sources=(Workflow, 'document_states:setup_workflow_create',
                     'document_states:setup_workflow_list'))
        menu_setup.bind_links(links=(link_setup_workflow_list, ))
        menu_sidebar.bind_links(links=(link_setup_workflow_state_create,
                                       link_setup_workflow_transition_create),
                                sources=(Workflow, ))

        post_save.connect(launch_workflow,
                          dispatch_uid='launch_workflow',
                          sender=Document)
Exemplo n.º 51
0
    def ready(self):
        super(TagsApp, self).ready()

        Document = apps.get_model(app_label='documents', model_name='Document')

        DocumentTag = self.get_model('DocumentTag')
        Tag = self.get_model('Tag')

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

        Document.add_to_class(
            'attached_tags',
            lambda document: DocumentTag.objects.filter(documents=document))

        ModelPermission.register(model=Document,
                                 permissions=(permission_tag_attach,
                                              permission_tag_remove,
                                              permission_tag_view))

        ModelPermission.register(model=Tag,
                                 permissions=(
                                     permission_acl_edit,
                                     permission_acl_view,
                                     permission_tag_delete,
                                     permission_tag_edit,
                                     permission_tag_view,
                                 ))

        SourceColumn(source=DocumentTag,
                     label=_('Preview'),
                     func=lambda context: widget_single_tag(context['object']))

        SourceColumn(
            source=Document,
            label=_('Tags'),
            func=lambda context: widget_document_tags(
                document=context['object'], user=context['request'].user))

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

        document_search.add_model_field(field='tags__label', label=_('Tags'))

        menu_facet.bind_links(links=(link_tag_document_list, ),
                              sources=(Document, ))
        menu_main.bind_links(links=(link_tag_list, ))
        menu_multi_item.bind_links(links=(link_multiple_documents_attach_tag,
                                          link_multiple_documents_tag_remove),
                                   sources=(Document, ))
        menu_multi_item.bind_links(links=(link_tag_multiple_delete, ),
                                   sources=(Tag, ))
        menu_multi_item.bind_links(
            links=(link_single_document_multiple_tag_remove, ),
            sources=(DocumentTag, ))
        menu_object.bind_links(links=(link_tag_tagged_item_list, link_tag_edit,
                                      link_acl_list, link_tag_delete),
                               sources=(Tag, ))
        menu_secondary.bind_links(links=(link_tag_list, link_tag_create),
                                  sources=(Tag, 'tags:tag_list',
                                           'tags:tag_create'))
        menu_sidebar.bind_links(
            links=(link_tag_attach, ),
            sources=('tags:document_tags', 'tags:tag_remove',
                     'tags:tag_multiple_remove', 'tags:tag_attach'))
Exemplo n.º 52
0
    def ready(self):
        super(DocumentsApp, self).ready()
        from actstream import registry

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

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

        Collection(
            label=_('Recent documents'), link=link_document_list_recent,
            order=1
        )
        Collection(
            label=_('Document types'), model=DocumentType,
            icon='fa fa-book'
        )
        Collection(
            label=_('All documents'), link=link_document_list, order=99
        )
        Collection(
            label=_('Trash'), link=link_document_list_deleted, order=100
        )

        DynamicSerializerField.add_serializer(
            klass=Document,
            serializer_class='documents.serializers.DocumentSerializer'
        )

        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_version_view, 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, permission_document_type_delete,
                permission_document_type_edit, permission_document_type_view
            )
        )

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

        ModelPermission.register_inheritance(
            model=Document, related='document_type',
        )
        ModelPermission.register_inheritance(
            model=DocumentPage, related='document',
        )
        ModelPermission.register_inheritance(
            model=DocumentTypeFilename, related='document_type',
        )
        ModelPermission.register_inheritance(
            model=DocumentVersion, related='document',
        )

        # Document and document page thumbnail widget
        document_page_thumbnail_widget = DocumentPageThumbnailWidget()
        document_thumbnail_widget = DocumentThumbnailWidget()
        document_version_thumbnail_widget = DocumentVersionThumbnailWidget()

        # Document
        SourceColumn(
            source=Document, label=_('Thumbnail'),
            func=lambda context: document_thumbnail_widget.render(
                instance=context['object']
            )
        )
        SourceColumn(
            source=Document, label=_('Type'), attribute='document_type'
        )

        # DocumentPage
        SourceColumn(
            source=DocumentPage, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Thumbnail'),
            func=lambda context: document_page_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DocumentPageResult, label=_('Type'),
            attribute='document_version.document.document_type'
        )

        # DocumentType
        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)
        )

        # DeletedDocument
        SourceColumn(
            source=DeletedDocument, label=_('Thumbnail'),
            func=lambda context: document_thumbnail_widget.render(
                instance=context['object']
            )
        )

        SourceColumn(
            source=DeletedDocument, label=_('Type'), attribute='document_type'
        )
        SourceColumn(
            source=DeletedDocument, label=_('Date time trashed'),
            attribute='deleted_date_time'
        )

        # DocumentVersion
        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'
        )
        SourceColumn(
            source=DocumentVersion, label=_('Thumbnail'),
            func=lambda context: document_version_thumbnail_widget.render(
                instance=context['object']
            )
        )

        # DuplicatedDocument
        SourceColumn(
            source=DuplicatedDocument, label=_('Thumbnail'),
            func=lambda context: document_thumbnail_widget.render(
                instance=context['object'].document
            )
        )
        SourceColumn(
            source=DuplicatedDocument, label=_('Duplicates'),
            func=lambda context: context['object'].documents.count()
        )

        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'),
                Queue(
                    'documents', Exchange('documents'), routing_key='documents'
                ),
            )
        )

        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_generate_document_page_image': {
                    'queue': 'converter'
                },
                'documents.tasks.task_update_page_count': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_upload_new_version': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_scan_duplicates_all': {
                    'queue': 'tools'
                },
                'documents.tasks.task_scan_duplicates_for': {
                    'queue': 'uploads'
                },
                'documents.tasks.task_delete_document': {
                    'queue': 'documents'
                },
            }
        )

        dashboard_main.add_widget(widget=widget_document_types)
        dashboard_main.add_widget(widget=widget_documents_in_trash)
        dashboard_main.add_widget(widget=widget_new_documents_this_month)
        dashboard_main.add_widget(widget=widget_pages_per_month)
        dashboard_main.add_widget(widget=widget_total_documents)

        menu_documents.bind_links(
            links=(
                link_document_list_recent, link_document_list,
                link_document_list_deleted, link_duplicated_document_list
            )
        )

        menu_main.bind_links(links=(menu_documents,), position=0)

        menu_setup.bind_links(links=(link_document_type_setup,))
        menu_tools.bind_links(
            links=(link_clear_image_cache, link_duplicated_document_scan)
        )

        # 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_clone_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_document_duplicates_list, link_acl_list_with_icon,),
            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,)
        )

        # Document versions
        menu_facet.bind_links(
            links=(
                link_document_version_return_document,
                link_document_version_return_list
            ), sources=(DocumentVersion,)
        )
        menu_facet.bind_links(
            links=(link_document_version_view,), sources=(DocumentVersion,)
        )

        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'
        )
        post_version_upload.connect(
            handler_scan_duplicates_for,
            dispatch_uid='handler_scan_duplicates_for',
        )

        registry.register(DeletedDocument)
        registry.register(Document)
        registry.register(DocumentType)
        registry.register(DocumentVersion)
Exemplo n.º 53
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)
Exemplo n.º 54
0
    def ready(self):
        super(DocumentStatesApp, self).ready()

        SourceColumn(
            source=Workflow, label=_('Initial state'),
            func=lambda context: context['object'].get_initial_state() or _('None')
        )

        SourceColumn(
            source=WorkflowInstance, label=_('Current state'),
            attribute='get_current_state'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('User'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'user', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Last transition'),
            attribute='get_last_transition'
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Date and time'),
            func=lambda context: getattr(
                context['object'].get_last_log_entry(), 'datetime', _('None')
            )
        )
        SourceColumn(
            source=WorkflowInstance, label=_('Completion'),
            func=lambda context: getattr(
                context['object'].get_current_state(), 'completion', _('None')
            )
        )

        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Date and time'),
            attribute='datetime'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('User'), attribute='user'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Transition'),
            attribute='transition'
        )
        SourceColumn(
            source=WorkflowInstanceLogEntry, label=_('Comment'),
            attribute='comment'
        )

        SourceColumn(
            source=WorkflowState, label=_('Is initial state?'),
            func=lambda context: two_state_template(context['object'].initial)
        )
        SourceColumn(
            source=WorkflowState, label=_('Completion'), attribute='completion'
        )

        SourceColumn(
            source=WorkflowTransition, label=_('Origin state'),
            attribute='origin_state'
        )
        SourceColumn(
            source=WorkflowTransition, label=_('Destination state'),
            attribute='destination_state'
        )

        menu_facet.bind_links(
            links=(link_document_workflow_instance_list,), sources=(Document,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_states, link_setup_workflow_transitions,
                link_setup_workflow_document_types, link_setup_workflow_edit,
                link_setup_workflow_delete
            ), sources=(Workflow,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_state_edit,
                link_setup_workflow_state_delete
            ), sources=(WorkflowState,)
        )
        menu_object.bind_links(
            links=(
                link_setup_workflow_transition_edit,
                link_setup_workflow_transition_delete
            ), sources=(WorkflowTransition,)
        )
        menu_object.bind_links(
            links=(
                link_workflow_instance_detail,
                link_workflow_instance_transition
            ), sources=(WorkflowInstance,)
        )
        menu_secondary.bind_links(
            links=(link_setup_workflow_list, link_setup_workflow_create),
            sources=(
                Workflow, 'document_states:setup_workflow_create',
                'document_states:setup_workflow_list'
            )
        )
        menu_setup.bind_links(links=(link_setup_workflow_list,))
        menu_sidebar.bind_links(
            links=(
                link_setup_workflow_state_create,
                link_setup_workflow_transition_create
            ), sources=(Workflow,)
        )

        post_save.connect(
            launch_workflow, dispatch_uid='launch_workflow', sender=Document
        )