Repository: getnikola/nikola

Issue:
Wrong filter order in post_list plugin
## 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

``` rest
.. 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

``` diff
--- 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:
```



Discussion:
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`)


Resolving patch:
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -129,6 +129,7 @@ def run(self):
         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,20 @@ def run(self):
         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:


Test patch: