From 8fad557345adb4d5181e3468df10c81b060ec0f1 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Fri, 9 Dec 2016 20:49:29 +0100 Subject: web: show only feed-items with more than one version --- watchnews/web.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'watchnews') diff --git a/watchnews/web.py b/watchnews/web.py index c687120..2699554 100644 --- a/watchnews/web.py +++ b/watchnews/web.py @@ -3,6 +3,7 @@ from . import data, css from ll.xist import xsc, parse from ll.xist.ns import html, chars from flask import Flask, url_for +import peewee import re import difflib @@ -66,7 +67,7 @@ class DiffSupport: if line != '': # trailing unchanged text elems += [html.span(line)] - + elems += [ html.br() ] return elems @@ -218,9 +219,15 @@ def get_app(): @app.route('/feed/') def feed(id): feed = data.Feed.get(data.Feed.id == id) - items = data.Item.select() \ - .where(data.Item.feed == feed) \ - .order_by(data.Item.created_date.desc()) + counts = (data.Version.select(data.Version.item.alias('item_id'), + peewee.fn.Count(data.Version.id).alias('count')) + .group_by(data.Version.item) + .alias('counts')) + + items = (data.Item.select() + .join(counts, on=(data.Item.id == counts.c.item_id)) + .where((data.Item.feed == feed) & (counts.c.count > 1)) + .order_by(data.Item.created_date.desc())) return Template.feed(feed, items).string('utf-8') @app.route('/item/') -- cgit v1.2.1