Пример #1
0
    def ready(self):
        # Load projector elements.
        # Do this by just importing all from these files.
        from . import projector  # noqa

        # Import all required stuff.
        from openslides.core.config import config
        from openslides.utils.rest_api import router
        from .config_variables import get_config_variables
        from .signals import create_builtin_workflows
        from .views import CategoryViewSet, MotionViewSet, MotionBlockViewSet, MotionPollViewSet, MotionChangeRecommendationViewSet, WorkflowViewSet

        # Define config variables
        config.update_config_variables(get_config_variables())

        # Connect signals.
        post_migrate.connect(create_builtin_workflows, dispatch_uid='motion_create_builtin_workflows')

        # Register viewsets.
        router.register(self.get_model('Category').get_collection_string(), CategoryViewSet)
        router.register(self.get_model('Motion').get_collection_string(), MotionViewSet)
        router.register(self.get_model('MotionBlock').get_collection_string(), MotionBlockViewSet)
        router.register(self.get_model('Workflow').get_collection_string(), WorkflowViewSet)
        router.register(self.get_model('MotionChangeRecommendation').get_collection_string(),
                        MotionChangeRecommendationViewSet)
        router.register('motions/motionpoll', MotionPollViewSet)
Пример #2
0
 def ready(self):
     from .management import create_initial_superuser
     from .models import Account
     services.register(Account, menu=False, dashboard=False)
     accounts.register(Account, icon='Face-monkey.png')
     post_migrate.connect(create_initial_superuser,
         dispatch_uid="orchestra.contrib.accounts.management.createsuperuser")
Пример #3
0
 def ready(self):
     from metadata.handlers import save_db_state, populate_values_list_cache
     # Hooking to post_migrate is the only way I've found to
     # make sure the db is really available and can be queried
     # to populate the values list cache
     post_migrate.connect(save_db_state, sender=self)
     post_migrate.connect(populate_values_list_cache, sender=self)
Пример #4
0
 def ready(self):
     post_migrate.connect(
         create_permissions,
         dispatch_uid="django.contrib.auth.management.create_permissions"
     )
     checks.register(check_user_model, checks.Tags.models)
     checks.register(check_models_permissions, checks.Tags.models)
    def setUp(self):
        from django.db.models.signals import post_save, post_delete
        try:
            from django.db.models.signals import post_migrate
        except ImportError:  # django <= 1.6
            from django.db.models.signals import post_syncdb as post_migrate

        from django_elasticsearch.models import es_save_callback
        from django_elasticsearch.models import es_delete_callback
        from django_elasticsearch.models import es_syncdb_callback
        try:
            from django.apps import apps
            app = apps.get_app_config('django_elasticsearch')
        except ImportError: # django 1.4
            from django.db.models import get_app
            app = get_app('django_elasticsearch')

        post_save.connect(es_save_callback)
        post_delete.connect(es_delete_callback)
        post_migrate.connect(es_syncdb_callback)
        
        if int(get_version()[2]) >= 6:
            sender = app
        else:
            sender = None
        post_migrate.send(sender=sender,
                          app_config=app,
                          app=app,  # django 1.4
                          created_models=[TestModel,],
                          verbosity=2)

        self.instance = TestModel.objects.create(username=u"1",
                                                 first_name=u"woot",
                                                 last_name=u"foo")
        self.instance.es.do_index()
Пример #6
0
    def ready(self):
        stylesSet = force_text(settings.CKEDITOR_SETTINGS.get('stylesSet'))
        if stylesSet != 'default:{}'.format(reverse('admin:cascade_texteditor_config')):
            msg = "settings.CKEDITOR_SETTINGS['stylesSet'] should be `format_lazy('default:{}', reverse_lazy('admin:cascade_texteditor_config'))`"
            raise ImproperlyConfigured(msg)

        pre_migrate.connect(self.__class__.pre_migrate, sender=self)
        post_migrate.connect(self.__class__.post_migrate, sender=self)
Пример #7
0
    def ready(self):
        if 'cmsplugin_cascade.icon' in settings.INSTALLED_APPS:
            stylesSet = force_text(settings.CKEDITOR_SETTINGS.get('stylesSet'))
            if stylesSet != 'default:{}'.format(reverse('admin:cascade_texticon_wysiwig_config')):
                msg = "settings.CKEDITOR_SETTINGS['stylesSet'] should be `format_lazy('default:{}', reverse_lazy('admin:cascade_texticon_wysiwig_config'))`"
                raise ImproperlyConfigured(msg)

        pre_migrate.connect(self.__class__.pre_migrate, sender=self)
        post_migrate.connect(self.__class__.post_migrate, sender=self)
Пример #8
0
 def ready(self):
     """
     Connect post_save handler during routine operation. Disconnect it during migrations.
     """
     connect_post_save_handler()
     pre_migrate.connect(disconnect_post_save_handler)
     # now, we need to reconnect the post_save handler because unittests run
     # immediately after running migrate, in the same process
     post_migrate.connect(connect_post_save_handler)
Пример #9
0
   def ready(self):

        post_migrate.disconnect(
            dispatch_uid="django.contrib.auth.management.create_permissions")
        post_migrate.connect(
            lazy_permission_creation,
            sender=self,
            dispatch_uid="django.contrib.auth.management.create_permissions",
        )
Пример #10
0
 def ready(self):
     post_migrate.connect(
         create_permissions,
         dispatch_uid="django.contrib.auth.management.create_permissions"
     )
     if hasattr(get_user_model(), 'last_login'):
         from .models import update_last_login
         user_logged_in.connect(update_last_login, dispatch_uid='update_last_login')
     checks.register(check_user_model, checks.Tags.models)
     checks.register(check_models_permissions, checks.Tags.models)
Пример #11
0
    def ready(self) -> None:
        # We import zerver.signals here for the side effect of
        # registering the user_logged_in signal receiver.  This import
        # needs to be here (rather than e.g. at top-of-file) to avoid
        # running that code too early in Django's setup process, but
        # in any case, this is an intentionally unused import.
        import zerver.signals

        if settings.POST_MIGRATION_CACHE_FLUSHING:
            post_migrate.connect(flush_cache, sender=self)
Пример #12
0
    def ready(self):
        """
        For postgresql only, remove like indexes for uuid columns and
        create version-unique indexes.

        This will only be run in django >= 1.7.

        :return: None
        """
        if connection.vendor == 'postgresql':
            post_migrate.connect(index_adjustments, sender=self)
Пример #13
0
    def ready(self):
        from . import signals
        from django.contrib.auth.models import User

        post_migrate.connect(signals.create_groups)

        if DJANGO_AUTH_TYPE == 'SIMPLE':
            post_save.connect(signals.create_user, sender=User, dispatch_uid="create_user")

        import django_auth_ldap.backend
        django_auth_ldap.backend.populate_user.connect(signals.update_ldap_groups)
Пример #14
0
    def ready(self):
        from .utils import create_perms

        post_migrate.connect(
            create_perms,
            sender=__import__('disguise')
        )
        post_save.connect(
            create_perms,
            sender=apps.get_model('auth.Permission')
        )
Пример #15
0
    def ready(self):
        from django.contrib.sites.models import Site

        from job_board.signals import gen_site_config_post_migrate
        from job_board.signals import gen_site_config_post_save

        post_save.connect(gen_site_config_post_save, sender=Site)
        # NOTE: We list sites before job_board in INSTALLED_APPS, failing to
        #       do that will result in this post_migrate signal firing before
        #       the default site has been created.
        post_migrate.connect(gen_site_config_post_migrate, sender=self)
Пример #16
0
 def ready(self):
     post_migrate.connect(
         create_permissions,
         dispatch_uid="django.contrib.auth.management.create_permissions"
     )
     last_login_field = getattr(get_user_model(), 'last_login', None)
     # Register the handler only if UserModel.last_login is a field.
     if isinstance(last_login_field, DeferredAttribute):
         from .models import update_last_login
         user_logged_in.connect(update_last_login, dispatch_uid='update_last_login')
     checks.register(check_user_model, checks.Tags.models)
     checks.register(check_models_permissions, checks.Tags.models)
Пример #17
0
def patch():
    global PATCHED

    post_migrate.connect(_invalidate_on_migration)
    if 'south' in settings.INSTALLED_APPS:
        from south.signals import post_migrate as south_post_migrate
        south_post_migrate.connect(_invalidate_on_migration)

    _patch_cursor()
    _patch_atomic()
    _patch_orm()

    PATCHED = True
Пример #18
0
    def ready(self):
        # Ensure everything below is only ever run once
        if getattr(AppConfig, 'has_run_ready', False):
            return
        AppConfig.has_run_ready = True

        if 'django.contrib.sites' in settings.INSTALLED_APPS:
            from .management import create_default_site

            post_migrate.connect(create_default_site, sender=self)

        try:
            importlib.import_module('localsite.receivers')
        except ImportError:
            pass
Пример #19
0
    def ready(self):
        if django_version() == DjangoVersion.DJANGO_21:
            # Disable silently the package for Django => 2.1. We don't override
            # admin_site neither the default ModelAdmin.
            warnings.warn(
                'The package `admin_view_permission is deprecated in '
                'Django 2.1. Django added this functionality into the core.',
                DeprecationWarning
            )
            return

        if not isinstance(admin.site, AdminViewPermissionAdminSite):
            admin.site = AdminViewPermissionAdminSite('admin')
            admin.sites.site = admin.site

        post_migrate.connect(update_permissions)
Пример #20
0
    def ready(self):
        # Import all required stuff.
        from .config import config
        from ..utils.rest_api import router
        from .config_variables import get_config_variables
        from .projector import get_projector_elements
        from .signals import (
            delete_django_app_permissions,
            get_permission_change_data,
            permission_change,
            post_permission_creation,
            required_users,
            user_data_required,
        )
        from .views import (
            ChatMessageViewSet,
            ConfigViewSet,
            CountdownViewSet,
            ProjectorMessageViewSet,
            ProjectorViewSet,
            TagViewSet,
        )

        # Define config variables and projector elements.
        config.update_config_variables(get_config_variables())
        register_projector_elements(get_projector_elements())

        # Connect signals.
        post_permission_creation.connect(
            delete_django_app_permissions,
            dispatch_uid='delete_django_app_permissions')
        permission_change.connect(
            get_permission_change_data,
            dispatch_uid='core_get_permission_change_data')
        user_data_required.connect(
            required_users,
            dispatch_uid='core_required_users')

        post_migrate.connect(call_save_default_values, sender=self, dispatch_uid='core_save_config_default_values')

        # Register viewsets.
        router.register(self.get_model('Projector').get_collection_string(), ProjectorViewSet)
        router.register(self.get_model('ChatMessage').get_collection_string(), ChatMessageViewSet)
        router.register(self.get_model('Tag').get_collection_string(), TagViewSet)
        router.register(self.get_model('ConfigStore').get_collection_string(), ConfigViewSet, 'config')
        router.register(self.get_model('ProjectorMessage').get_collection_string(), ProjectorMessageViewSet)
        router.register(self.get_model('Countdown').get_collection_string(), CountdownViewSet)
Пример #21
0
 def setUp(self):
     post_save.connect(manage_meetup_location_groups, sender=MeetupLocation,
                       dispatch_uid="manage_groups")
     post_delete.connect(remove_meetup_location_groups, sender=MeetupLocation,
                         dispatch_uid="remove_groups")
     m2m_changed.connect(add_meetup_location_members, sender=MeetupLocation.members.through,
                         dispatch_uid="add_members")
     m2m_changed.connect(add_meetup_location_moderators,
                         sender=MeetupLocation.moderators.through,
                         dispatch_uid="add_moderators")
     m2m_changed.connect(delete_meetup_location_members, sender=MeetupLocation.members.through,
                         dispatch_uid="delete_members")
     m2m_changed.connect(delete_meetup_location_moderators,
                         sender=MeetupLocation.moderators.through,
                         dispatch_uid="delete_moderators")
     post_migrate.connect(create_notice_types, dispatch_uid="create_notice_types")
     self.password = "******"
Пример #22
0
    def ready(self):
        # Import all required stuff.
        from openslides.core.config import config
        from openslides.core.signals import permission_change, user_data_required
        from openslides.utils.rest_api import router
        from .config_variables import get_config_variables
        from .projector import get_projector_elements
        from .signals import (
            create_builtin_workflows,
            get_permission_change_data,
            required_users,
        )
        from .views import (
            CategoryViewSet,
            MotionViewSet,
            MotionBlockViewSet,
            MotionPollViewSet,
            MotionChangeRecommendationViewSet,
            StateViewSet,
            WorkflowViewSet,
        )

        # Define config variables and projector elements.
        config.update_config_variables(get_config_variables())
        register_projector_elements(get_projector_elements())

        # Connect signals.
        post_migrate.connect(
            create_builtin_workflows,
            dispatch_uid='motion_create_builtin_workflows')
        permission_change.connect(
            get_permission_change_data,
            dispatch_uid='motions_get_permission_change_data')
        user_data_required.connect(
            required_users,
            dispatch_uid='motions_required_users')

        # Register viewsets.
        router.register(self.get_model('Category').get_collection_string(), CategoryViewSet)
        router.register(self.get_model('Motion').get_collection_string(), MotionViewSet)
        router.register(self.get_model('MotionBlock').get_collection_string(), MotionBlockViewSet)
        router.register(self.get_model('Workflow').get_collection_string(), WorkflowViewSet)
        router.register(self.get_model('MotionChangeRecommendation').get_collection_string(),
                        MotionChangeRecommendationViewSet)
        router.register(self.get_model('MotionPoll').get_collection_string(), MotionPollViewSet)
        router.register(self.get_model('State').get_collection_string(), StateViewSet)
    def test_signals(self):
        """ Test the signals emitted during the migration """

        app_config = apps.get_app_config('event_calendar')

        pre_migrate_callback = mock.MagicMock()
        post_migrate_callback = mock.MagicMock()

        pre_migrate.connect(pre_migrate_callback, sender=app_config)
        post_migrate.connect(post_migrate_callback, sender=app_config)

        self.test_routine_migration()

        pre_migrate.disconnect(pre_migrate_callback, sender=app_config)
        post_migrate.disconnect(post_migrate_callback, sender=app_config)

        self.assertEqual(pre_migrate_callback.call_count, 3)
        self.assertEqual(post_migrate_callback.call_count, 3)
Пример #24
0
    def ready(self):
        # Load projector elements.
        # Do this by just importing all from these files.
        from . import projector  # noqa

        # Import all required stuff.
        from openslides.core.signals import config_signal
        from openslides.utils.rest_api import router
        from .signals import create_builtin_workflows, setup_motion_config
        from .views import CategoryViewSet, MotionViewSet, MotionPollViewSet, WorkflowViewSet

        # Connect signals.
        config_signal.connect(setup_motion_config, dispatch_uid='setup_motion_config')
        post_migrate.connect(create_builtin_workflows, dispatch_uid='motion_create_builtin_workflows')

        # Register viewsets.
        router.register('motions/category', CategoryViewSet)
        router.register('motions/motion', MotionViewSet)
        router.register('motions/motionpoll', MotionPollViewSet)
        router.register('motions/workflow', WorkflowViewSet)
Пример #25
0
    def _fixture_teardown(self):
        post_migrate.disconnect(create_default_site, sender=apps.get_app_config('sites'))
        post_migrate.disconnect(update_contenttypes)
        post_migrate.disconnect(create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions")

        super(AskbotTestCase, self)._fixture_teardown()

        post_migrate.connect(update_contenttypes)
        post_migrate.connect(create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions")
        post_migrate.connect(create_default_site, sender=apps.get_app_config('sites'))
Пример #26
0
    def ready(self):
        super(WorkAppConfig, self).ready()

        from work.models import create_unit_types, create_exchange_skills
        from general.models import create_general_types
        from work.signals import comment_notification

        post_migrate.connect(create_general_types, sender=self)
        post_migrate.connect(create_unit_types, sender=self)
        post_migrate.connect(create_exchange_skills, sender=self)
        comment_was_posted.connect(comment_notification, sender=self) #Comment)
        #comment_will_be_posted.connect(pre_comment, sender=Comment)
        logger.debug("Connected signals to post_migrate and comment_was_posted")
Пример #27
0
    def ready(self):

        post_migrate.connect(create_global_settings, sender=self)

        self.module.autodiscover()
Пример #28
0
 def ready(self):
     post_migrate.connect(create_default_kafka_group, sender=self)
Пример #29
0
    def ready(self):
        post_migrate.connect(init_users_groups, sender=self)

        # noinspection PyUnresolvedReferences
        import grandchallenge.core.signals  # noqa: F401
Пример #30
0
 def ready(self):
     post_migrate.connect(create_CMSpages)
Пример #31
0
from institutions.models import Institution
from users.models import User, AccountType

for model in apps.get_app_config('common').models.values():
    admin.site.register(model)


def add_default_user(sender, **kwargs):
    if User.objects.count() == 0:
        AccountType.objects.all().delete()
        print 'Creating Account Types'
        for account_type in ['Teacher', 'Parent', 'Student']:
            AccountType.objects.create(name=account_type)

        print 'Creating User'
        user = User.objects.create(
            'tweechy',
            'Peter',
            'tweechy!@#',
            last_name='Saruni',
            middle_name='Njenga',
            account_type=AccountType.objects.get(name='Teacher'))

        print 'Creating Default Institution'
        institution = Institution.objects.create(name='Starehe Boys Centre',
                                                 created_by=user)


# Add default user to database
post_migrate.connect(add_default_user)
Пример #32
0
 def ready(self):
     super().ready()
     post_migrate.connect(permission_callback, sender=self)
Пример #33
0
def auto_create_superuser(sender, **kwargs):
    if not settings.USERS_CREATE_SUPERUSER:
        return

    email = settings.USERS_SUPERUSER_EMAIL
    password = settings.USERS_SUPERUSER_PASSWORD
    #name=UsersAppConf.SUPERUSER_NAEM
    User = get_user_model()
    try:
        User.base_objects.get(email=email)
    except User.DoesNotExist:
        print('Creating superuser ({0}:{1})'.format(email, password))
        User.objects.create_superuser(email, password)


post_migrate.connect(auto_create_superuser, sender=None)


class EmailActivationTokenGenerator(object):
    def make_token(self, user):
        return self._make_token_with_timestamp(user,
                                               self._num_days(self._today()))

    def check_token(self, user, token):
        """
        Check that a activation token is correct for a given user.
        """
        # Parse the token
        try:
            ts_b36, hash = token.split('-')
        except ValueError:
Пример #34
0
 def ready(self):
     post_migrate.connect(init_workstation_creators_group, sender=self)
     post_migrate.connect(init_session_permissions, sender=self)
Пример #35
0
import os
from django.db.models.signals import post_migrate
from django.contrib.auth import get_user_model
from django.contrib import admin

admin.site.site_header = 'BI-transactions Admin'
User = get_user_model()


def add_initial_super_admin(sender, **kwargs):
    if User.objects.count() == 0:
        print('Creating a superAdmin')
        User.objects.create_superuser(username=os.getenv('SUPER_NAME'),
                                      email=os.getenv('SUPER_EMAIL'),
                                      password=os.getenv('SUPER_PASS'))


post_migrate.connect(add_initial_super_admin)
Пример #36
0
    def ready(self):
        post_migrate.connect(post_migrate_callback, sender=self)

        from vehicles.importers import register_importers_from_settings
        register_importers_from_settings()
Пример #37
0
 def ready(self):
     super(PagesConfig, self).ready()
     post_migrate.connect(create_notice_types, sender=self)
Пример #38
0
 def ready(self):
     post_migrate.connect(ensure_django_comment_object_pk_is_int)
Пример #39
0
    """
    # for each of our content types
    for content_type in ContentType.objects.all():
        # build our permission slug
        codename = "view_%s" % content_type.model

        # if it doesn't exist..
        if not Permission.objects.filter(content_type=content_type, codename=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                                      codename=codename,
                                      name="Can view %s" % content_type.name)
            # print "Added view permission for %s" % content_type.name

# check for all our view permissions after a syncdb
post_migrate.connect(add_view_permissions)


class Bookmark(models.Model):
    title = models.CharField(_(u'Title'), max_length=128)
    user = models.ForeignKey(AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name=_(u"user"), blank=True, null=True)
    url_name = models.CharField(_(u'Url Name'), max_length=64)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    query = models.CharField(_(u'Query String'), max_length=1000, blank=True)
    is_share = models.BooleanField(_(u'Is Shared'), default=False)

    @property
    def url(self):
        base_url = reverse(self.url_name)
        if self.query:
            base_url = base_url + '?' + self.query
Пример #40
0
 def ready(self):
     post_migrate.connect(create_index, sender=self)
Пример #41
0
 def ready(self):
     post_migrate.connect(signals.signal_post_migrate, sender=self)
Пример #42
0
 def ready(self):
     post_migrate.connect(my_callback, sender=self)
Пример #43
0
    def append(self, field):
        self._fields.append([field.model._meta.app_label, field.model.__name__])

    def __iter__(self):
        return iter([get_model(*i)._concurrencymeta.field for i in self._fields])

    def __contains__(self, field):
        target = [field.model._meta.app_label, field.model.__name__]
        return target in self._fields


_TRIGGERS = TriggerRegistry()
# _TRIGGERS = []

if not conf.MANUAL_TRIGGERS:
    post_migrate.connect(post_syncdb_concurrency_handler, dispatch_uid='post_syncdb_concurrency_handler')


class VersionField(Field):
    """ Base class """

    def __init__(self, *args, **kwargs):
        verbose_name = kwargs.get('verbose_name', None)
        name = kwargs.get('name', None)
        db_tablespace = kwargs.get('db_tablespace', None)
        db_column = kwargs.get('db_column', None)
        help_text = kwargs.get('help_text', _('record revision number'))

        super(VersionField, self).__init__(verbose_name, name,
                                           help_text=help_text,
                                           default=0,
Пример #44
0
def auto_create_superuser(sender, **kwargs):
    if not settings.USERS_CREATE_SUPERUSER:
        return

    email = settings.USERS_SUPERUSER_EMAIL
    password = settings.USERS_SUPERUSER_PASSWORD

    User = get_user_model()
    try:
        User.base_objects.get(email=email)
    except User.DoesNotExist:
        print('Creating superuser ({0}:{1})'.format(email, password))
        User.objects.create_superuser(email, password)

post_migrate.connect(auto_create_superuser, sender=None)


class EmailActivationTokenGenerator(object):

    def make_token(self, user):
        return self._make_token_with_timestamp(user, self._num_days(self._today()))

    def check_token(self, user, token):
        """
        Check that a activation token is correct for a given user.
        """
        # Parse the token
        try:
            ts_b36, hash = token.split('-')
        except ValueError:
Пример #45
0
 def ready(self):
     # start email reminder task once migrations have completed
     post_migrate.connect(start_reminder_email_task, sender=self)
Пример #46
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()

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

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

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

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

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

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

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

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

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

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

        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),
                               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_list',
            ))
        menu_secondary.bind_links(
            links=(link_workflow_template_state_create, ),
            sources=(
                WorkflowState,
                '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)
Пример #47
0
    def ready(self):
        super(UserManagerConfig, self).ready()

        post_migrate.connect(init_user, sender=self)
Пример #48
0
 def ready(self):
     import tracker.signals
     post_migrate.connect(tracker.signals.create_default_settings, sender=self)
Пример #49
0
 def ready(self):
     post_migrate.connect(create_superuser, sender=self)
Пример #50
0
try:
    from django.db.models.signals import post_migrate as db_ready
except ImportError:
    from django.db.models.signals import post_syncdb as db_ready


def sync_badges_to_db(**kwargs):
    from .utils import registered_badges
    for badge in registered_badges.values():
        badge.badge


db_ready.connect(sync_badges_to_db)
Пример #51
0
 def ready(self):
     post_migrate.connect(pm_callback, sender=self, dispatch_uid='geotrek.core.movetoschemas')
Пример #52
0
 def ready(self):
     from .security import Management
     post_migrate.connect(Management.init_groups,
                          sender=self.apps.app_configs["auth"])
Пример #53
0
 def ready(self):
     pre_migrate.connect(inject_rename_contenttypes_operations, sender=self)
     post_migrate.connect(create_contenttypes)
     checks.register(check_generic_foreign_keys, checks.Tags.models)
     checks.register(check_model_name_lengths, checks.Tags.models)
Пример #54
0
 def ready(self):
     post_migrate.connect(post_migration_callback, sender=self)
Пример #55
0
    def ready(self):
        # Import all required stuff.
        # Let all client websocket message register
        from ..utils.rest_api import router
        from . import serializers  # noqa
        from .config import config
        from .signals import (
            autoupdate_for_many_to_many_relations,
            cleanup_unused_permissions,
            delete_django_app_permissions,
            get_permission_change_data,
            permission_change,
            post_permission_creation,
        )
        from .views import (
            ConfigViewSet,
            CountdownViewSet,
            ProjectionDefaultViewSet,
            ProjectorMessageViewSet,
            ProjectorViewSet,
            TagViewSet,
        )

        # Collect all config variables before getting the constants.
        config.collect_config_variables_from_apps()

        # Connect signals.
        post_permission_creation.connect(
            delete_django_app_permissions,
            dispatch_uid="delete_django_app_permissions")
        post_permission_creation.connect(
            cleanup_unused_permissions,
            dispatch_uid="cleanup_unused_permissions")
        permission_change.connect(
            get_permission_change_data,
            dispatch_uid="core_get_permission_change_data")

        post_migrate.connect(manage_config,
                             sender=self,
                             dispatch_uid="core_manage_config")
        pre_delete.connect(
            autoupdate_for_many_to_many_relations,
            dispatch_uid="core_autoupdate_for_many_to_many_relations",
        )

        # Register viewsets.
        router.register(
            self.get_model("Projector").get_collection_string(),
            ProjectorViewSet)
        router.register(
            self.get_model("Projectiondefault").get_collection_string(),
            ProjectionDefaultViewSet,
        )
        router.register(
            self.get_model("Tag").get_collection_string(), TagViewSet)
        router.register(
            self.get_model("ConfigStore").get_collection_string(),
            ConfigViewSet,
            "config",
        )
        router.register(
            self.get_model("ProjectorMessage").get_collection_string(),
            ProjectorMessageViewSet,
        )
        router.register(
            self.get_model("Countdown").get_collection_string(),
            CountdownViewSet)

        if "runserver" in sys.argv or "changeconfig" in sys.argv:
            from openslides.utils.startup import run_startup_hooks

            run_startup_hooks()
Пример #56
0
 def ready(self):
     post_migrate.connect(init_default_interfaces, sender=self)
Пример #57
0
    def class_hierarchy(clslist):
        """Recursively yield a class hierarchy"""
        for cls in clslist:
            subclass_list = cls.__subclasses__()
            if subclass_list:
                for subcls in class_hierarchy(subclass_list):
                    yield subcls
            else:
                yield cls

    for cls in class_hierarchy([SharedMemoryModel]):
        cls.flush_instance_cache()
    # run the python garbage collector
    return gc.collect()
#request_finished.connect(flush_cache)
post_migrate.connect(flush_cache)


def flush_cached_instance(sender, instance, **kwargs):
    """
    Flush the idmapper cache only for a given instance.

    """
    # XXX: Is this the best way to make sure we can flush?
    if not hasattr(instance, 'flush_cached_instance'):
        return
    sender.flush_cached_instance(instance, force=True)
pre_delete.connect(flush_cached_instance)


def update_cached_instance(sender, instance, **kwargs):
Пример #58
0
    def ready(self):
        # type: () -> None
        import zerver.signals

        if settings.POST_MIGRATION_CACHE_FLUSHING:
            post_migrate.connect(flush_cache, sender=self)
Пример #59
0
 def ready(self):
     import account.signals as ss
     post_migrate.connect(
         ss.create_admin,
         sender=self
     )
Пример #60
0
 def ready(self):
     post_migrate.connect(update_admin_index, sender=self)