Repository navigation
Conversation
Reviewer's GuideEnsures public post listings only show currently published posts by filtering on publication date range, and stabilizes test data by using deterministic publication dates and adding coverage for the new filtering behavior. Sequence diagram for public post listing with publication date filteringsequenceDiagram
actor PublicUser
participant Browser
participant PostListView
participant PostContent_manager
participant Database
PublicUser->>Browser: Request_stories_listing
Browser->>PostListView: HTTP_GET /stories/
PostListView->>PostListView: get_queryset()
PostListView->>PostContent_manager: model.objects.all()
PostContent_manager->>Database: SELECT * FROM postcontent
Database-->>PostContent_manager: All_PostContent_rows
PostListView->>PostContent_manager: filter(date_published_lte_now, date_published_end_null_or_gt_now)
PostContent_manager->>Database: SELECT ... WHERE post.date_published <= now AND (post.date_published_end IS NULL OR post.date_published_end > now)
Database-->>PostContent_manager: Currently_published_PostContent
PostListView->>PostContent_manager: filter(language, namespace)
PostContent_manager->>Database: SELECT ... WHERE language = request_language AND app_config.namespace = view_namespace
Database-->>PostContent_manager: Localized_namespace_posts
PostListView-->>Browser: Rendered_list_template
Browser-->>PublicUser: Page_with_only_currently_published_posts
Updated class diagram for post content listing and publication datesclassDiagram
class Post {
DateTimeField date_published
DateTimeField date_published_end
}
class PostAppConfig {
CharField namespace
}
class PostContent {
CharField language
ForeignKey post
ForeignKey app_config
}
class PostContentManager {
QuerySet all()
}
class PostContentAdminManager {
QuerySet latest_content()
}
class PostListView {
get_queryset()
}
PostContent "*" --> "1" Post
Post "1" --> "1" PostAppConfig
PostContent "*" --> "1" PostAppConfig
PostContent --> PostContentManager : objects
PostContent --> PostContentAdminManager : admin_manager
PostListView --> PostContent : model
PostListView ..> Post : filters_by_date_published
PostListView ..> Post : filters_by_date_published_end
PostListView ..> PostContent : filters_by_language
PostListView ..> PostAppConfig : filters_by_namespace
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
views.pyyou remove thefrom cms.utils import get_current_siteimport but still callsite_compatibility_decorator(get_current_site), which will raise aNameError; either keep the import or rename the wrapped variable to avoid shadowing and ensure the correct function is passed in.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `views.py` you remove the `from cms.utils import get_current_site` import but still call `site_compatibility_decorator(get_current_site)`, which will raise a `NameError`; either keep the import or rename the wrapped variable to avoid shadowing and ensure the correct function is passed in.
## Individual Comments
### Comment 1
<location path="djangocms_stories/views.py" line_range="125-127" />
<code_context>
queryset = self.model.admin_manager.latest_content()
else:
queryset = self.model.objects.all()
+ queryset = queryset.filter(
+ Q(post__date_published__lte=current_time),
+ Q(post__date_published_end__isnull=True) | Q(post__date_published_end__gt=current_time),
+ )
+
</code_context>
<issue_to_address>
**issue:** Consider whether items with date_published_end exactly equal to `current_time` should be treated as expired.
Because the filter uses `post__date_published_end__gt=current_time`, posts ending exactly at `current_time` will not be returned. If the end timestamp is meant to be inclusive, switch to `gte`; if it’s meant to be exclusive, consider documenting that assumption to prevent future off‑by‑one timing issues.
</issue_to_address>
### Comment 2
<location path="tests/test_views.py" line_range="103-112" />
<code_context>
+ assert expired_post.title not in content
+
+
@pytest.mark.django_db
def test_post_archive_view(admin_client, admin_user, default_config):
"""
</code_context>
<issue_to_address>
**suggestion (testing):** Add a complementary test to verify that future-dated posts are excluded from the public list view
You can mirror this test by creating a post with `date_published = now() + timedelta(days=1)` and a valid `date_published_end`, marking it as published, then asserting its title is absent from the public `client` response (e.g. in `test_post_list_view_filters_out_future_posts`). That will ensure future-dated content can’t accidentally appear in public views.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
==========================================
- Coverage 90.94% 89.41% -1.53%
==========================================
Files 24 24
Lines 2309 2325 +16
Branches 276 281 +5
==========================================
- Hits 2100 2079 -21
- Misses 126 160 +34
- Partials 83 86 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@dnlzrgz Nice PR! Thank you! I appreciate the use of django ORM features to fix the visibility and sorting issues. There's a package called djangocms-timed-publishing which is an extension to djangocms-verisoning and adds precisely the feature of making published content only visible after and/or before a certain date. We might need to think on how to align those features. Would you mind having a look at djangocms-timed-publishing ? |
|
Thanks for the comment @fsbraun! I took a look at the I feel like My proposal would be then to ensure that Let me know if this approach sounds good to you! |
|
OK, let's avoid the "being broken by default". For now, can we check for |
|
To not make things messier these are the changes I will make if everything looks good to you:
#...
if hasattr(self.request, "toolbar") and (
self.request.toolbar.edit_mode_active or self.request.toolbar.preview_mode_active
):
queryset = self.model.admin_manager.latest_content()
else:
queryset = self.model.objects.all()
if not apps.is_installed("djangocms_timed_publishing"):
queryset = queryset.filter(
Q(post__date_published__lte=current_time) | Q(post__date_published__isnull=True),
Q(post__date_published_end__isnull=True) | Q(post__date_published_end__gt=current_time),
)
#...
This PR feels a bit "spaghetti" to me but I haven't been able to come up with a better solution. |
|
There is a failling test in I got a bit lost in some parts but I think everything should be good now. Edit: I just merged the 'main' branch so maybe the failing test I mentioned is fixed now. |
|
@dnlzrgz Can you take another look at the failing tests? It seems to be influenced by the django CMS version. |
|
Hey @fsbraun, thanks for the patience. I have been trying to understand what is failing and why but so far I haven't been able to replicate the CI results on my machine (even after purging the environment, setting a new one, and doing a fresh install). All tests pass on my end. I checked if maybe Any guidance on what to look at next would be greatly appreciated! |
Description
This PR fixes the issue about expired or future posts being visible to public users. I also updated how test data is generated because the previous "random" dates were causing inconsistently fails after the fix was applied.
Since both issues are related, I decided to solve the date fallback problem when sorting and I realized that I had introduced a subtle bug that caused posts without a
post__date_publishedto be filtered out. Both the filtering and the ordering logic should be correct now.Related resources
post__date_publishedappear first despite descending order #55Checklist
masterDiscord to find a “pr review buddy” who is going to review my pull request.
Summary by Sourcery
Ensure public post listings only include currently published stories and add coverage for publication window filtering.
Bug Fixes:
Tests:
Summary by Sourcery
Ensure public post views expose only currently available posts while retaining correct fallback ordering and compatible admin fields.
Bug Fixes:
Enhancements:
Tests: