Skip to content
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

Wrong filter order in post_list plugin #1365

Closed
CarstenGrohmann opened this issue Jul 19, 2014 · 1 comment · Fixed by #1366
Closed

Wrong filter order in post_list plugin #1365

CarstenGrohmann opened this issue Jul 19, 2014 · 1 comment · Fixed by #1366
Assignees
Milestone

Comments

@CarstenGrohmann
Copy link
Contributor

Desc

I want to include the newest post with tag "games". But the newest "games" post isn't the newest post at all. The rest directive post_list (example below) doesn't return anything. It's caused by timeline filtering first.

The plugin should filter for tags first and apply the timeline filter in a second step.

Details to reproduce

Existing posts

  • 20140719.news: tag: news
  • 20140630.news: tag: photos
  • 20140615.news: tag: games

Rest directive

.. post-list::
   :start: 0
   :stop: 1
   :tags: games

Result

None

Expected Result

headline and date of 20140615.news

A fix may base on this patch

--- post_list.py.old    2014-07-19 08:59:55.814081440 +0200
+++ post_list.py    2014-07-19 08:49:48.887397065 +0200
@@ -129,6 +129,7 @@
         else:
             post_list_id = self.options.get('id', 'post_list_' + uuid.uuid4().hex)

+        filtered_timeline = []
         posts = []
         step = -1 if reverse is None else None
         if show_all is None:
@@ -136,16 +137,21 @@
         else:
             timeline = [p for p in self.site.timeline if p.use_in_feeds]

-        for post in timeline[start:stop:step]:
+        for post in timeline:
             if tags:
                 cont = True
+                tags_lower = [t.lower() for t in post.tags]
                 for tag in tags:
-                    if tag in [t.lower() for t in post.tags]:
+                    if tag in tags_lower:
                         cont = False

                 if cont:
                     continue

+            filtered_timeline.append(post)
+
+        for post in filtered_timeline[start:stop:step]:
+
             if slugs:
                 cont = True
                 for slug in slugs:
@Kwpolska Kwpolska added the bug label Jul 19, 2014
@Kwpolska Kwpolska added this to the v7.0.2 milestone Jul 19, 2014
@Kwpolska
Copy link
Member

Your patch looks sane. Send a pull request with this exact patch, and also an appropriate entry in CHANGES.txt and AUTHORS.txt. (though you may want to drop the extra newline after the filtered_timeline for)

@Kwpolska Kwpolska self-assigned this Jul 19, 2014
Kwpolska added a commit that referenced this issue Jul 19, 2014
Fixed wrong filter order in post_list plugin (Issue #1365)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants