|
|
|
@ -462,6 +462,7 @@ class AdminTransactionViewSet(ModelViewSet): |
|
|
|
""" |
|
|
|
queryset = TransactionParticipant.objects.all() |
|
|
|
serializer_class = AdminTransactionSerializer |
|
|
|
|
|
|
|
permission_classes = [IsAuthenticated, IsSuperAdmin] |
|
|
|
authentication_classes = [TokenAuthentication] |
|
|
|
pagination_class = StandardResultsSetPagination |
|
|
|
@ -476,7 +477,9 @@ class AdminTransactionViewSet(ModelViewSet): |
|
|
|
|
|
|
|
# Search |
|
|
|
search_query = self.request.query_params.get('search', None) |
|
|
|
has_search = False |
|
|
|
if search_query: |
|
|
|
has_search = True |
|
|
|
matching_course_ids = list( |
|
|
|
Course.objects.filter( |
|
|
|
Q(title__icontains=search_query) | |
|
|
|
@ -492,10 +495,19 @@ class AdminTransactionViewSet(ModelViewSet): |
|
|
|
or normalized_search in extract_text_from_json(course.slug).lower() |
|
|
|
] |
|
|
|
|
|
|
|
from django.db.models import Case, When, Value, IntegerField |
|
|
|
queryset = queryset.filter( |
|
|
|
Q(user__fullname__icontains=search_query) | |
|
|
|
Q(user__email__icontains=search_query) | |
|
|
|
Q(course_id__in=matching_course_ids) |
|
|
|
).annotate( |
|
|
|
search_relevance=Case( |
|
|
|
When(user__fullname__icontains=search_query, then=Value(3)), |
|
|
|
When(user__email__icontains=search_query, then=Value(2)), |
|
|
|
When(course_id__in=matching_course_ids, then=Value(1)), |
|
|
|
default=Value(0), |
|
|
|
output_field=IntegerField() |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
# Status filter |
|
|
|
@ -525,5 +537,6 @@ class AdminTransactionViewSet(ModelViewSet): |
|
|
|
if date_before: |
|
|
|
queryset = queryset.filter(created_at__date__lte=date_before) |
|
|
|
|
|
|
|
if has_search: |
|
|
|
return queryset.order_by('-search_relevance', '-created_at') |
|
|
|
return queryset.order_by('-created_at') |
|
|
|
|