Skip to content

CommunityLibrarySubmission model#5156

Merged
AlexVelezLl merged 8 commits intolearningequality:community-channelsfrom
Jakoma02:community-library-submission-model
Jul 8, 2025
Merged

CommunityLibrarySubmission model#5156
AlexVelezLl merged 8 commits intolearningequality:community-channelsfrom
Jakoma02:community-library-submission-model

Conversation

@Jakoma02
Copy link
Contributor

@Jakoma02 Jakoma02 commented Jul 2, 2025

Summary

I implemented CommunityLibrarySubmission model and tests for it according to specs in #5145.

I have tested the changes by running pytest tests and making sure that the new tests pass and the existing tests do not break, and I have made sure that the devserver still starts.

References

Resolves #5145.

Reviewer guidance

I have decided to override the clean method to validate that the author of the submission should be an editor of the corresponding channel. This cannot be achieved using a database constraint because traversing related fields is not supported inside them. This way, the constraint will be checked when using forms and when explicitly calling full_clean() (not on every save). Please check that this solution matches your expectations.

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 is looking great @Jakoma02! Thanks! Just a couple of nitpick comments, but this is looking great! :)

method is NOT called automatically on every save.
"""
super().clean()
if not self.channel.editors.filter(pk=self.author.pk).exists():
Copy link
Member

Choose a reason for hiding this comment

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

We usually do these validations at api level, but can imagine the benefits of doing this at model level. This doesn't seem to be a common pattern in our codebase thought, would like to hear @rtibbles thoughts, as we may also need to do the check of the version being version > 0 and version <= channel.version

Copy link
Member

@rtibbles rtibbles Jul 7, 2025

Choose a reason for hiding this comment

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

When we have done these kinds of validations on the model itself, we have usually done it in the save method rather than the clean method - for precisely the reasons noted in the docstring - clean is not called on every save, but only when using a Django model form (which we rarely use).

If we want to ensure that this is being used every time we save a model, we should put it in the save method instead, otherwise, I think it would sit better in the API endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, if you agree, I will move the logic to the save method.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, lets move this logic to the save method, along with the version check. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 7f17512 and f0a05eb.

Copy link
Member

Choose a reason for hiding this comment

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

Thank youu! <3 Just one little thing before we merge (I promise this is the last one 😅):

Could you remove the translate function from the error messages? We use to return these validation error messages without translating them e.g. here.

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 removed translation in cb61cb1.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@AlexVelezLl AlexVelezLl requested a review from rtibbles July 7, 2025 14:26
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.

Code changes looks good and tests are passing, the first lines of code of this project are ready to go! Thanks a lot @Jakoma02! Merging!

@AlexVelezLl AlexVelezLl merged commit 98a34e2 into learningequality:community-channels Jul 8, 2025
11 checks passed
@AlexVelezLl AlexVelezLl linked an issue Jul 17, 2025 that may be closed by this pull request
3 tasks
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: Create CommunityLibrarySubmission model

3 participants