Skip to content

Conversation

@taoerman
Copy link
Member

Summary

Renames date_resolved to Test Filtering And Search with database indexes for performance, adds FilterSet with date range and status filters plus channel name search, and makes resolved_by visible to editors.

References

Fixed #5456

Reviewer guidance

Run unit tests.

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Eddie! Looking good! Just one major concern now that we are treating this date_updated field, we need to use the auto_now arg.

Comment on lines 2706 to 2709
indexes = [
# Useful for cursor pagination
models.Index(fields=["-date_created"], name="submission_date_created_idx"),
models.Index(fields=["-date_updated"], name="submission_date_updated_idx"),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are already specifying this index in the field definition, I think we can remove this one here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed!

Comment on lines 1 to 7
import django_filters
from django.utils import timezone
from django_filters import DateTimeFilter
from django_filters import MultipleChoiceFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.decorators import action
from rest_framework.filters import SearchFilter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we import these (and the FilterSet class) from django_filters.rest_framework instead? Since these aaddmore context for DRF

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed!


date_updated__lte = DateTimeFilter(field_name="date_updated", lookup_expr="lte")
date_updated__gte = DateTimeFilter(field_name="date_updated", lookup_expr="gte")
status__in = MultipleChoiceFilter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Apologies, I didn't note this 😅) But could we create a ChoiceInFilter class for this instead? Something like this

This way ⬆️ we can pass these statuses in a single query param like status="STATUS_A,STATUS_B" instead of using multiple query params like status="STATUS_A"&status="STATUS_B", which is not the most idiomatic way to handle in the frontend.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, fixed!

categories = models.JSONField(blank=True, null=True)
date_created = models.DateTimeField(auto_now_add=True)
date_resolved = models.DateTimeField(blank=True, null=True)
date_updated = models.DateTimeField(blank=True, null=True, db_index=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we also need an auto_now=True argument so that this field gets updated automatically every time an instance is updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

date_created=datetime.datetime(2023, 1, 1, tzinfo=pytz.utc),
)
self.old_pending_submission.date_updated = datetime.datetime(
2023, 1, 1, tzinfo=pytz.utc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the update on the date_updated field, we will need to mock the django.utils.timezone.now function to set this date_updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!



def get_resolved_by_name(item):
if item.get("resolved_by__first_name") and item.get("resolved_by__last_name"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip this validation, just in case we have just the name or last name of a user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the function, now this function will return:

      - If both names exist: returns "First Last"
      - If only first name exists: returns "First"
      - If only last name exists: returns "Last"
      - If neither exists: returns None

Comment on lines 309 to 311
date_updated = timezone.now()
submission = serializer.save(
date_resolved=date_resolved,
date_updated=date_updated,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the changes on the auto_now we now may not even need to set this date here :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, Thanks!

"resolved_by_id",
"resolved_by__first_name",
"resolved_by__last_name",
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, something I did not see when planning this issue, we'll need to return the channel__name here too to get the channel name directly. And add this to the field_map to return this field without the double underscore. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, thanks!

@AlexVelezLl
Copy link
Member

Thanks @taoerman! It seems like there are some failing tests on the last commit. Could you take a look at it, please? Thanks!

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks @taoerman! Just one last thing: Could we consolidate the migrations 0159 and 0160 into just one migration? They are both related, and the reason why they are separated is because of the code review, so logically as the result of this PR, there should only be one. Thanks!

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @taoerman! LGTM!

@AlexVelezLl AlexVelezLl merged commit da5fb15 into learningequality:unstable Dec 1, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update CommunityLibraryViewset to support notifications filtering

2 participants