Exemplo n.º 1
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)
Exemplo n.º 2
0
    def ready(self):
        super(LinkingApp, self).ready()

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

        EventModelRegistry.register(model=SmartLink)

        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))
        ModelPermission.register_inheritance(
            model=SmartLinkCondition,
            related='smart_link',
        )

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

        source_column_smart_link_label = SourceColumn(attribute='label',
                                                      is_identifier=True,
                                                      is_sortable=True,
                                                      source=SmartLink)
        source_column_smart_link_label.add_exclude(ResolvedSmartLink)
        source_column_smart_link_dynamic_label = SourceColumn(
            attribute='dynamic_label',
            include_label=True,
            is_sortable=True,
            source=SmartLink)
        source_column_smart_link_dynamic_label.add_exclude(ResolvedSmartLink)
        source_column_smart_link_enabled = SourceColumn(attribute='enabled',
                                                        include_label=True,
                                                        is_sortable=True,
                                                        source=SmartLink,
                                                        widget=TwoStateWidget)
        source_column_smart_link_enabled.add_exclude(ResolvedSmartLink)
        SourceColumn(attribute='get_full_label',
                     is_identifier=True,
                     source=SmartLinkCondition)
        SourceColumn(attribute='enabled',
                     include_label=True,
                     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_object.unbind_links(links=(
            link_smart_link_delete,
            link_smart_link_edit,
        ),
                                 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, ))
Exemplo n.º 3
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, ))
Exemplo n.º 4
0
    def ready(self):
        super(CabinetsApp, self).ready()
        from .wizard_steps import WizardStepCabinets  # NOQA

        Cabinet = self.get_model(model_name='Cabinet')
        CabinetSearchResult = self.get_model(model_name='CabinetSearchResult')
        Document = apps.get_model(app_label='documents', model_name='Document')
        DocumentCabinet = self.get_model(model_name='DocumentCabinet')
        DocumentPageResult = apps.get_model(app_label='documents',
                                            model_name='DocumentPageResult')

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

        EventModelRegistry.register(model=Cabinet)

        def cabinet_model_copy_condition(instance):
            return instance.is_root_node()

        def cabinet_unique_conditional(instance, new_instance_dictionary):
            if instance.parent:
                return instance.parent_id == new_instance_dictionary[
                    'parent_id'] and instance.label == new_instance_dictionary[
                        'label']
            else:
                return not new_instance_dictionary[
                    'parent_id'] and instance.label == new_instance_dictionary[
                        'label']

        ModelCopy(model=Cabinet,
                  condition=cabinet_model_copy_condition,
                  bind_link=True,
                  register_permission=True).add_fields(
                      field_names=('label', 'documents'),
                      unique_conditional={'label': cabinet_unique_conditional})

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

        model_query_fields_document = ModelQueryFields(model=Document)
        model_query_fields_document.add_prefetch_related_field(
            field_name='cabinets')

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

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

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

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

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

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

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

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