Skip to content

CommunityLibrarySubmission viewset #5167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Jakoma02
Copy link
Contributor

@Jakoma02 Jakoma02 commented Jul 9, 2025

Summary

The PR implements a viewset for managing community library submissions.

Detailed changes:

  • Added CommunityLibrarySubmissionViewset
  • Added a database index for the date_created field to support pagination better
  • Registered the new viewset in a router
  • Added tests for CommunityLibrarySubmissionViewset

The functionality was verified by checking that the new tests pass and by briefly manually testing using the browsable API.

References

Resolves #5157

Reviewer guidance

Nothing

@AlexVelezLl AlexVelezLl linked an issue Jul 11, 2025 that may be closed by this pull request
3 tasks
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 @Jakoma02! This is looking great! I've left just a couple minor comments, the more important one is the potential 500 error that we can have the update method of the serializer. Apart from that everything looks great!

@@ -2616,6 +2616,10 @@ class Meta:
name="unique_channel_with_channel_version",
),
]
indexes = [
# Useful for cursor pagination
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@@ -2655,6 +2659,7 @@ def has_changes(self):

class Meta:
indexes = [
# Useful for cursor pagination
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we introduced and unwanted change here

Copy link
Contributor Author

@Jakoma02 Jakoma02 Jul 12, 2025

Choose a reason for hiding this comment

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

You are right, removed in 6ab6775.

from contentcuration.tests.base import StudioAPITestCase


def reverse_with_query(
Copy link
Member

Choose a reason for hiding this comment

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

Loved it!

Comment on lines 214 to 221
cursor = more["cursor"]

response = self.client.get(
reverse_with_query(
"community-library-submission-list",
query={"max_results": 1, "cursor": cursor},
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Not super important, but just noting that usually the returned more object can be used as the new query param, as it already returns the max_results, and all filters we have applied to the previous request (e.g. if we are filtering by channel, it already returns the channel filter too). So we usually just do something like:

        response = self.client.get(
            reverse_with_query(
                "community-library-submission-list",
                query=more
            )
        )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a neat feature :) Changed in 6ab6775.

return instance

def update(self, instance, validated_data):
if instance.channel.id != validated_data["channel"].id:
Copy link
Member

Choose a reason for hiding this comment

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

This will throw a 500 error for patch operations that don't send the channel in the request.

I know this is different from what is written in the issue, but another Idea would be to just silently remove the channel from the validated_data if it exists, and just prevent channel changes updates altogether. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right; thanks for catching this! I forgot that partial updates are also possible. This is fixed in ba77607.

I kept the provided channel in validated_data so that a more descriptive error is given in case of failure, but I can silently remove it if you like that approach better.

countries = validated_data.pop("countries", [])
instance = super().create(validated_data)

for country in countries:
Copy link
Member

Choose a reason for hiding this comment

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

(nitpick) I think here we can just do instance.countries.set(countries) too right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I have only discovered the set method later and forgot to use it for create as well. Changed in 6ab6775.

Comment on lines 117 to 131
def get_queryset(self):
base_queryset = CommunityLibrarySubmission.objects.all()
user = self.request.user
queryset = CommunityLibrarySubmission.filter_view_queryset(
base_queryset, user
).order_by("-date_created")

return queryset

def get_edit_queryset(self):
base_queryset = CommunityLibrarySubmission.objects.all()
user = self.request.user
queryset = CommunityLibrarySubmission.filter_edit_queryset(base_queryset, user)

return queryset
Copy link
Member

Choose a reason for hiding this comment

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

Oh, we don't need to override these methods, we already have them thanks to our BaseValuesViewset from which the ReadOnlyValuesViewset inherits: https://github.com/jakoma02/studio/blob/9e7c0f7fff6f749bc04b8acb8635f848eaa5823d/contentcuration/contentcuration/viewsets/base.py#L581-L595.

So we can define our base queryset directly as a class property. (e.g. https://github.com/jakoma02/studio/blob/9e7c0f7fff6f749bc04b8acb8635f848eaa5823d/contentcuration/contentcuration/viewsets/assessmentitem.py#L247) and we can apply the order_by there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have completely missed that! Thanks, changed in 6ab6775.

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 great! One more excellent PR! Thanks @Jakoma02!

@AlexVelezLl AlexVelezLl merged commit 4a34ccc into learningequality:community-channels Jul 16, 2025
11 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.

ESoCC: Add viewset for handling Community Library Submissions
2 participants