<s> from __future__ import unicode_literals <EOL> import logging <EOL> from kombu import Exchange , Queue <EOL> from django . db . models . signals import post_delete , post_save <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from acls import ModelPermission <EOL> from common import ( <EOL> MayanAppConfig , menu_facet , menu_multi_item , menu_object , menu_secondary , <EOL> menu_setup , menu_sidebar <EOL> ) <EOL> from common . classes import ModelAttribute , Filter <EOL> from common . widgets import two_state_template <EOL> from documents . models import Document , DocumentType <EOL> from documents . search import document_search <EOL> from documents . signals import post_document_type_change <EOL> from documents . permissions import permission_document_view <EOL> from mayan . celery import app <EOL> from navigation import SourceColumn <EOL> from rest_api . classes import APIEndPoint <EOL> from . classes import DocumentMetadataHelper <EOL> from . handlers import ( <EOL> post_document_type_metadata_type_add , <EOL> post_document_type_metadata_type_delete , <EOL> post_post_document_type_change_metadata <EOL> ) <EOL> from . links import ( <EOL> link_metadata_add , link_metadata_edit , link_metadata_multiple_add , <EOL> link_metadata_multiple_edit , link_metadata_multiple_remove , <EOL> link_metadata_remove , link_metadata_view , <EOL> link_setup_document_type_metadata , <EOL> link_setup_document_type_metadata_required , <EOL> link_setup_metadata_type_create , link_setup_metadata_type_delete , <EOL> link_setup_metadata_type_edit , link_setup_metadata_type_list , <EOL> ) <EOL> from . models import DocumentMetadata , DocumentTypeMetadataType , MetadataType <EOL> from . permissions import ( <EOL> permission_metadata_document_add , permission_metadata_document_edit , <EOL> permission_metadata_document_remove , permission_metadata_document_view <EOL> ) <EOL> from . widgets import get_metadata_string <EOL> logger = logging . getLogger ( __name__ ) <EOL> class MetadataApp ( MayanAppConfig ) : <EOL> name = '<STR_LIT>' <EOL> test = True <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> def ready ( self ) : <EOL> super ( MetadataApp , self ) . ready ( ) <EOL> APIEndPoint ( app = self , version_string = '<STR_LIT:1>' ) <EOL> Document . add_to_class ( <EOL> '<STR_LIT>' , DocumentMetadataHelper . constructor <EOL> ) <EOL> Filter ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> slug = '<STR_LIT>' , <EOL> filter_kwargs = [ <EOL> { <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : False <EOL> } <EOL> ] , model = Document , object_permission = permission_document_view , <EOL> hide_links = True <EOL> ) <EOL> Filter ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> slug = '<STR_LIT>' , <EOL> filter_kwargs = [ <EOL> { <EOL> '<STR_LIT>' : False , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> { <EOL> '<STR_LIT>' : False <EOL> } <EOL> ] , model = Document , object_permission = permission_document_view , <EOL> hide_links = True <EOL> ) <EOL> ModelAttribute ( <EOL> Document , '<STR_LIT>' , type_name = '<STR_LIT>' , <EOL> description = _ ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> ModelAttribute ( <EOL> Document , '<STR_LIT>' , <EOL> label = _ ( '<STR_LIT>' ) , type_name = '<STR_LIT>' <EOL> ) <EOL> ModelAttribute ( <EOL> Document , '<STR_LIT>' , label = _ ( '<STR_LIT>' ) , <EOL> type_name = '<STR_LIT>' <EOL> ) <EOL> ModelAttribute ( <EOL> Document , '<STR_LIT>' , label = _ ( '<STR_LIT>' ) , <EOL> description = _ ( <EOL> '<STR_LIT>' <EOL> ) , <EOL> type_name = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> ModelPermission . register ( <EOL> model = Document , permissions = ( <EOL> permission_metadata_document_add , <EOL> permission_metadata_document_edit , <EOL> permission_metadata_document_remove , <EOL> permission_metadata_document_view , <EOL> ) <EOL> ) <EOL> SourceColumn ( <EOL> source = Document , label = _ ( '<STR_LIT>' ) , <EOL> func = lambda context : get_metadata_string ( context [ '<STR_LIT:object>' ] ) <EOL> ) <EOL> SourceColumn ( <EOL> source = DocumentMetadata , label = _ ( '<STR_LIT>' ) , <EOL> attribute = '<STR_LIT:value>' <EOL> ) <EOL> SourceColumn ( <EOL> source = DocumentMetadata , label = _ ( '<STR_LIT>' ) , <EOL> func = lambda context : two_state_template ( <EOL> context [ '<STR_LIT:object>' ] . is_required <EOL> ) <EOL> ) <EOL> app . conf . CELERY_QUEUES . append ( <EOL> Queue ( '<STR_LIT>' , Exchange ( '<STR_LIT>' ) , routing_key = '<STR_LIT>' ) , <EOL> ) <EOL> app . conf . CELERY_ROUTES . update ( <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> } <EOL> ) <EOL> document_search . add_model_field ( <EOL> field = '<STR_LIT>' , label = _ ( '<STR_LIT>' ) <EOL> ) <EOL> document_search . add_model_field ( <EOL> field = '<STR_LIT>' , label = _ ( '<STR_LIT>' ) <EOL> ) <EOL> menu_facet . bind_links ( links = ( link_metadata_view , ) , sources = ( Document , ) ) <EOL> menu_multi_item . bind_links ( <EOL> links = ( <EOL> link_metadata_multiple_add , link_metadata_multiple_edit , <EOL> link_metadata_multiple_remove <EOL> ) , sources = ( Document , ) <EOL> ) <EOL> menu_object . bind_links ( <EOL> links = ( <EOL> link_setup_document_type_metadata , <EOL> link_setup_document_type_metadata_required <EOL> ) , sources = ( DocumentType , ) <EOL> ) <EOL> menu_object . bind_links ( <EOL> links = ( <EOL> link_setup_metadata_type_edit , <EOL> link_setup_metadata_type_delete <EOL> ) , sources = ( MetadataType , ) <EOL> ) <EOL> menu_secondary . bind_links ( <EOL> links = ( <EOL> link_setup_metadata_type_list , <EOL> link_setup_metadata_type_create <EOL> ) , sources = ( <EOL> MetadataType , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> menu_setup . bind_links ( links = ( link_setup_metadata_type_list , ) ) <EOL> menu_sidebar . bind_links ( <EOL> links = ( <EOL> link_metadata_add , link_metadata_edit , link_metadata_remove <EOL> ) , sources = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> ) <EOL> post_delete . connect ( <EOL> post_document_type_metadata_type_delete , <EOL> dispatch_uid = '<STR_LIT>' , <EOL> sender = DocumentTypeMetadataType <EOL> ) <EOL> post_document_type_change . connect ( <EOL> post_post_document_type_change_metadata , <EOL> dispatch_uid = '<STR_LIT>' , <EOL> sender = Document <EOL> ) <EOL> post_save . connect ( <EOL> post_document_type_metadata_type_add , <EOL> dispatch_uid = '<STR_LIT>' , <EOL> sender = DocumentTypeMetadataType <EOL> ) </s>
