from django.http import JsonResponse

from web.models.custom_user import CustomUser


def users(request):
    parsed_users = {'users': []}
    admin_only = request.GET.get('admin', False)
    users = CustomUser.objects.filter(is_active=True).filter(groups__name='Member')
    if admin_only == 'true':
        users = users.filter(is_superuser=True)

    users = users.all().values('username', 'description', 'url')
    for user in users:
        parsed_users['users'].append(user)
    return JsonResponse(parsed_users)

