예제 #1
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(attribute='serialized_value',
                     label=_('Value'),
                     source=Setting)
        SourceColumn(attribute='is_overrided',
                     source=Setting,
                     widget=TwoStateWidget)

        menu_object.bind_links(links=(link_namespace_detail, ),
                               sources=(Namespace, ))
        menu_object.bind_links(links=(link_setting_edit, ),
                               sources=(Setting, ))
        menu_secondary.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()
예제 #2
0
파일: apps.py 프로젝트: stewart-lhc/mayan
    def ready(self):
        super(StatisticsApp, self).ready()

        SourceColumn(
            attribute='schedule',
            # Translators: Schedule here is a noun, the 'schedule' at
            # which the statistic will be updated
            label=_('Schedule'),
            source=StatisticLineChart,
        )

        SourceColumn(
            attribute='get_last_update',
            label=_('Last update'),
            source=StatisticLineChart,
        )

        menu_object.bind_links(links=(link_execute, link_view),
                               sources=(StatisticLineChart, ))
        menu_object.bind_links(links=(link_namespace_details, ),
                               sources=(StatisticNamespace, ))
        menu_secondary.bind_links(links=(link_namespace_list, ),
                                  sources=(StatisticNamespace,
                                           'statistics:namespace_list'))
        menu_tools.bind_links(links=(link_statistics, ))
예제 #3
0
    def ready(self):
        super(SmartSettingsApp, self).ready()

        SettingNamespace.load_modules()

        SourceColumn(func=lambda context: len(context['object'].settings),
                     label=_('Setting count'),
                     include_label=True,
                     source=SettingNamespace)
        SourceColumn(func=lambda context: setting_widget(context['object']),
                     label=_('Name'),
                     is_identifier=True,
                     source=Setting)
        SourceColumn(attribute='serialized_value',
                     include_label=True,
                     label=_('Value'),
                     source=Setting)
        SourceColumn(attribute='is_overridden',
                     include_label=True,
                     source=Setting,
                     widget=TwoStateWidget)

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

        Setting.save_last_known_good()
예제 #4
0
파일: apps.py 프로젝트: stewart-lhc/mayan
    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_secondary.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()
예제 #5
0
    def ready(self):
        super(ConverterApp, self).ready()

        LayerTransformation = self.get_model(model_name='LayerTransformation')

        ModelPermission.register_inheritance(
            model=LayerTransformation,
            related='object_layer__content_object',
        )

        SourceColumn(attribute='order',
                     is_identifier=True,
                     source=LayerTransformation)
        SourceColumn(func=lambda context: force_text(context['object']),
                     include_label=True,
                     label=_('Transformation'),
                     source=LayerTransformation)
        SourceColumn(attribute='arguments',
                     include_label=True,
                     source=LayerTransformation)

        menu_object.bind_links(links=(link_transformation_edit,
                                      link_transformation_delete),
                               sources=(LayerTransformation, ))
        menu_secondary.bind_links(links=(link_transformation_select, ),
                                  sources=(LayerTransformation, ))
        menu_secondary.bind_links(links=(link_transformation_select, ),
                                  sources=('converter:transformation_create',
                                           'converter:transformation_list'))
예제 #6
0
    def ready(self):
        super(PermissionsApp, self).ready()

        Role = self.get_model('Role')
        Group = apps.get_model(app_label='auth', model_name='Group')

        Group.add_to_class(name='roles_add', value=method_group_roles_add)
        Group.add_to_class(name='roles_remove',
                           value=method_group_roles_remove)

        EventModelRegistry.register(model=Role)

        ModelEventType.register(event_types=(event_role_created,
                                             event_role_edited),
                                model=Role)

        ModelPermission.register(
            model=Role,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_events_view, permission_role_delete,
                         permission_role_edit, permission_role_view))

        # Initialize the permissions at the ready method for subsequent
        # restarts.
        Permission.initialize()

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Role)

        dashboard_main.add_widget(widget=DashboardWidgetRoleTotal, order=99)

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
            link_role_groups,
            link_role_permissions,
        ),
                                   sources=(Role, ))
        menu_list_facet.bind_links(links=(link_group_roles, ),
                                   sources=(Group, ))
        menu_object.bind_links(links=(link_role_delete, link_role_edit),
                               sources=(Role, ))
        menu_secondary.bind_links(links=(link_role_list, link_role_create),
                                  sources=(Role, 'permissions:role_create',
                                           'permissions:role_list'))
        menu_setup.bind_links(links=(link_role_list, ))

        # Initialize the permissions post migrate of this app for new
        # installations
        post_migrate.connect(
            dispatch_uid='permissions_handler_permission_initialize',
            receiver=handler_permission_initialize,
            sender=self)

        perform_upgrade.connect(
            dispatch_uid='permissions_handler_purge_permissions',
            receiver=handler_purge_permissions)
예제 #7
0
    def ready(self):
        super(ACLsApp, self).ready()
        from actstream import registry

        AccessControlList = self.get_model(model_name='AccessControlList')

        ModelEventType.register(event_types=(event_acl_created,
                                             event_acl_edited),
                                model=AccessControlList)

        ModelPermission.register_inheritance(
            model=AccessControlList,
            related='content_object',
        )

        SourceColumn(
            attribute='role',
            is_sortable=True,
            source=AccessControlList,
        )

        menu_object.bind_links(
            links=(link_acl_permissions, link_acl_delete,
                   link_events_for_object,
                   link_object_event_types_user_subcriptions_list),
            sources=(AccessControlList, ))
        menu_secondary.bind_links(links=(link_acl_create, ),
                                  sources=('acls:acl_list', ))

        registry.register(AccessControlList)
예제 #8
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()
        from actstream import registry

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

        Comment = self.get_model(model_name='Comment')

        ModelEventType.register(model=Comment,
                                event_types=(event_document_comment_edited, ))
        ModelEventType.register(model=Document,
                                event_types=(event_document_comment_created,
                                             event_document_comment_deleted,
                                             event_document_comment_edited))

        ModelPermission.register(model=Comment,
                                 permissions=(permission_events_view, ))
        ModelPermission.register_inheritance(
            model=Comment,
            related='document',
        )
        ModelPermission.register(
            model=Document,
            permissions=(permission_document_comment_create,
                         permission_document_comment_delete,
                         permission_document_comment_edit,
                         permission_document_comment_view))

        SourceColumn(attribute='submit_date', source=Comment)
        SourceColumn(attribute='get_user_label', source=Comment)
        SourceColumn(attribute='comment', source=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_facet.bind_links(links=(link_comments_for_document, ),
                              sources=(Document, ))

        menu_list_facet.bind_links(
            links=(link_events_for_object,
                   link_object_event_types_user_subcriptions_list),
            sources=(Comment, ))

        menu_secondary.bind_links(
            links=(link_comment_add, ),
            sources=('comments:comments_for_document', 'comments:comment_add',
                     'comments:comment_delete', 'comments:comment_details',
                     'comments:comment_edit',
                     'comments:comment_multiple_delete'))

        menu_object.bind_links(links=(link_comment_delete, link_comment_edit),
                               sources=(Comment, ))

        registry.register(Comment)
예제 #9
0
    def ready(self):
        super(MOTDApp, self).ready()

        Message = self.get_model(model_name='Message')

        EventModelRegistry.register(model=Message)

        ModelCopy(model=Message, bind_link=True,
                  register_permission=True).add_fields(
                      field_names=('label', 'message', 'enabled',
                                   'start_datetime', 'end_datetime'), )

        ModelEventType.register(model=Message,
                                event_types=(event_message_edited, ))

        ModelPermission.register(
            model=Message,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_events_view, permission_message_delete,
                         permission_message_edit, permission_message_view))
        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Message)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=Message,
                     widget=TwoStateWidget)
        SourceColumn(attribute='start_datetime',
                     empty_value=_('None'),
                     include_label=True,
                     is_sortable=True,
                     source=Message)
        SourceColumn(attribute='end_datetime',
                     empty_value=_('None'),
                     include_label=True,
                     is_sortable=True,
                     source=Message)

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
        ),
                                   sources=(Message, ))

        menu_multi_item.bind_links(links=(link_message_multiple_delete, ),
                                   sources=(Message, ))
        menu_object.bind_links(links=(link_message_single_delete,
                                      link_message_edit),
                               sources=(Message, ))
        menu_secondary.bind_links(links=(link_message_create, ),
                                  sources=(Message, 'motd:message_list',
                                           'motd:message_create'))
        menu_setup.bind_links(links=(link_message_list, ))
예제 #10
0
    def ready(self):
        super(FileCachingConfig, self).ready()
        from actstream import registry

        Cache = self.get_model(model_name='Cache')

        ModelEventType.register(
            event_types=(event_cache_edited, event_cache_purged,),
            model=Cache
        )

        ModelPermission.register(
            model=Cache, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_cache_purge, permission_cache_view
            )
        )

        SourceColumn(
            attribute='label', is_identifier=True, source=Cache
        )
        SourceColumn(
            attribute='get_maximum_size_display', include_label=True,
            is_sortable=True, sort_field='maximum_size', source=Cache
        )
        SourceColumn(
            attribute='get_total_size_display', include_label=True,
            source=Cache
        )

        menu_list_facet.bind_links(
            links=(
                link_acl_list, link_events_for_object,
                link_object_event_types_user_subcriptions_list,
            ), sources=(Cache,)
        )

        menu_object.bind_links(
            links=(link_cache_purge,),
            sources=(Cache,)
        )
        menu_multi_item.bind_links(
            links=(link_cache_multiple_purge,),
            sources=(Cache,)
        )
        menu_secondary.bind_links(
            links=(link_caches_list,), sources=(
                Cache,
            )
        )

        menu_tools.bind_links(links=(link_caches_list,))

        registry.register(Cache)
예제 #11
0
    def ready(self):
        super(AuthenticationApp, self).ready()

        User = get_user_model()

        menu_multi_item.bind_links(links=(link_user_multiple_set_password, ),
                                   sources=('user_management:user_list', ))

        menu_object.bind_links(links=(link_user_set_password, ),
                               sources=(User, ))

        menu_user.bind_links(links=(Separator(), link_password_change,
                                    link_logout),
                             position=99)
예제 #12
0
    def ready(self):
        super(PermissionsApp, self).ready()
        from actstream import registry

        Role = self.get_model('Role')
        Group = apps.get_model(app_label='auth', model_name='Group')

        Group.add_to_class(name='roles_add', value=method_group_roles_add)
        Group.add_to_class(name='roles_remove',
                           value=method_group_roles_remove)

        ModelEventType.register(event_types=(event_role_created,
                                             event_role_edited),
                                model=Role)

        ModelPermission.register(
            model=Role,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_events_view, permission_role_delete,
                         permission_role_edit, permission_role_view))

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Role)

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
            link_role_groups,
            link_role_permissions,
        ),
                                   sources=(Role, ))
        menu_list_facet.bind_links(links=(link_group_roles, ),
                                   sources=(Group, ))
        menu_object.bind_links(links=(link_role_delete, link_role_edit),
                               sources=(Role, ))
        menu_secondary.bind_links(links=(link_role_list, link_role_create),
                                  sources=(Role, 'permissions:role_create',
                                           'permissions:role_list'))
        menu_setup.bind_links(links=(link_role_list, ))

        perform_upgrade.connect(
            dispatch_uid='permissions_handler_purge_permissions',
            receiver=handler_purge_permissions)

        registry.register(Role)
예제 #13
0
    def ready(self):
        super(MOTDApp, self).ready()

        Message = self.get_model(model_name='Message')
        ModelPermission.register(
            model=Message, permissions=(
                permission_acl_edit, permission_acl_view,
                permission_message_delete, permission_message_edit,
                permission_message_view
            )
        )
        SourceColumn(
            attribute='label', is_identifier=True, is_sortable=True,
            source=Message
        )
        SourceColumn(
            attribute='enabled', include_label=True, is_sortable=True,
            source=Message, widget=TwoStateWidget
        )
        SourceColumn(
            attribute='start_datetime', empty_value=_('None'),
            include_label=True, is_sortable=True, source=Message
        )
        SourceColumn(
            attribute='end_datetime', empty_value=_('None'),
            include_label=True, is_sortable=True, source=Message
        )

        menu_list_facet.bind_links(
            links=(
                link_acl_list,
            ), sources=(Message,)
        )
        menu_object.bind_links(
            links=(
                link_message_delete, link_message_edit
            ), sources=(Message,)
        )
        menu_secondary.bind_links(
            links=(link_message_create,),
            sources=(Message, 'motd:message_list', 'motd:message_create')
        )
        menu_setup.bind_links(
            links=(link_message_list,)
        )
예제 #14
0
    def ready(self):
        super(TaskManagerApp, self).ready()

        CeleryQueue.initialize()

        SourceColumn(source=CeleryQueue, label=_('Label'), attribute='label')
        SourceColumn(source=CeleryQueue, label=_('Name'), attribute='name')
        SourceColumn(attribute='default_queue',
                     label=_('Default queue?'),
                     source=CeleryQueue,
                     widget=TwoStateWidget)
        SourceColumn(attribute='transient',
                     label=_('Is transient?'),
                     source=CeleryQueue,
                     widget=TwoStateWidget)
        SourceColumn(source=Task, label=_('Type'), attribute='task_type')
        SourceColumn(source=Task,
                     label=_('Start time'),
                     attribute='get_time_started')
        SourceColumn(source=Task,
                     label=_('Host'),
                     func=lambda context: context['object'].kwargs['hostname'])
        SourceColumn(source=Task,
                     label=_('Arguments'),
                     func=lambda context: context['object'].kwargs['args'])
        SourceColumn(source=Task,
                     label=_('Keyword arguments'),
                     func=lambda context: context['object'].kwargs['kwargs'])
        SourceColumn(
            source=Task,
            label=_('Worker process ID'),
            func=lambda context: context['object'].kwargs['worker_pid'])

        menu_object.bind_links(links=(
            link_queue_active_task_list,
            link_queue_scheduled_task_list,
            link_queue_reserved_task_list,
        ),
                               sources=(CeleryQueue, ))

        menu_secondary.bind_links(links=(link_queue_list, ),
                                  sources=(CeleryQueue, Task,
                                           'task_manager:queue_list'))

        menu_tools.bind_links(links=(link_task_manager, ))
예제 #15
0
파일: apps.py 프로젝트: stewart-lhc/mayan
    def ready(self):
        super(ConverterApp, self).ready()

        Transformation = self.get_model(model_name='Transformation')

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

        menu_object.bind_links(links=(link_transformation_edit,
                                      link_transformation_delete),
                               sources=(Transformation, ))
        menu_secondary.bind_links(links=(link_transformation_create, ),
                                  sources=(Transformation, ))
        menu_secondary.bind_links(links=(link_transformation_create, ),
                                  sources=('converter:transformation_create',
                                           'converter:transformation_list'))
예제 #16
0
파일: apps.py 프로젝트: stewart-lhc/mayan
    def ready(self):
        super(DjangoGPGApp, self).ready()

        Key = self.get_model(model_name='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(attribute='key_id', label=_('Key ID'), source=Key)
        SourceColumn(attribute='user_id', source=Key)

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

        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_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_secondary.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
            )
        )
        menu_setup.bind_links(links=(link_key_setup,))
예제 #17
0
    def ready(self):
        super(TagsApp, self).ready()
        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(model_name='DocumentTag')
        Tag = self.get_model(model_name='Tag')

        Document.add_to_class(name='get_tags', value=method_document_get_tags)

        EventModelRegistry.register(model=Tag)

        ModelCopy(model=Tag, bind_link=True,
                  register_permission=True).add_fields(field_names=(
                      'label',
                      'color',
                      'documents',
                  ), )

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

        ModelFieldRelated(model=Document, name='tags__label')
        ModelFieldRelated(model=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,
                                 ))

        model_query_fields_document = ModelQueryFields.get(model=Document)
        model_query_fields_document.add_prefetch_related_field(
            field_name='tags')

        model_query_fields_tag = ModelQueryFields.get(model=Tag)
        model_query_fields_tag.add_prefetch_related_field(
            field_name='documents')

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=DocumentTag)

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

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

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Tag)
        SourceColumn(attribute='get_preview_widget',
                     include_label=True,
                     source=Tag)
        source_column_tag_document_count = SourceColumn(
            func=lambda context: context['object'].get_document_count(
                user=context['request'].user),
            include_label=True,
            label=_('Documents'),
            source=Tag)
        source_column_tag_document_count.add_exclude(source=DocumentTag)

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

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
            link_tag_document_list,
        ),
                                   sources=(Tag, ))

        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_document_multiple_attach_multiple_tag,
                   link_document_multiple_tag_multiple_remove),
            sources=(Document, ))
        menu_multi_item.bind_links(links=(link_tag_multiple_delete, ),
                                   sources=(Tag, ))
        menu_object.bind_links(links=(link_tag_edit, link_tag_delete),
                               sources=(Tag, ))
        menu_secondary.bind_links(
            links=(link_document_tag_multiple_attach,
                   link_document_tag_multiple_remove),
            sources=('tags:tag_attach', 'tags:document_tag_list',
                     'tags:single_document_multiple_tag_remove'))

        # Index update

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

        pre_delete.connect(dispatch_uid='tags_handler_tag_pre_delete',
                           receiver=handler_tag_pre_delete,
                           sender=Tag)
예제 #18
0
    def ready(self):
        super(CabinetsApp, self).ready()
        from actstream import registry
        from .wizard_steps import WizardStepCabinets  # NOQA

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

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

        # Add explicit order_by as DocumentCabinet ordering Meta option has no
        # effect.
        Document.add_to_class(name='document_cabinets',
                              value=method_get_document_cabinets)

        ModelEventType.register(model=Cabinet,
                                event_types=(event_cabinet_edited,
                                             event_cabinet_add_document,
                                             event_cabinet_remove_document))

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

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

        def get_root_filter():
            return {
                'acl_filter': {
                    'level': 0
                },
                'acl_values': ('tree_id', ),
                'field_lookup': 'tree_id__in'
            }

        ModelPermission.register_function(model=Cabinet,
                                          function=get_root_filter)

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Cabinet)

        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_list_facet.bind_links(links=(
            link_cabinet_view,
            link_custom_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
        ),
                                   sources=(Cabinet, ))

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

        menu_multi_item.bind_links(
            links=(link_document_multiple_cabinet_add,
                   link_multiple_document_cabinet_remove),
            sources=(Document, ))
        menu_object.bind_links(links=(link_cabinet_view, ),
                               sources=(DocumentCabinet, ))
        menu_object.bind_links(links=(link_cabinet_delete, link_cabinet_edit,
                                      link_cabinet_child_add),
                               sources=(Cabinet, ))
        menu_object.unbind_links(links=(link_cabinet_delete, link_cabinet_edit,
                                        link_cabinet_child_add),
                                 sources=(DocumentCabinet, ))
        menu_secondary.bind_links(links=(link_document_cabinet_add,
                                         link_document_cabinet_remove),
                                  sources=('cabinets:document_cabinet_list',
                                           'cabinets:document_cabinet_add',
                                           'cabinets:document_cabinet_remove'))

        registry.register(Cabinet)
예제 #19
0
    def ready(self):
        super(MailerApp, self).ready()

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

        UserMailer = self.get_model(model_name='UserMailer')

        error_log = ErrorLog(app_config=self)
        error_log.register_model(model=UserMailer, register_permission=True)

        EventModelRegistry.register(model=UserMailer)

        MailerBackend.load_modules()

        ModelCopy(model=UserMailer, bind_link=True,
                  register_permission=True).add_fields(
                      field_names=('label', 'enabled', 'backend_path',
                                   'backend_data'),
                      field_values={'default': False})

        ModelEventType.register(model=UserMailer,
                                event_types=(event_email_sent, ))

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=UserMailer)
        SourceColumn(attribute='default',
                     include_label=True,
                     is_sortable=True,
                     source=UserMailer,
                     widget=TwoStateWidget)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=UserMailer,
                     widget=TwoStateWidget)
        SourceColumn(attribute='backend_label',
                     include_label=True,
                     source=UserMailer)

        ModelPermission.register(
            model=Document,
            permissions=(permission_mailing_link,
                         permission_mailing_send_document))

        ModelPermission.register(model=UserMailer,
                                 permissions=(permission_acl_edit,
                                              permission_acl_view,
                                              permission_user_mailer_delete,
                                              permission_user_mailer_edit,
                                              permission_user_mailer_view,
                                              permission_user_mailer_use))

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
        ),
                                   sources=(UserMailer, ))

        menu_multi_item.bind_links(links=(link_send_multiple_document,
                                          link_send_multiple_document_link),
                                   sources=(Document, ))

        menu_object.bind_links(links=(link_send_document_link,
                                      link_send_document),
                               sources=(Document, ))

        menu_object.bind_links(links=(link_user_mailer_delete,
                                      link_user_mailer_edit,
                                      link_user_mailer_test),
                               sources=(UserMailer, ))

        menu_secondary.bind_links(links=(
            link_user_mailer_list,
            link_user_mailer_create,
        ),
                                  sources=(UserMailer,
                                           'mailer:user_mailer_list',
                                           'mailer:user_mailer_create'))

        menu_setup.bind_links(links=(link_user_mailer_setup, ))
예제 #20
0
파일: apps.py 프로젝트: Charsly/Mayan-EDMS
    def ready(self):
        super(EventsApp, self).ready()
        Action = apps.get_model(app_label='actstream', model_name='Action')
        Notification = self.get_model(model_name='Notification')
        StoredEventType = self.get_model(model_name='StoredEventType')

        # Add labels to Action model, they are not marked translatable in the
        # upstream package.
        SourceColumn(attribute='timestamp',
                     is_identifier=True,
                     is_sortable=True,
                     label=_('Date and time'),
                     source=Action)
        SourceColumn(func=widget_event_actor_link,
                     label=_('Actor'),
                     source=Action)
        SourceColumn(func=widget_event_type_link,
                     label=_('Event'),
                     source=Action)
        SourceColumn(attribute='target',
                     label=_('Target'),
                     source=Action,
                     widget=ObjectLinkWidget)
        SourceColumn(attribute='action_object',
                     label=_('Action object'),
                     source=Action,
                     widget=ObjectLinkWidget)

        SourceColumn(source=StoredEventType,
                     label=_('Namespace'),
                     attribute='namespace')
        SourceColumn(source=StoredEventType,
                     label=_('Label'),
                     attribute='label')

        SourceColumn(attribute='action__timestamp',
                     is_identifier=True,
                     is_sortable=True,
                     label=_('Date and time'),
                     source=Notification)
        SourceColumn(func=widget_event_actor_link,
                     label=_('Actor'),
                     kwargs={'attribute': 'action'},
                     source=Notification)
        SourceColumn(func=widget_event_type_link,
                     label=_('Event'),
                     kwargs={'attribute': 'action'},
                     source=Notification)
        SourceColumn(attribute='action.target',
                     label=_('Target'),
                     source=Notification,
                     widget=ObjectLinkWidget)

        SourceColumn(attribute='read',
                     is_sortable=True,
                     label=_('Seen'),
                     source=Notification,
                     widget=TwoStateWidget)

        menu_main.bind_links(links=(link_user_notifications_list, ),
                             position=99)
        menu_object.bind_links(links=(link_notification_mark_read, ),
                               sources=(Notification, ))
        menu_secondary.bind_links(links=(link_notification_mark_read_all, ),
                                  sources=('events:user_notifications_list', ))
        menu_tools.bind_links(links=(link_events_list, ))
        menu_user.bind_links(links=(link_event_types_subscriptions_list,
                                    link_current_user_events),
                             position=50)
예제 #21
0
    def ready(self):
        super(DocumentIndexingApp, self).ready()
        from actstream import registry

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

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

        DocumentIndexInstanceNode = self.get_model(
            model_name='DocumentIndexInstanceNode')

        Index = self.get_model(model_name='Index')
        IndexInstance = self.get_model(model_name='IndexInstance')
        IndexInstanceNode = self.get_model(model_name='IndexInstanceNode')
        IndexTemplateNode = self.get_model(model_name='IndexTemplateNode')

        ModelEventType.register(event_types=(event_index_template_created,
                                             event_index_template_edited),
                                model=Index)

        ModelPermission.register(
            model=Index,
            permissions=(
                permission_acl_edit,
                permission_acl_view,
                permission_document_indexing_delete,
                permission_document_indexing_edit,
                permission_document_indexing_instance_view,
                permission_document_indexing_rebuild,
                permission_document_indexing_view,
            ))
        ModelPermission.register_inheritance(model=IndexTemplateNode,
                                             related='index')

        ModelPermission.register_inheritance(
            model=IndexInstanceNode, related='index_template_node__index')

        column_index_label = SourceColumn(attribute='label',
                                          is_identifier=True,
                                          is_sortable=True,
                                          source=Index)
        column_index_label.add_exclude(source=IndexInstance)
        SourceColumn(attribute='label',
                     is_object_absolute_url=True,
                     is_identifier=True,
                     is_sortable=True,
                     source=IndexInstance)
        column_index_slug = SourceColumn(attribute='slug',
                                         is_sortable=True,
                                         source=Index)
        column_index_slug.add_exclude(IndexInstance)
        column_index_enabled = SourceColumn(attribute='enabled',
                                            is_sortable=True,
                                            source=Index,
                                            widget=TwoStateWidget)
        column_index_enabled.add_exclude(source=IndexInstance)

        SourceColumn(func=lambda context: context['object'].instance_root.
                     get_descendants_count(),
                     label=_('Total levels'),
                     source=IndexInstance)
        SourceColumn(
            func=lambda context: context['object'].instance_root.
            get_descendants_document_count(user=context['request'].user),
            label=_('Total documents'),
            source=IndexInstance)

        SourceColumn(func=lambda context: node_level(context['object']),
                     label=_('Level'),
                     source=IndexTemplateNode)
        SourceColumn(attribute='enabled',
                     is_sortable=True,
                     source=IndexTemplateNode,
                     widget=TwoStateWidget)
        SourceColumn(attribute='link_documents',
                     is_sortable=True,
                     source=IndexTemplateNode,
                     widget=TwoStateWidget)
        SourceColumn(
            func=lambda context: index_instance_item_link(context['object']),
            label=_('Level'),
            is_sortable=True,
            sort_field='value',
            source=IndexInstanceNode)
        SourceColumn(
            func=lambda context: context['object'].get_descendants_count(),
            label=_('Levels'),
            source=IndexInstanceNode)

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

        SourceColumn(func=lambda context: get_instance_link(
            index_instance_node=context['object'], ),
                     label=_('Level'),
                     is_sortable=True,
                     sort_field='value',
                     source=DocumentIndexInstanceNode)
        SourceColumn(
            func=lambda context: context['object'].get_descendants_count(),
            label=_('Levels'),
            source=DocumentIndexInstanceNode)
        SourceColumn(
            func=lambda context: context['object'].
            get_descendants_document_count(user=context['request'].user),
            label=_('Documents'),
            source=DocumentIndexInstanceNode)

        menu_facet.bind_links(links=(link_document_index_instance_list, ),
                              sources=(Document, ))
        menu_list_facet.bind_links(
            links=(link_document_type_index_templates, ),
            sources=(DocumentType, ))
        menu_list_facet.bind_links(
            links=(link_acl_list, link_events_for_object,
                   link_index_template_document_types,
                   link_index_template_node_tree_view,
                   link_object_event_types_user_subcriptions_list),
            sources=(Index, ))
        menu_object.bind_links(links=(link_index_template_delete,
                                      link_index_template_edit,
                                      link_index_instance_rebuild),
                               sources=(Index, ))
        menu_object.bind_links(links=(link_index_template_node_create,
                                      link_index_template_node_edit,
                                      link_index_template_node_delete),
                               sources=(IndexTemplateNode, ))
        menu_main.bind_links(links=(link_index_instance_menu, ), position=98)
        menu_secondary.bind_links(links=(link_index_template_list,
                                         link_index_template_create),
                                  sources=(Index, 'indexing:index_setup_list',
                                           'indexing:index_setup_create'))
        menu_setup.bind_links(links=(link_index_template_setup, ))
        menu_tools.bind_links(links=(link_index_instances_rebuild,
                                     link_index_instances_reset))

        post_delete.connect(
            dispatch_uid='document_indexing_handler_delete_empty',
            receiver=handler_delete_empty,
            sender=Document)
        post_document_created.connect(
            dispatch_uid='document_indexing_handler_index_document',
            receiver=handler_index_document,
            sender=Document)
        post_initial_document_type.connect(
            dispatch_uid=
            'document_indexing_handler_create_default_document_index',
            receiver=handler_create_default_document_index,
            sender=DocumentType)
        post_save.connect(
            dispatch_uid='document_indexing_handler_post_save_index_document',
            receiver=handler_post_save_index_document,
            sender=Document)
        pre_delete.connect(
            dispatch_uid='document_indexing_handler_remove_document',
            receiver=handler_remove_document,
            sender=Document)

        registry.register(Index)
예제 #22
0
    def ready(self):
        super(UserManagementApp, self).ready()
        from actstream import registry

        Group = apps.get_model(app_label='auth', model_name='Group')
        User = get_user_model()

        DynamicSerializerField.add_serializer(
            klass=get_user_model(),
            serializer_class=
            'mayan.apps.user_management.serializers.UserSerializer')

        # Silence UnorderedObjectListWarning
        # "Pagination may yield inconsistent result"
        # TODO: Remove on Django 2.x
        Group._meta.ordering = ('name', )
        Group._meta.verbose_name = _('Group')
        Group._meta.verbose_name_plural = _('Groups')
        Group._meta.get_field('name').verbose_name = _('Name')

        # Silence UnorderedObjectListWarning
        # "Pagination may yield inconsistent result"
        # TODO: Remove on Django 2.x
        User._meta.ordering = ('pk', )
        User._meta.verbose_name = _('User')
        User._meta.verbose_name_plural = _('Users')
        User._meta.ordering = ('last_name', 'first_name')

        User._meta.get_field('username').verbose_name = _('Username')
        User._meta.get_field('first_name').verbose_name = _('First name')
        User._meta.get_field('last_name').verbose_name = _('Last name')
        User._meta.get_field('email').verbose_name = _('Email')
        User._meta.get_field('is_active').verbose_name = _('Is active?')
        if six.PY3:
            User.has_usable_password.short_description = _(
                'Has usable password?')
        else:
            User.has_usable_password.__func__.short_description = _(
                'Has usable password?')

        Group.add_to_class(name='get_users', value=method_group_get_users)
        Group.add_to_class(name='users_add', value=method_group_users_add)
        Group.add_to_class(name='users_remove',
                           value=method_group_users_remove)
        Group.add_to_class(name='save', value=get_method_group_save())

        MetadataLookup(description=_('All the groups.'),
                       name='groups',
                       value=get_groups)
        MetadataLookup(description=_('All the users.'),
                       name='users',
                       value=get_users)

        ModelEventType.register(event_types=(event_group_created,
                                             event_group_edited),
                                model=Group)

        ModelEventType.register(event_types=(event_user_created,
                                             event_user_edited),
                                model=User)

        ModelPermission.register(model=Group,
                                 permissions=(
                                     permission_acl_edit,
                                     permission_acl_view,
                                     permission_events_view,
                                     permission_group_delete,
                                     permission_group_edit,
                                     permission_group_view,
                                 ))
        ModelPermission.register(
            model=User,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_events_view, permission_user_delete,
                         permission_user_edit, permission_user_view))

        SourceColumn(attribute='name',
                     is_identifier=True,
                     is_sortable=True,
                     source=Group)
        SourceColumn(attribute='user_set.count',
                     label=_('Users'),
                     source=Group)

        SourceColumn(attribute='username',
                     is_object_absolute_url=True,
                     is_identifier=True,
                     is_sortable=True,
                     source=User)
        SourceColumn(attribute='first_name', is_sortable=True, source=User)
        SourceColumn(attribute='last_name', is_sortable=True, source=User)
        SourceColumn(attribute='email', is_sortable=True, source=User)
        SourceColumn(attribute='is_active',
                     is_sortable=True,
                     source=User,
                     widget=TwoStateWidget)
        SourceColumn(attribute='has_usable_password',
                     source=User,
                     widget=TwoStateWidget)

        User.add_to_class(name='get_absolute_url',
                          value=method_user_get_absolute_url)
        User.add_to_class(name='get_groups', value=method_user_get_groups)
        User.add_to_class(name='groups_add', value=method_user_groups_add)
        User.add_to_class(name='groups_remove',
                          value=method_user_groups_remove)
        User.add_to_class(name='save', value=get_method_user_save())

        dashboard_main.add_widget(widget=DashboardWidgetUserTotal, order=99)
        dashboard_main.add_widget(widget=DashboardWidgetGroupTotal, order=99)

        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_object_event_types_user_subcriptions_list,
            link_group_user_list,
        ),
                                   sources=(Group, ))
        menu_list_facet.bind_links(
            links=(link_acl_list, link_events_for_object,
                   link_object_event_types_user_subcriptions_list,
                   link_user_group_list, link_user_set_options),
            sources=(User, ))
        menu_multi_item.bind_links(links=(link_user_multiple_delete, ),
                                   sources=('user_management:user_list', ))
        menu_object.bind_links(links=(link_group_edit, ), sources=(Group, ))
        menu_object.bind_links(links=(link_group_delete, ),
                               position=99,
                               sources=(Group, ))
        menu_object.bind_links(links=(
            link_user_delete,
            link_user_edit,
        ),
                               sources=(User, ))
        menu_secondary.bind_links(
            links=(link_group_list, link_group_create),
            sources=('user_management:group_multiple_delete',
                     'user_management:group_list',
                     'user_management:group_create', Group))
        menu_secondary.bind_links(
            links=(link_user_list, link_user_create),
            sources=(User, 'authentication:user_multiple_set_password',
                     'user_management:user_multiple_delete',
                     'user_management:user_list',
                     'user_management:user_create'))
        menu_setup.bind_links(links=(link_user_setup, link_group_setup))
        menu_user.bind_links(links=(
            text_user_label,
            separator_user_label,
            link_current_user_details,
            link_current_user_edit,
        ),
                             position=0)

        post_save.connect(
            dispatch_uid='user_management_handler_initialize_new_user_options',
            receiver=handler_initialize_new_user_options,
            sender=User)

        user_logged_in.connect(
            dispatch_uid='user_management_handler_user_logged_in',
            receiver=handler_user_logged_in,
            sender=User)
        user_logged_out.connect(
            dispatch_uid='user_management_handler_user_logged_out',
            receiver=handler_user_logged_out,
            sender=User)

        registry.register(Group)
        registry.register(User)
예제 #23
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')

        DetachedSignature = self.get_model(model_name='DetachedSignature')
        EmbeddedSignature = self.get_model(model_name='EmbeddedSignature')

        SignatureBaseModel = self.get_model(model_name='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,
            ))
        ModelPermission.register_inheritance(model=SignatureBaseModel,
                                             related='document_version')
        ModelPermission.register_inheritance(model=DetachedSignature,
                                             related='document_version')

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

        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_secondary.bind_links(
            links=(link_document_version_signature_upload, ),
            sources=(DocumentVersion, ))
        menu_tools.bind_links(
            links=(link_document_version_all_signature_verify, ))

        post_delete.connect(
            dispatch_uid='signatures_handler_unverify_key_signatures',
            receiver=handler_unverify_key_signatures,
            sender=Key)
        post_save.connect(
            dispatch_uid='signatures_handler_verify_key_signatures',
            receiver=handler_verify_key_signatures,
            sender=Key)
예제 #24
0
    def ready(self):
        super(DocumentsApp, self).ready()
        from actstream import registry

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

        DynamicSerializerField.add_serializer(
            klass=Document,
            serializer_class=
            'mayan.apps.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')

        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_changed,
                                             event_document_version_new,
                                             event_document_version_revert,
                                             event_document_view))

        ModelField(model=Document, name='description')
        ModelField(model=Document, name='date_added')
        ModelField(model=Document, name='deleted_date_time')
        ModelField(model=Document, name='document_type')
        ModelField(model=Document, name='in_trash')
        ModelField(model=Document, name='is_stub')
        ModelField(model=Document, name='label')
        ModelField(model=Document, name='language')
        ModelField(model=Document, name='uuid')

        ModelFieldRelated(model=Document, name='document_type__label')
        ModelFieldRelated(model=Document, name='versions__checksum')
        ModelFieldRelated(model=Document,
                          label=_('Versions comment'),
                          name='versions__comment')
        ModelFieldRelated(model=Document,
                          label=_('Versions encoding'),
                          name='versions__encoding')
        ModelFieldRelated(model=Document,
                          label=_('Versions mime type'),
                          name='versions__mimetype')
        ModelFieldRelated(model=Document,
                          label=_('Versions timestamp'),
                          name='versions__timestamp')

        ModelProperty(
            description=_('Return the lastest version of the document.'),
            model=Document,
            label=_('Latest version'),
            name='latest_version')

        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_tools,
                                     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,
                                     permission_acl_edit,
                                     permission_acl_view,
                                     permission_events_view,
                                 ))

        ModelPermission.register_inheritance(
            model=Document,
            related='document_type',
        )
        ModelPermission.register_manager(model=Document,
                                         manager_name='passthrough')
        ModelPermission.register_inheritance(
            model=DocumentPage,
            related='document_version__document',
        )
        ModelPermission.register_manager(model=DocumentPage,
                                         manager_name='passthrough')
        ModelPermission.register_inheritance(
            model=DocumentPageResult,
            related='document_version__document',
        )
        ModelPermission.register_manager(model=DocumentPageResult,
                                         manager_name='passthrough')
        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(attribute='label',
                     is_object_absolute_url=True,
                     is_identifier=True,
                     is_sortable=True,
                     source=Document)
        SourceColumn(func=lambda context: document_page_thumbnail_widget.
                     render(instance=context['object']),
                     html_extra_classes='text-center document-thumbnail-list',
                     label=_('Thumbnail'),
                     source=Document)
        SourceColumn(
            attribute='document_type',
            is_sortable=True,
            source=Document,
        )
        SourceColumn(func=lambda context: widget_document_page_number(
            document=context['object']),
                     label=_('Pages'),
                     source=Document)
        SourceColumn(attribute='date_added',
                     include_label=True,
                     is_sortable=True,
                     source=Document,
                     views=('documents:document_list_recent_added', ))
        SourceColumn(func=lambda context: DuplicatedDocument.objects.get(
            document=context['object']).documents.count(),
                     include_label=True,
                     label=_('Duplicates'),
                     source=Document,
                     views=('documents:duplicated_document_list', ))

        # DocumentPage
        SourceColumn(attribute='get_label',
                     is_identifier=True,
                     is_object_absolute_url=True,
                     source=DocumentPage,
                     widget_condition=is_document_page_enabled)
        SourceColumn(func=lambda context: document_page_thumbnail_widget.
                     render(instance=context['object']),
                     html_extra_classes='text-center document-thumbnail-list',
                     label=_('Thumbnail'),
                     source=DocumentPage)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     source=DocumentPage,
                     widget=TwoStateWidget)
        SourceColumn(attribute='page_number',
                     include_label=True,
                     source=DocumentPage)

        SourceColumn(attribute='get_label',
                     is_identifier=True,
                     is_object_absolute_url=True,
                     source=DocumentPageResult)
        SourceColumn(func=lambda context: document_page_thumbnail_widget.
                     render(instance=context['object']),
                     html_extra_classes='text-center document-thumbnail-list',
                     label=_('Thumbnail'),
                     source=DocumentPageResult)
        SourceColumn(attribute='document_version.document.document_type',
                     label=_('Type'),
                     source=DocumentPageResult)

        # DocumentType
        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=DocumentType)

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

        SourceColumn(attribute='filename',
                     is_identifier=True,
                     is_sortable=True,
                     source=DocumentTypeFilename)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=DocumentTypeFilename,
                     widget=TwoStateWidget)

        # DeletedDocument
        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=DeletedDocument)
        SourceColumn(attribute='deleted_date_time',
                     include_label=True,
                     order=99,
                     source=DeletedDocument)

        # DocumentVersion
        SourceColumn(source=DocumentVersion,
                     attribute='timestamp',
                     is_identifier=True,
                     is_object_absolute_url=True)
        SourceColumn(func=lambda context: document_page_thumbnail_widget.
                     render(instance=context['object']),
                     html_extra_classes='text-center document-thumbnail-list',
                     label=_('Thumbnail'),
                     source=DocumentVersion)
        SourceColumn(func=lambda context: widget_document_version_page_number(
            document_version=context['object']),
                     label=_('Pages'),
                     source=DocumentVersion)
        SourceColumn(attribute='mimetype',
                     is_sortable=True,
                     source=DocumentVersion)
        SourceColumn(attribute='encoding',
                     is_sortable=True,
                     source=DocumentVersion)
        SourceColumn(attribute='comment',
                     is_sortable=True,
                     source=DocumentVersion)

        Template(name='invalid_document',
                 template_name='documents/invalid_document.html')

        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_duplicated_document_scan, ))

        # Document type links
        menu_list_facet.bind_links(links=(
            link_document_type_filename_list,
            link_document_type_policies,
            link_acl_list,
            link_object_event_types_user_subcriptions_list,
            link_events_for_object,
        ),
                                   sources=(DocumentType, ))

        menu_object.bind_links(links=(link_document_type_delete,
                                      link_document_type_edit),
                               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_secondary.bind_links(
            links=(link_document_type_filename_create, ),
            sources=(DocumentTypeFilename,
                     'documents:document_type_filename_list',
                     'documents:document_type_filename_create'))
        menu_secondary.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_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),
                              sources=(DocumentPage, ))
        menu_list_facet.bind_links(links=(link_transformation_list, ),
                                   sources=(DocumentPage, ))
        menu_multi_item.bind_links(links=(link_document_page_multiple_disable,
                                          link_document_page_multiple_enable),
                                   sources=(DocumentPage, ))
        menu_object.bind_links(links=(link_document_page_disable,
                                      link_document_page_enable),
                               sources=(DocumentPage, ))
        menu_secondary.bind_links(links=(link_document_page_return, ),
                                  sources=(DocumentPage, ))

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

        post_delete.connect(
            dispatch_uid='documents_handler_remove_empty_duplicates_lists',
            receiver=handler_remove_empty_duplicates_lists,
            sender=Document)
        post_initial_setup.connect(
            dispatch_uid='documents_handler_create_default_document_type',
            receiver=handler_create_default_document_type)
        post_migrate.connect(
            dispatch_uid='documents_handler_create_document_cache',
            receiver=handler_create_document_cache,
        )
        post_version_upload.connect(
            dispatch_uid='documents_handler_scan_duplicates_for',
            receiver=handler_scan_duplicates_for)

        registry.register(DeletedDocument)
        registry.register(Document)
        registry.register(DocumentType)
        registry.register(DocumentVersion)
예제 #25
0
    def ready(self):
        super(DocumentCommentsApp, self).ready()

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

        Comment = self.get_model(model_name='Comment')

        EventModelRegistry.register(model=Comment)

        ModelEventType.register(
            model=Comment, event_types=(
                event_document_comment_edited,
            )
        )
        ModelEventType.register(
            model=Document, event_types=(
                event_document_comment_created, event_document_comment_deleted,
                event_document_comment_edited
            )
        )

        ModelPermission.register(
            model=Comment, permissions=(permission_events_view,)
        )
        ModelPermission.register_inheritance(
            model=Comment, related='document',
        )
        ModelPermission.register(
            model=Document, permissions=(
                permission_document_comment_create,
                permission_document_comment_delete,
                permission_document_comment_edit,
                permission_document_comment_view
            )
        )

        SourceColumn(
            attribute='submit_date', is_identifier=True, source=Comment
        )
        SourceColumn(
            attribute='get_user_label', include_label=True, source=Comment
        )
        SourceColumn(attribute='comment', include_label=True, source=Comment)

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

        menu_list_facet.bind_links(
            links=(
                link_events_for_object,
                link_object_event_types_user_subcriptions_list
            ), sources=(Comment,)
        )

        menu_secondary.bind_links(
            links=(link_comment_add,),
            sources=(
                'comments:comments_for_document', 'comments:comment_add',
                'comments:comment_delete', 'comments:comment_details',
                'comments:comment_edit', 'comments:comment_multiple_delete'
            )
        )

        menu_object.bind_links(
            links=(link_comment_delete, link_comment_edit), sources=(Comment,)
        )
예제 #26
0
    def ready(self):
        super(MetadataApp, self).ready()
        from actstream import registry

        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(model_name='DocumentMetadata')
        DocumentTypeMetadataType = self.get_model(
            model_name='DocumentTypeMetadataType')
        MetadataType = self.get_model(model_name='MetadataType')

        Document.add_to_class(name='metadata_value_of',
                              value=DocumentMetadataHelper.constructor)

        ModelAttribute(
            model=Document,
            name='metadata_value_of',
            description=_('Return the value of a specific document metadata'))

        ModelField(model=Document,
                   name='metadata__metadata_type__name',
                   label=_('Metadata type name'))
        ModelField(model=Document,
                   name='metadata__value',
                   label=_('Metadata type value'))

        ModelEventType.register(model=Document,
                                event_types=(
                                    event_document_metadata_added,
                                    event_document_metadata_edited,
                                    event_document_metadata_removed,
                                ))

        ModelEventType.register(model=MetadataType,
                                event_types=(
                                    event_document_metadata_added,
                                    event_document_metadata_edited,
                                    event_document_metadata_removed,
                                    event_metadata_type_edited,
                                    event_metadata_type_relationship,
                                ))

        ModelEventType.register(
            model=DocumentType,
            event_types=(event_metadata_type_relationship, ))

        ModelPermission.register(model=Document,
                                 permissions=(
                                     permission_document_metadata_add,
                                     permission_document_metadata_edit,
                                     permission_document_metadata_remove,
                                     permission_document_metadata_view,
                                 ))
        ModelPermission.register(model=MetadataType,
                                 permissions=(permission_acl_edit,
                                              permission_acl_view,
                                              permission_events_view,
                                              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(attribute='metadata_type',
                     is_identifier=True,
                     is_sortable=True,
                     source=DocumentMetadata)
        SourceColumn(attribute='value',
                     is_sortable=True,
                     source=DocumentMetadata)

        SourceColumn(attribute='is_required',
                     source=DocumentMetadata,
                     widget=TwoStateWidget)

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=MetadataType)
        SourceColumn(attribute='name', is_sortable=True, source=MetadataType)

        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_list_facet.bind_links(
            links=(link_setup_document_type_metadata_types, ),
            sources=(DocumentType, ))
        menu_multi_item.bind_links(links=(link_metadata_multiple_add,
                                          link_metadata_multiple_edit,
                                          link_metadata_multiple_remove),
                                   sources=(Document, ))
        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_setup_metadata_type_document_types,
            link_object_event_types_user_subcriptions_list,
            link_events_for_object,
        ),
                                   sources=(MetadataType, ))
        menu_object.bind_links(links=(link_setup_metadata_type_delete,
                                      link_setup_metadata_type_edit),
                               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_secondary.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(
            dispatch_uid=
            'metadata_handler_post_document_type_metadata_type_delete',
            receiver=handler_post_document_type_metadata_type_delete,
            sender=DocumentTypeMetadataType)
        post_document_type_change.connect(
            dispatch_uid='metadata_handler_post_document_type_change_metadata',
            receiver=handler_post_document_type_change_metadata,
            sender=Document)
        post_save.connect(
            dispatch_uid=
            'metadata_handler_post_document_type_metadata_type_add',
            receiver=handler_post_document_type_metadata_type_add,
            sender=DocumentTypeMetadataType)

        # Index updating

        post_delete.connect(
            dispatch_uid='metadata_handler_index_document_delete',
            receiver=handler_index_document,
            sender=DocumentMetadata)
        post_save.connect(dispatch_uid='metadata_handler_index_document_save',
                          receiver=handler_index_document,
                          sender=DocumentMetadata)

        registry.register(MetadataType)
        registry.register(DocumentTypeMetadataType)
예제 #27
0
    def ready(self):
        super(MailerApp, self).ready()
        from actstream import registry

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

        LogEntry = self.get_model(model_name='LogEntry')
        UserMailer = self.get_model(model_name='UserMailer')
        UserMailerLogEntry = self.get_model(model_name='UserMailerLogEntry')

        MailerBackend.initialize()

        ModelEventType.register(model=UserMailer,
                                event_types=(event_email_sent, ))

        SourceColumn(source=LogEntry,
                     label=_('Date and time'),
                     attribute='datetime')
        SourceColumn(source=LogEntry, label=_('Message'), attribute='message')
        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=UserMailer)
        SourceColumn(attribute='default',
                     include_label=True,
                     is_sortable=True,
                     source=UserMailer,
                     widget=TwoStateWidget)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=UserMailer,
                     widget=TwoStateWidget)
        SourceColumn(attribute='backend_label',
                     include_label=True,
                     source=UserMailer)
        SourceColumn(attribute='datetime',
                     label=_('Date and time'),
                     source=UserMailerLogEntry)
        SourceColumn(attribute='message',
                     label=_('Message'),
                     source=UserMailerLogEntry)

        ModelPermission.register(
            model=Document,
            permissions=(permission_mailing_link,
                         permission_mailing_send_document))

        ModelPermission.register(model=UserMailer,
                                 permissions=(permission_acl_edit,
                                              permission_acl_view,
                                              permission_user_mailer_delete,
                                              permission_user_mailer_edit,
                                              permission_user_mailer_view,
                                              permission_user_mailer_use))

        menu_list_facet.bind_links(
            links=(link_acl_list, link_events_for_object,
                   link_object_event_types_user_subcriptions_list,
                   link_user_mailer_log_list),
            sources=(UserMailer, ))

        menu_multi_item.bind_links(links=(link_send_multiple_document,
                                          link_send_multiple_document_link),
                                   sources=(Document, ))

        menu_object.bind_links(links=(link_send_document_link,
                                      link_send_document),
                               sources=(Document, ))

        menu_object.bind_links(links=(link_user_mailer_delete,
                                      link_user_mailer_edit,
                                      link_user_mailer_test),
                               sources=(UserMailer, ))

        menu_secondary.bind_links(links=(
            link_user_mailer_list,
            link_user_mailer_create,
        ),
                                  sources=(UserMailer,
                                           'mailer:user_mailer_list',
                                           'mailer:user_mailer_create'))

        menu_tools.bind_links(links=(link_system_mailer_error_log, ))

        menu_setup.bind_links(links=(link_user_mailer_setup, ))

        registry.register(UserMailer)
예제 #28
0
    def ready(self):
        super(WebLinksApp, self).ready()

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

        ResolvedWebLink = self.get_model(model_name='ResolvedWebLink')
        WebLink = self.get_model(model_name='WebLink')

        EventModelRegistry.register(model=ResolvedWebLink)
        EventModelRegistry.register(model=WebLink)

        ModelEventType.register(event_types=(event_web_link_edited, ),
                                model=WebLink)

        ModelPermission.register(
            model=Document, permissions=(permission_web_link_instance_view, ))
        ModelPermission.register(
            model=DocumentType,
            permissions=(permission_web_link_instance_view, ))
        ModelPermission.register(
            model=WebLink,
            permissions=(permission_acl_edit, permission_acl_view,
                         permission_web_link_delete, permission_web_link_edit,
                         permission_web_link_instance_view,
                         permission_web_link_view))

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=ResolvedWebLink)
        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=WebLink)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=WebLink,
                     widget=TwoStateWidget)

        menu_facet.bind_links(links=(link_document_web_link_list, ),
                              sources=(Document, ))
        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_web_link_document_types,
            link_object_event_types_user_subcriptions_list,
        ),
                                   sources=(WebLink, ))
        menu_list_facet.bind_links(links=(link_document_type_web_links, ),
                                   sources=(DocumentType, ))
        menu_object.bind_links(links=(link_web_link_delete,
                                      link_web_link_edit),
                               sources=(WebLink, ))
        menu_object.bind_links(links=(link_web_link_instance_view, ),
                               sources=(ResolvedWebLink, ))
        menu_object.unbind_links(links=(link_web_link_delete,
                                        link_web_link_edit),
                                 sources=(ResolvedWebLink, ))
        menu_secondary.bind_links(links=(link_web_link_list,
                                         link_web_link_create),
                                  sources=(WebLink, 'web_links:web_link_list',
                                           'web_links:web_link_create'))
        menu_setup.bind_links(links=(link_web_link_setup, ))
예제 #29
0
파일: apps.py 프로젝트: stewart-lhc/mayan
    def ready(self):
        super(LinkingApp, self).ready()
        from actstream import registry

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

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

        ModelEventType.register(event_types=(event_smart_link_edited, ),
                                model=SmartLink)

        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_label_for(
                         document=context['document']))

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=SmartLink)
        SourceColumn(attribute='dynamic_label',
                     is_sortable=True,
                     source=SmartLink)
        SourceColumn(attribute='enabled',
                     is_sortable=True,
                     source=SmartLink,
                     widget=TwoStateWidget)

        SourceColumn(attribute='get_full_label',
                     is_identifier=True,
                     source=SmartLinkCondition)
        SourceColumn(attribute='enabled',
                     is_sortable=True,
                     source=SmartLinkCondition,
                     widget=TwoStateWidget)

        menu_facet.bind_links(links=(link_smart_link_instances_for_document, ),
                              sources=(Document, ))
        menu_list_facet.bind_links(links=(
            link_acl_list,
            link_events_for_object,
            link_smart_link_document_types,
            link_object_event_types_user_subcriptions_list,
            link_smart_link_condition_list,
        ),
                                   sources=(SmartLink, ))
        menu_list_facet.bind_links(links=(link_document_type_smart_links, ),
                                   sources=(DocumentType, ))
        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_delete,
                                      link_smart_link_edit),
                               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_secondary.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'))
        menu_setup.bind_links(links=(link_smart_link_setup, ))

        registry.register(SmartLink)
예제 #30
0
    def ready(self):
        super(DocumentStatesApp, self).ready()
        from actstream import registry

        Action = apps.get_model(app_label='actstream', model_name='Action')
        Document = apps.get_model(app_label='documents', model_name='Document')
        DocumentType = apps.get_model(app_label='documents',
                                      model_name='DocumentType')
        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')
        WorkflowTransitionField = self.get_model('WorkflowTransitionField')
        WorkflowTransitionTriggerEvent = self.get_model(
            'WorkflowTransitionTriggerEvent')

        Document.add_to_class(name='workflow',
                              value=DocumentStateHelper.constructor)

        ErrorLogEntry.objects.register(model=WorkflowStateAction)

        WorkflowAction.initialize()

        ModelProperty(
            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.'))
        ModelProperty(
            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.'))

        ModelEventType.register(event_types=(event_workflow_edited, ),
                                model=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_tools,
                         permission_workflow_transition,
                         permission_workflow_view))
        ModelPermission.register(
            model=WorkflowTransition,
            permissions=(permission_workflow_transition, ))

        ModelPermission.register_inheritance(
            model=WorkflowInstance,
            related='workflow',
        )
        ModelPermission.register_inheritance(
            model=WorkflowInstanceLogEntry,
            related='workflow_instance__workflow',
        )
        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=WorkflowTransitionField,
            related='transition',
        )
        ModelPermission.register_inheritance(
            model=WorkflowTransitionTriggerEvent,
            related='transition__workflow',
        )

        ModelField(model=WorkflowInstance, name='document')
        ModelField(model=WorkflowInstance, name='workflow')
        ModelReverseField(model=WorkflowInstance, name='log_entries')

        ModelProperty(description=_(
            'Return the last workflow instance log entry. The '
            'log entry itself has the following fields: datetime, '
            'transition, user, and comment.'),
                      label=_('Get last log entry'),
                      model=WorkflowInstance,
                      name='get_last_log_entry')

        ModelProperty(description=_(
            'Return the current context dictionary which includes '
            'runtime data from the workflow transition fields.'),
                      label=_('Get the context'),
                      model=WorkflowInstance,
                      name='get_runtime_context')

        ModelProperty(
            description=_('Return the transition of the workflow instance.'),
            label=_('Get last transition'),
            model=WorkflowInstance,
            name='get_last_transition')

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=Workflow)
        column_workflow_internal_name = SourceColumn(attribute='internal_name',
                                                     include_label=True,
                                                     is_sortable=True,
                                                     source=Workflow)
        column_workflow_internal_name.add_exclude(source=WorkflowRuntimeProxy)
        SourceColumn(attribute='get_initial_state',
                     empty_value=_('None'),
                     include_label=True,
                     source=Workflow)

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

        SourceColumn(attribute='datetime',
                     is_identifier=True,
                     label=_('Date and time'),
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='user',
                     include_label=True,
                     label=_('User'),
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='transition__origin_state',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='transition',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='transition__destination_state',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='comment',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowInstanceLogEntry)
        SourceColumn(attribute='get_extra_data',
                     include_label=True,
                     label=_('Additional details'),
                     source=WorkflowInstanceLogEntry,
                     widget=WorkflowLogExtraDataWidget)

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=WorkflowState)
        SourceColumn(attribute='initial',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowState,
                     widget=TwoStateWidget)
        SourceColumn(attribute='completion',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowState)

        SourceColumn(attribute='label',
                     is_identifier=True,
                     is_sortable=True,
                     source=WorkflowStateAction)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowStateAction,
                     widget=TwoStateWidget)
        SourceColumn(attribute='get_when_display',
                     include_label=True,
                     label=_('When?'),
                     source=WorkflowStateAction)
        SourceColumn(attribute='get_class_label',
                     include_label=True,
                     label=_('Action type'),
                     source=WorkflowStateAction)
        SourceColumn(attribute='has_condition',
                     include_label=True,
                     source=WorkflowStateAction,
                     widget=TwoStateWidget)

        SourceColumn(
            attribute='label',
            is_identifier=True,
            is_sortable=True,
            source=WorkflowTransition,
        )
        SourceColumn(attribute='origin_state',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowTransition)
        SourceColumn(attribute='destination_state',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowTransition)
        SourceColumn(attribute='has_condition',
                     include_label=True,
                     source=WorkflowTransition,
                     widget=TwoStateWidget)
        SourceColumn(
            func=lambda context: widget_transition_events(transition=context[
                'object']),
            help_text=_(
                'Triggers are system events that will cause the transition '
                'to be applied.'),
            include_label=True,
            label=_('Triggers'),
            source=WorkflowTransition)

        SourceColumn(attribute='name',
                     is_identifier=True,
                     is_sortable=True,
                     source=WorkflowTransitionField)
        SourceColumn(attribute='label',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowTransitionField)
        SourceColumn(attribute='get_field_type_display',
                     include_label=True,
                     label=_('Type'),
                     source=WorkflowTransitionField)
        SourceColumn(attribute='required',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowTransitionField,
                     widget=TwoStateWidget)
        SourceColumn(attribute='get_widget_display',
                     include_label=True,
                     label=_('Widget'),
                     is_sortable=False,
                     source=WorkflowTransitionField)
        SourceColumn(attribute='widget_kwargs',
                     include_label=True,
                     is_sortable=True,
                     source=WorkflowTransitionField)

        SourceColumn(func=lambda context: context['object'].get_document_count(
            user=context['request'].user),
                     include_label=True,
                     label=_('Documents'),
                     order=99,
                     source=WorkflowRuntimeProxy)
        SourceColumn(func=lambda context: context['object'].get_document_count(
            user=context['request'].user),
                     include_label=True,
                     label=_('Documents'),
                     order=99,
                     source=WorkflowStateRuntimeProxy)

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

        menu_list_facet.bind_links(
            links=(link_acl_list, link_events_for_object,
                   link_object_event_types_user_subcriptions_list,
                   link_workflow_template_document_types,
                   link_workflow_template_state_list,
                   link_workflow_template_transition_list,
                   link_workflow_template_preview),
            sources=(Workflow, ))

        menu_list_facet.unbind_links(
            links=(link_acl_list, link_events_for_object,
                   link_object_event_types_user_subcriptions_list,
                   link_workflow_template_document_types,
                   link_workflow_template_state_list,
                   link_workflow_template_transition_list,
                   link_workflow_template_preview),
            sources=(WorkflowRuntimeProxy, ))

        menu_list_facet.bind_links(
            links=(link_document_type_workflow_templates, ),
            sources=(DocumentType, ))

        menu_main.bind_links(links=(link_workflow_runtime_proxy_list, ),
                             position=10)
        menu_object.bind_links(links=(link_workflow_template_delete,
                                      link_workflow_template_edit,
                                      link_workflow_template_launch),
                               sources=(Workflow, ))
        menu_object.bind_links(links=(link_workflow_template_state_edit,
                                      link_workflow_template_state_action_list,
                                      link_workflow_template_state_delete),
                               sources=(WorkflowState, ))
        menu_object.bind_links(
            links=(link_workflow_template_transition_edit,
                   link_workflow_template_transition_events,
                   link_workflow_template_transition_field_list, link_acl_list,
                   link_workflow_template_transition_delete),
            sources=(WorkflowTransition, ))
        menu_object.bind_links(
            links=(link_workflow_template_transition_field_delete,
                   link_workflow_template_transition_field_edit),
            sources=(WorkflowTransitionField, ))
        menu_object.bind_links(links=(link_workflow_instance_detail,
                                      link_workflow_instance_transition),
                               sources=(WorkflowInstance, ))

        menu_list_facet.bind_links(links=(
            link_workflow_runtime_proxy_document_list,
            link_workflow_runtime_proxy_state_list,
        ),
                                   sources=(WorkflowRuntimeProxy, ))
        menu_list_facet.bind_links(
            links=(link_workflow_runtime_proxy_state_document_list, ),
            sources=(WorkflowStateRuntimeProxy, ))
        menu_object.bind_links(links=(
            link_workflow_template_state_action_edit,
            link_object_error_list,
            link_workflow_template_state_action_delete,
        ),
                               sources=(WorkflowStateAction, ))

        menu_secondary.bind_links(
            links=(link_workflow_template_list, link_workflow_template_create),
            sources=(Workflow, 'document_states:workflow_template_create',
                     'document_states:workflow_template_list'))
        menu_secondary.bind_links(
            links=(link_workflow_template_transition_field_create, ),
            sources=(WorkflowTransition, ))
        menu_secondary.bind_links(links=(link_workflow_runtime_proxy_list, ),
                                  sources=(WorkflowRuntimeProxy, ))
        menu_secondary.bind_links(
            links=(link_workflow_template_state_action_selection, ),
            sources=(WorkflowState, ))
        menu_secondary.bind_links(
            links=(link_workflow_template_transition_create, ),
            sources=(
                WorkflowTransition,
                'document_states:workflow_template_transition_create',
                'document_states:workflow_template_transition_list',
            ))
        menu_secondary.bind_links(
            links=(link_workflow_template_state_create, ),
            sources=(
                WorkflowState,
                'document_states:workflow_template_state_create',
                'document_states:workflow_template_state_list',
            ))

        menu_setup.bind_links(links=(link_workflow_template_list, ))

        menu_tools.bind_links(links=(link_tool_launch_workflows, ))

        post_save.connect(dispatch_uid='workflows_handler_launch_workflow',
                          receiver=handler_launch_workflow,
                          sender=Document)

        # Index updating

        post_migrate.connect(
            dispatch_uid='workflows_handler_create_workflow_image_cache',
            receiver=handler_create_workflow_image_cache,
        )
        post_save.connect(dispatch_uid='workflows_handler_index_document_save',
                          receiver=handler_index_document,
                          sender=WorkflowInstanceLogEntry)
        post_save.connect(dispatch_uid='workflows_handler_trigger_transition',
                          receiver=handler_trigger_transition,
                          sender=Action)

        registry.register(Workflow)