Skip to content

Commit

Permalink
fix: more in progress stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 committed Nov 13, 2024
1 parent fdbb35c commit 52a91e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
62 changes: 16 additions & 46 deletions enterprise/api/v1/views/enterprise_customer_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from django.contrib import auth
from django.core.exceptions import ValidationError
from django.db.models import Case, CharField, Q, Value, When
from django.db.models import Case, CharField, F, Q, Value, When

from enterprise import models
from enterprise.api.v1 import serializers
Expand Down Expand Up @@ -73,36 +73,9 @@ def filter_queryset_by_user_query(self, queryset):
user_query = self.request.query_params.get("user_query", None)
if user_query:
queryset = queryset.filter(
# Q(user_email__icontains=user_query) #Q(name__icontains=user_query) |
Q(user_email__icontains=user_query) | Q(name__icontains=user_query)
)
return queryset


# user_id__in=User.objects.filter(
# Q(first_name__icontains=user_query) | Q(last_name__icontains=user_query) |
# Q(email__icontains=user_query)
# )
# )
# user_profiles = queryset.filter(
# user_id__in=UserProfile.objects.filter(
# Q(name__icontains=user_query)
# )
# )
# return users | user_profiles
return queryset

# queryset1 = models.EnterpriseCustomerUser.objects.filter(
# user_id__in=User.objects.filter(
# Q(first_name__icontains=user_query) | Q(last_name__icontains=user_query) |
# Q(email__icontains=user_query)
# )
# )
# queryset2 = models.EnterpriseCustomerUser.objects.filter(
# user_id__in=UserProfile.objects.filter(
# Q(name__icontains=user_query)
# )
# )
# return queryset1 | queryset2

def get_members(self, request, *args, **kwargs):
"""
Expand All @@ -114,7 +87,8 @@ def get_members(self, request, *args, **kwargs):
# Because our main User table is not in this repo, and isn't connected through
# a foreign key (like enterprise_customer) and only the user_id attribute, we
# have to use django's extra() function in order to sort on the name before
# pagination.
# pagination. Not everyone has first and last filled out, so we also have to
# fetch the name from userprofile as well
enterprise_customer_queryset = models.EnterpriseCustomerUser.objects.filter(
enterprise_customer__uuid=enterprise_uuid
).extra(
Expand All @@ -127,22 +101,23 @@ def get_members(self, request, *args, **kwargs):
where=['auth_userprofile.user_id = enterprise_enterprisecustomeruser.user_id']
)

# print(enterprise_customer_queryset[0].first_name)
# raise Exception(enterprise_customer_queryset[0].first_name)

enterprise_customer_queryset = enterprise_customer_queryset.annotate(
# linkable=Case(
# When(is_relinkable=True, then=Value(1)),
# default=Value(0),
# raise Exception(enterprise_customer_queryset[0].__dir__())
print('hi kira!')
print('first name', enterprise_customer_queryset[0].first_name)
print('last name', enterprise_customer_queryset[0].last_name)
print('full name', enterprise_customer_queryset[0].full_name)


# )
# We need to combine users with first/last and full into one 'name'
# column, so then we can order by that
enterprise_customer_queryset = enterprise_customer_queryset.annotate(
name=Case(
When(full_name=None, then=Value('first_name' + ' ' + 'last_name')),
default=Value(0),
When(full_name__isnull=True,first_name__isnull=False, then=F('first_name') + ' ' + F('last_name')),
When(first_name__isnull=True,full_name__isnull=False, then=F('full_name')),
default=Value(None),
output_field=CharField(),
)
).order_by('name')
print(enterprise_customer_queryset[0]['name'])

enterprise_customer_queryset = self.filter_queryset_by_user_query(
enterprise_customer_queryset
Expand All @@ -156,11 +131,6 @@ def get_members(self, request, *args, **kwargs):
status=status.HTTP_404_NOT_FOUND,
)

#alred g
#zane b
#alan


# paginate the queryset
users_page = self.paginator.paginate_queryset(users, request, view=self)

Expand Down
1 change: 0 additions & 1 deletion enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
LOGGER = getEnterpriseLogger(__name__)
User = auth.get_user_model()
mark_safe_lazy = lazy(mark_safe, str)
FAKER = FakerFactory.create()


class EnterpriseCustomerManager(models.Manager):
Expand Down

0 comments on commit 52a91e9

Please sign in to comment.