コード例 #1
0
    def post_save(self, sender, document, created, **kwargs):
        """
        If created, the :class:`~core.models.Tenant` should be initialized.
        """
        from core.models import VosaeGroup
        # Removed related TTL
        document.remove_related_ttl()

        if created:
            # Ensure that an index with the current search settings is present in ElasticSearch
            # Done synchronously since we can't currently chain all the related tasks from here
            conn = pyes.ES(settings.ES_SERVERS, basic_auth=settings.ES_AUTH)
            conn.ensure_index(document.slug, get_search_settings())

            # Creates an admin group
            admin_group = VosaeGroup(tenant=document, name=pgettext('group_name', 'Administrators'), is_admin=True)
            for perm, perm_data in admin_group.permissions.perms.iteritems():
                admin_group.permissions.perms[perm]['authorization'] = True
            admin_group.save()
コード例 #2
0
ファイル: tenant.py プロジェクト: hkmshb/vosae-app
    def post_save(self, sender, document, created, **kwargs):
        """
        If created, the :class:`~core.models.Tenant` should be initialized.
        """
        from core.models import VosaeGroup

        # Removed related TTL
        document.remove_related_ttl()

        if created:
            # Ensure that an index with the current search settings is present in ElasticSearch
            # Done synchronously since we can't currently chain all the related tasks from here
            conn = pyes.ES(settings.ES_SERVERS, basic_auth=settings.ES_AUTH)
            conn.ensure_index(document.slug, get_search_settings())

            # Creates an admin group
            admin_group = VosaeGroup(tenant=document, name=pgettext("group_name", "Administrators"), is_admin=True)
            for perm, perm_data in admin_group.permissions.perms.iteritems():
                admin_group.permissions.perms[perm]["authorization"] = True
            admin_group.save()
コード例 #3
0
    def handle(self, *args, **options):
        kwargs = {}
        if options.get('tenant'):
            kwargs.update(slug=options.get('tenant'))
        tenants = Tenant.objects.filter(**kwargs)
        tenants_count = tenants.count()
        search_models = get_search_models()
        search_settings = get_search_settings()
        conn = pyes.ES(settings.ES_SERVERS, basic_auth=settings.ES_AUTH)
        if tenants_count == 1:
            print 'Reindexing tenant {0}'.format(tenants[0].name)
        else:
            print 'Reindexing {0} tenants'.format(tenants_count)

        # Processing each tenant independently
        for tenant in tenants:
            try:
                # Ensure index mapping
                conn.ensure_index(tenant.slug, search_settings, clear=True)

                # Data indexation
                for name, cls in search_models:
                    kwargs = {'tenant': tenant}
                    obj_list = cls.get_indexable_documents(**kwargs)

                    if options.get('verbosity') is '2':
                        sys.stdout.write("\rIndexing %d %ss..." %
                                         (len(obj_list), name))
                        sys.stdout.flush()

                    for doc in obj_list:
                        try:
                            doc.es_index()
                        except Exception as e:
                            print u'\r{0}'.format(e)
                if options.get('verbosity') is '2':
                    print unicode('\r[{0}]'.format(
                        tenant.slug)).ljust(30) + ": OK"
            except Exception as e:
                print 'An error occured with tenant {0}:'.format(tenant.slug)
                print e
コード例 #4
0
    def handle(self, *args, **options):
        kwargs = {}
        if options.get('tenant'):
            kwargs.update(slug=options.get('tenant'))
        tenants = Tenant.objects.filter(**kwargs)
        tenants_count = tenants.count()
        search_models = get_search_models()
        search_settings = get_search_settings()
        conn = pyes.ES(settings.ES_SERVERS, basic_auth=settings.ES_AUTH)
        if tenants_count == 1:
            print 'Reindexing tenant {0}'.format(tenants[0].name)
        else:
            print 'Reindexing {0} tenants'.format(tenants_count)

        # Processing each tenant independently
        for tenant in tenants:
            try:
                # Ensure index mapping
                conn.ensure_index(tenant.slug, search_settings, clear=True)

                # Data indexation
                for name, cls in search_models:
                    kwargs = {'tenant': tenant}
                    obj_list = cls.get_indexable_documents(**kwargs)

                    if options.get('verbosity') is '2':
                        sys.stdout.write("\rIndexing %d %ss..." % (len(obj_list), name))
                        sys.stdout.flush()

                    for doc in obj_list:
                        try:
                            doc.es_index()
                        except Exception as e:
                            print u'\r{0}'.format(e)
                if options.get('verbosity') is '2':
                    print unicode('\r[{0}]'.format(tenant.slug)).ljust(30) + ": OK"
            except Exception as e:
                print 'An error occured with tenant {0}:'.format(tenant.slug)
                print e