Exemplo n.º 1
0
    def handle(self, *args, **options):
        # Connection needs first to be at the public schema, as this is where
        # the database needs to be set before creating a new tenant. If this is
        # not done then django-tenants will raise a "Can't create tenant outside
        # the public schema." error.
        connection.set_schema_to_public()  # Switch to Public.

        # Get the user inputs.
        schema_name = options['schema_name'][0]
        length = options['length'][0]

        try:
            organization = SharedOrganization.objects.get(
                schema_name=schema_name)
        except SharedOrganization.DoesNotExist:
            raise CommandError(_('Organization does not exist!'))

        # Connection will set it back to our tenant.
        connection.set_schema(organization.schema_name,
                              True)  # Switch to Tenant.

        members = Member.seed(organization, length)

        # Iterate through all the randomly generated members
        for member in members:
            freezer = freeze_time(member.last_modified_at)
            freezer.start()

            # Run the following which will save our searchable content.
            indexed_text = Member.get_searchable_content(member)
            member.indexed_text = Truncator(indexed_text).chars(1023)
            member.save()

            freezer.stop()

        # For debugging purposes.
        self.stdout.write(
            self.style.SUCCESS(
                _('Successfully seed the following member(s):')))

        for member in members:
            self.stdout.write(
                self.style.SUCCESS(
                    _('Slug %(slug)s.') % {
                        'slug': member.user.slug,
                    }))
    def handle(self, *args, **options):
        # Connection needs first to be at the public schema, as this is where
        # the database needs to be set before creating a new tenant. If this is
        # not done then django-tenants will raise a "Can't create tenant outside
        # the public schema." error.
        connection.set_schema_to_public()  # Switch to Public.

        # Get the user inputs.
        schema_name = options['schema_name'][0]
        length = options['length'][0]

        try:
            organization = SharedOrganization.objects.get(
                schema_name=schema_name)
        except SharedOrganization.DoesNotExist:
            raise CommandError(_('Organization does not exist!'))

        # Connection will set it back to our tenant.
        connection.set_schema(organization.schema_name,
                              True)  # Switch to Tenant.

        members = Member.seed(organization, length)

        # Iterate through all the randomly generated members
        for member in members:
            freezer = freeze_time(member.last_modified_at)
            freezer.start()

            # Run the following which will save our searchable content.
            indexed_text = Member.get_searchable_content(member)
            member.indexed_text = Truncator(indexed_text).chars(1023)
            member.save()

            # Promote the `member` to be an `area coordinator`.
            associate = member.promote_to_associate(
                defaults={
                    'has_signed_associate_agreement': True,
                    'has_signed_conflict_of_interest_agreement': True,
                    'has_signed_code_of_conduct_agreement': True,
                    'has_signed_confidentiality_agreement': True,
                    'police_check_date': timezone.now(),
                    'created_by': None,
                    'created_from': None,
                    'created_from_is_public': False,
                    'last_modified_by': None,
                    'last_modified_from': None,
                    'last_modified_from_is_public': False,
                })

            # For debugging purposes.
            self.stdout.write(
                self.style.SUCCESS(
                    _('Promoted member slug %(slug)s to area coordinator.') % {
                        'slug': member.user.slug,
                    }))

            freezer.stop()

        # For debugging purposes.
        self.stdout.write(
            self.style.SUCCESS(
                _('Successfully seed the following member(s):')))

        for member in members:
            self.stdout.write(
                self.style.SUCCESS(
                    _('Slug %(slug)s.') % {
                        'slug': member.user.slug,
                    }))