<commit_before>from __future__ import unicode_literals

from django.apps import AppConfig
from django.db.models import signals
from django_fsm import signals as fsm_signals


class StructureConfig(AppConfig):
    name = 'waldur_core.structure'
    verbose_name = 'Structure'

    def ready(self):
        from waldur_core.core.models import CoordinatesMixin, User
        from waldur_core.structure.executors import check_cleanup_executors
        from waldur_core.structure.models import ResourceMixin, Service, TagMixin, VirtualMachine
        from waldur_core.structure import handlers
        from waldur_core.structure import signals as structure_signals
        from waldur_core.quotas import signals as quota_signals

        from django.core import checks
        checks.register(check_cleanup_executors)

        Customer = self.get_model('Customer')
        Project = self.get_model('Project')

        CustomerPermission = self.get_model('CustomerPermission')
        ProjectPermission = self.get_model('ProjectPermission')

        signals.post_save.connect(
            handlers.log_customer_save,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_save',
        )

        signals.post_delete.connect(
            handlers.log_customer_delete,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_delete',
        )

        signals.post_save.connect(
            handlers.log_project_save,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_save',
        )

        signals.post_delete.connect(
            handlers.log_project_delete,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_delete',
        )

        # increase nc_user_count quota usage on adding user to customer
        structure_models_with_roles = (Customer, Project)
        for model in structure_models_with_roles:
            name = 'increase_customer_nc_users_quota_on_adding_user_to_%s' % model.__name__
            structure_signals.structure_role_granted.connect(
                handlers.change_customer_nc_users_quota,
                sender=model,
                dispatch_uid='waldur_core.structure.handlers.%s' % name,
            )

        # decrease nc_user_count quota usage on removing user from customer
        for model in structure_models_with_roles:
            name = 'decrease_customer_nc_users_quota_on_removing_user_from_%s' % model.__name__
            structure_signals.structure_role_revoked.connect(
                handlers.change_customer_nc_users_quota,
                sender=model,
                dispatch_uid='waldur_core.structure.handlers.%s' % name,
            )

        structure_signals.structure_role_granted.connect(
            handlers.log_customer_role_granted,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_granted',
        )

        structure_signals.structure_role_revoked.connect(
            handlers.log_customer_role_revoked,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_revoked',
        )

        structure_signals.structure_role_updated.connect(
            handlers.log_customer_role_updated,
            sender=CustomerPermission,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_updated',
        )

        structure_signals.structure_role_granted.connect(
            handlers.log_project_role_granted,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_granted',
        )

        structure_signals.structure_role_revoked.connect(
            handlers.log_project_role_revoked,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_revoked',
        )

        structure_signals.structure_role_updated.connect(
            handlers.log_project_role_updated,
            sender=ProjectPermission,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_updated',
        )

        signals.pre_delete.connect(
            handlers.revoke_roles_on_project_deletion,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.revoke_roles_on_project_deletion',
        )

        for index, model in enumerate(ResourceMixin.get_all_models()):<commit_msg>Emit creation/deletion events for subresources, including OpenStack backups [WAL-1963]<commit_after>from __future__ import unicode_literals

from django.apps import AppConfig
from django.db.models import signals
from django_fsm import signals as fsm_signals


class StructureConfig(AppConfig):
    name = 'waldur_core.structure'
    verbose_name = 'Structure'

    def ready(self):
        from waldur_core.core.models import CoordinatesMixin, User
        from waldur_core.structure.executors import check_cleanup_executors
        from waldur_core.structure.models import ResourceMixin, SubResource, Service, TagMixin, VirtualMachine
        from waldur_core.structure import handlers
        from waldur_core.structure import signals as structure_signals
        from waldur_core.quotas import signals as quota_signals

        from django.core import checks
        checks.register(check_cleanup_executors)

        Customer = self.get_model('Customer')
        Project = self.get_model('Project')

        CustomerPermission = self.get_model('CustomerPermission')
        ProjectPermission = self.get_model('ProjectPermission')

        signals.post_save.connect(
            handlers.log_customer_save,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_save',
        )

        signals.post_delete.connect(
            handlers.log_customer_delete,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_delete',
        )

        signals.post_save.connect(
            handlers.log_project_save,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_save',
        )

        signals.post_delete.connect(
            handlers.log_project_delete,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_delete',
        )

        # increase nc_user_count quota usage on adding user to customer
        structure_models_with_roles = (Customer, Project)
        for model in structure_models_with_roles:
            name = 'increase_customer_nc_users_quota_on_adding_user_to_%s' % model.__name__
            structure_signals.structure_role_granted.connect(
                handlers.change_customer_nc_users_quota,
                sender=model,
                dispatch_uid='waldur_core.structure.handlers.%s' % name,
            )

        # decrease nc_user_count quota usage on removing user from customer
        for model in structure_models_with_roles:
            name = 'decrease_customer_nc_users_quota_on_removing_user_from_%s' % model.__name__
            structure_signals.structure_role_revoked.connect(
                handlers.change_customer_nc_users_quota,
                sender=model,
                dispatch_uid='waldur_core.structure.handlers.%s' % name,
            )

        structure_signals.structure_role_granted.connect(
            handlers.log_customer_role_granted,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_granted',
        )

        structure_signals.structure_role_revoked.connect(
            handlers.log_customer_role_revoked,
            sender=Customer,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_revoked',
        )

        structure_signals.structure_role_updated.connect(
            handlers.log_customer_role_updated,
            sender=CustomerPermission,
            dispatch_uid='waldur_core.structure.handlers.log_customer_role_updated',
        )

        structure_signals.structure_role_granted.connect(
            handlers.log_project_role_granted,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_granted',
        )

        structure_signals.structure_role_revoked.connect(
            handlers.log_project_role_revoked,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_revoked',
        )

        structure_signals.structure_role_updated.connect(
            handlers.log_project_role_updated,
            sender=ProjectPermission,
            dispatch_uid='waldur_core.structure.handlers.log_project_role_updated',
        )

        signals.pre_delete.connect(
            handlers.revoke_roles_on_project_deletion,
            sender=Project,
            dispatch_uid='waldur_core.structure.handlers.revoke_roles_on_project_deletion',
        )

        resource_and_subresources = ResourceMixin.get_all_models() + SubResource.get_all_models()
        for index, model in enumerate(resource_and_subresources):
{'fraction_non_alphanumeric': 0.06380650103972857, 'fraction_numerical': 0.000437780453102769, 'mean_word_length': 2.7389525368248773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '502750', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2484, 'n_words': 341}