Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
return HttpResponse(
json.dumps(data, cls=LazyEncoder),
content_type='application/json')
data.update({
'status': 204,
'error': _('No users registered as `%(username)s` '
'or user is unactived.') % {'username': username}
})
else:
data.update({
'status': 204,
'error': _('Validation Failed for field `username`')
})
return HttpResponse(
json.dumps(data, cls=LazyEncoder),
content_type='application/json')
"""
data = {}
username = request.GET.get('username')
if username is not None \
and username != '' \
and ' ' not in username:
users = User.objects.filter(
Q(username__icontains=username)
).filter(is_active=True)
if users.exists():
data.update({
'status': 200,
'data': [{'username': u.username} for u in users]
})
return HttpResponse(
json.dumps(data, cls=LazyEncoder),
content_type='application/json')
data.update({
'status': 204,
'error': _('No users registered as `%(username)s` '
'or user is unactived.') % {'username': username}
})
else:
data.update({
'status': 204,
'error': _('Validation Failed for field `username`')
})
return HttpResponse(
json.dumps(data, cls=LazyEncoder),
content_type='application/json')
def default(self, obj):
if isinstance(obj, Promise):
return force_text(obj)
return super(LazyEncoder, self).default(obj)