Here are the examples of the python api django.contrib.auth.models.User.objects.all taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
57 Examples
3
View Complete Implementation : export_users.py
Copyright GNU General Public License v3.0
Author : amfoss
Copyright GNU General Public License v3.0
Author : amfoss
def handle(self, *args, **options):
users = User.objects.all()
usersData = []
for user in users:
userArr = []
userArr.append(user.username)
userArr.append(user.email)
userArr.append(user.first_name)
userArr.append(user.last_name)
usersData.append(userArr)
with open('users.csv', 'w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(usersData)
csvFile.close()
3
View Complete Implementation : permission_backend.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
Copyright GNU Affero General Public License v3.0
Author : archesproject
def get_users_for_object(perm, obj):
"""
returns a list of user objects that have the given permission on the given object
Arguments:
perm -- the permssion string eg: "read_nodegroup"
obj -- the model instance to check
"""
ret = []
for user in User.objects.all():
if user.has_perm(perm, obj):
ret.append(user)
return ret
3
View Complete Implementation : test_urlparser.py
Copyright MIT License
Author : Arello-Mobile
Copyright MIT License
Author : Arello-Mobile
def test_exclude_router_api_root(self):
clast MyViewSet(ModelViewSet):
serializer_clast = CommentSerializer
queryset = User.objects.all()
model = User
router = DefaultRouter()
router.register('test', MyViewSet, base_name='test_base_name')
urls_created = len(router.urls)
apis = self.urlparser.get_apis(router.urls)
self.astertEqual(4, urls_created - len(apis))
3
View Complete Implementation : models.py
Copyright MIT License
Author : ArnaudLevaufre
Copyright MIT License
Author : ArnaudLevaufre
def __call__(self, request, *args, **kwargs):
key = request.GET.get('key')
if not key:
return HttpResponse(status=401)
for user in User.objects.all():
if key == str(user.profile.api_key):
break
else:
return HttpResponse(status=401)
return super().__call__(request, *args, **kwargs)
3
View Complete Implementation : create_usersettings.py
Copyright MIT License
Author : Arx-Game
Copyright MIT License
Author : Arx-Game
def handle(self, *args, **options):
"handle command line"
for u in User.objects.all():
try:
s = UserSettings.objects.get(user=u)
except UserSettings.DoesNotExist:
s = UserSettings(user=u, settings=DEFAULT_USER_SETTINGS)
s.save()
3
View Complete Implementation : create_default_project.py
Copyright BSD 2-Clause "Simplified" License
Author : awemulya
Copyright BSD 2-Clause "Simplified" License
Author : awemulya
def handle(self, *args, **options):
print "Task started ..."
# Get all the users
for user in queryset_iterator(User.objects.all()):
# For each user get the forms which are projectless
for form in queryset_iterator(XForm.objects
# JNM TEMPORARY
#.select_related('projectxform')
.filter(projectxform=None,
user=user)):
# Create the default project
self.create_and_astign_project(user, form)
print "Task completed ..."
3
View Complete Implementation : views.py
Copyright MIT License
Author : CodeForPhilly
Copyright MIT License
Author : CodeForPhilly
def get_queryset(self):
username = self.request.query_params.get('username', None)
first_name = self.request.query_params.get('first_name', None)
last_name = self.request.query_params.get('last_name', None)
groups = self.request.query_params.get('groups', None)
pk = self.request.query_params.get('pk', None)
queryset = User.objects.all()
if username is not None:
queryset = queryset.filter(username__iexact=username)
if first_name is not None:
queryset = queryset.filter(first_name__iexact=first_name)
if last_name is not None:
queryset = queryset.filter(last_name__iexact=last_name)
if pk is not None:
queryset = queryset.filter(id=pk)
if groups is not None:
queryset = queryset.filter(role__role_value__icontains=groups)
return queryset
3
View Complete Implementation : test_basic.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
@override_settings(AUTH_USER_MODEL='auth.CustomUser')
def test_swappable_user(self):
"The current user model can be swapped out for another"
self.astertEqual(get_user_model(), CustomUser)
with self.astertRaises(AttributeError):
User.objects.all()
3
View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : elastic
Copyright BSD 3-Clause "New" or "Revised" License
Author : elastic
def render_user_view(request):
def something_expensive():
with elasticapm.capture_span("something_expensive", "code"):
for i in range(100):
users = list(User.objects.all())
return users
return render(request, "list_users.html", {"users": something_expensive})
3
View Complete Implementation : rule_is_tests.py
Copyright MIT License
Author : excitedleigh
Copyright MIT License
Author : excitedleigh
@pytest.mark.django_db
def test_current_user():
u1 = UserFactory()
u2 = UserFactory()
astert current_user.check(u1, u1)
astert not current_user.check(u1, u2)
astert set(current_user.filter(u1, User.objects.all())) == {u1}