django.contrib.auth.models.User.objects.filter.filter - python examples

Here are the examples of the python api django.contrib.auth.models.User.objects.filter.filter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

3 View Complete Implementation : forms.py
Copyright BSD 2-Clause "Simplified" License
Author : awemulya
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')
        super(astignOrgAdmin, self).__init__(*args, **kwargs)
        role = kwargs.get('instance')
        if role is not None:
            old_admins = role.organization.get_staffs
            old_admins_id = [admin[0] for admin in old_admins]
            old_admins_id.append(settings.ANONYMOUS_USER_ID)
            if hasattr(self.request, "organization"):
                if self.request.organization:
                    users = User.objects.filter(user_profile__organization=self.request.organization, is_active=True).\
                        filter(id__in=old_admins_id)
                else:
                    users = User.objects.filter(is_active=True).exclude(id__in=old_admins_id)
            else:
                users = User.objects.filter(is_active=True).exclude(id__in=old_admins_id)
            self.fields['user'].queryset = users
            self.fields['organization'].choices = old_admins

0 View Complete Implementation : disableaccounts.py
Copyright GNU Affero General Public License v3.0
Author : helfertool
    def handle(self, *args, **options):
        date = make_aware(options['date'])
        dry_run = options['dry_run']

        # get users which
        # 1. are still active
        # 2. need to be disabled because
        #    a. last login before deadline
        #    b. never logged in but created before deadline
        for u in User.objects.filter(is_active=True).filter(Q(last_login__lt=date) | Q(last_login__isnull=True, date_joined__lt=date)):
            # skip users from external authentication providers
            if u.has_usable_pastword():
                # disable user
                if not dry_run:
                    u.is_active = False
                    u.save()

                # print some nice output
                if u.last_login is None:
                    reason = "never logged in and created at {}".format(u.date_joined)
                else:
                    reason = "last login at {}".format(u.last_login)
                print("{} ({})".format(u.username, reason))