Skip to content

Commit 9798e9e

Browse files
authored
Merge pull request #166 from Xpirix/fix_upcoming_news_not_showing
Add regression test for feed entries and update query logic
2 parents 8f9f644 + 223d13d commit 9798e9e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

qgisfeedproject/qgisfeed/tests.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,33 @@ def test_after(self):
232232
titles = [d["title"] for d in data]
233233
self.assertFalse("Null Island QGIS Hackfest" in titles)
234234

235+
def test_upcoming_feed_becomes_active(self):
236+
"""Test that entries whose publish_from falls between `after` and now
237+
are included for QGIS >= 3.36, even if their modified date predates `after`.
238+
Regression test for https://github.com/qgis/QGIS-Feed-Website/issues/164
239+
"""
240+
c = Client(
241+
HTTP_USER_AGENT="Mozilla/5.0 QGIS/33600/Fedora "
242+
"Linux (Workstation Edition)"
243+
)
244+
# Simulate an entry that was created in the past, scheduled to publish later,
245+
# but is now active: modified=2025-01-01, publish_from=2025-06-01.
246+
# QGIS last checked on 2025-02-01 (after=2025-02-01).
247+
# modified (2025-01-01) < after (2025-02-01), so the old query would miss it.
248+
# publish_from (2025-06-01) is between after and now, so it must be included.
249+
with connection.cursor() as cursor:
250+
cursor.execute(
251+
"UPDATE qgisfeed_qgisfeedentry "
252+
"SET publish_from='2025-06-01', modified='2025-01-01', "
253+
"publish_to=NULL, published=True "
254+
"WHERE title='QGIS Italian Meeting'"
255+
)
256+
# after = 2025-02-01, before publish_from but after modified
257+
response = c.get("/?after=%s" % timezone.datetime(2025, 2, 1).timestamp())
258+
data = json.loads(response.content)
259+
titles = [d["title"] for d in data]
260+
self.assertIn("QGIS Italian Meeting", titles)
261+
235262
def test_invalid_parameters(self):
236263
c = Client(
237264
HTTP_USER_AGENT="Mozilla/5.0 QGIS/32400/Fedora "

qgisfeedproject/qgisfeed/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ def get(self, request):
177177
else:
178178
qs = QgisFeedEntry.objects.all()
179179
now = timezone.now()
180-
qs = qs.filter(modified__gte=after, published=True).exclude(
181-
publish_from__gte=now
180+
# Include entries modified since `after`, OR entries whose publish_from
181+
# fell between `after` and now (entries that became active since last check).
182+
qs = (
183+
qs.filter(published=True)
184+
.exclude(publish_from__gte=now)
185+
.filter(Q(modified__gte=after) | Q(publish_from__gte=after))
182186
)
183187

184188
# Get filters for lang and lat/lon

0 commit comments

Comments
 (0)