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

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

7 Examples 7

3 View Complete Implementation : test_user.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_list_for_admin(self):
        admin = factory.make_admin()
        handler = UserHandler(admin, {}, None)
        factory.make_User()
        expected_users = [
            self.dehydrate_user(user, for_self=(user == admin))
            for user in User.objects.exclude(username__in=SYSTEM_USERS)
        ]
        self.astersatemsEqual(expected_users, handler.list({}))

3 View Complete Implementation : delete_non_staff.py
Copyright Mozilla Public License 2.0
Author : mozilla
def delete_non_staff():
    print("\nDeleting non staff users")
    group_q = Group.objects.all()
    non_staff = User.objects.exclude(
        Q(email__endswith='@mozillafoundation.org') |
        Q(is_staff=True) |
        Q(groups__in=group_q)
    )

    if non_staff:
        print('Deleting:', ', '.join([e.username for e in non_staff]))
        non_staff.delete()
    else:
        print('Nothing to delete')
    print("Done!")

0 View Complete Implementation : admin.py
Copyright Apache License 2.0
Author : edisonlz
    def save_model(self, request, obj, form, change):
        """
        Saves the message for the recipient and looks in the form instance
        for other possible recipients. Prevents duplication by excludin the
        original recipient from the list of optional recipients.

        When changing an existing message and choosing optional recipients,
        the message is effectively resent to those users.
        """
        obj.save()
        
        if notification:
            # Getting the appropriate notice labels for the sender and recipients.
            if obj.parent_msg is None:
                sender_label = 'messages_sent'
                recipients_label = 'messages_received'
            else:
                sender_label = 'messages_replied'
                recipients_label = 'messages_reply_received'
                
            # Notification for the sender.
            notification.send([obj.sender], sender_label, {'message': obj,})

        if form.cleaned_data['group'] == 'all':
            # send to all users
            recipients = User.objects.exclude(pk=obj.recipient.pk)
        else:
            # send to a group of users
            recipients = []
            group = form.cleaned_data['group']
            if group:
                group = Group.objects.get(pk=group)
                recipients.extend(
                    list(group.user_set.exclude(pk=obj.recipient.pk)))
        # create messages for all found recipients
        for user in recipients:
            obj.pk = None
            obj.recipient = user
            obj.save()

            if notification:
                # Notification for the recipient.
                notification.send([user], recipients_label, {'message' : obj,})

0 View Complete Implementation : views.py
Copyright MIT License
Author : InternetSemLimites
def _get_admin_emails():
    for user in User.objects.exclude(email=''):
        yield user.email

0 View Complete Implementation : mixins.py
Copyright MIT License
Author : InternetSemLimites
    def get_email_to(self):
        for user in User.objects.exclude(email=''):
            yield user.email

0 View Complete Implementation : migration.py
Copyright GNU Affero General Public License v3.0
Author : maas
def get_real_users():
    """Returns a `QuerySet` of real. not system, users."""
    users = User.objects.exclude(username__in=SYSTEM_USERS)
    users = users.exclude(username=legacy_user_name)
    return users

0 View Complete Implementation : views.py
Copyright MIT License
Author : thetruefuss
    def get_queryset(self, **kwargs):
        return User.objects.exclude(username=self.request.user.username)