From 8923720776f4305f84207a9d81ecb48fed3fc2cd Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 13 Aug 2021 11:26:22 +0200 Subject: [PATCH] =?UTF-8?q?news=20par=20d=C3=A9partement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/events.py | 1 + app/scodoc/sco_news.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/events.py b/app/models/events.py index b2c9ca794..0cdd7e930 100644 --- a/app/models/events.py +++ b/app/models/events.py @@ -28,6 +28,7 @@ class ScolarNews(db.Model): __tablename__ = "scolar_news" id = db.Column(db.Integer, primary_key=True) + dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True) date = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) authenticated_user = db.Column(db.Text) # login, sans contrainte # type in 'INSCR', 'NOTES', 'FORM', 'SEM', 'MISC' diff --git a/app/scodoc/sco_news.py b/app/scodoc/sco_news.py index 4f2ddfb64..214b95fd6 100644 --- a/app/scodoc/sco_news.py +++ b/app/scodoc/sco_news.py @@ -31,13 +31,12 @@ import datetime import re import time -from io import StringIO from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.header import Header from operator import itemgetter -import six +from flask import g from flask_login import current_user import app.scodoc.sco_utils as scu @@ -55,6 +54,7 @@ _scolar_news_editor = ndb.EditableTable( "scolar_news", "news_id", ("date", "authenticated_user", "type", "object", "text", "url"), + filter_dept=True, sortkey="date desc", output_formators={"date": ndb.DateISOtoDMY}, input_formators={"date": ndb.DateDMYtoISO}, @@ -119,7 +119,14 @@ def scolar_news_summary(context, n=5): cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) - cursor.execute("select * from scolar_news order by date desc limit 100") + cursor.execute( + """SELECT id AS news_id, * + FROM scolar_news + WHERE dept_id=%(dept_id)s + ORDER BY date DESC LIMIT 100 + """, + {"dept_id": g.scodoc_dept_id}, + ) selected_news = {} # (type,object) : news dict news = cursor.dictfetchall() # la plus récente d'abord