forked from ScoDoc/ScoDoc
news par département
This commit is contained in:
parent
0b0259997f
commit
8923720776
@ -28,6 +28,7 @@ class ScolarNews(db.Model):
|
|||||||
|
|
||||||
__tablename__ = "scolar_news"
|
__tablename__ = "scolar_news"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
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())
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
||||||
authenticated_user = db.Column(db.Text) # login, sans contrainte
|
authenticated_user = db.Column(db.Text) # login, sans contrainte
|
||||||
# type in 'INSCR', 'NOTES', 'FORM', 'SEM', 'MISC'
|
# type in 'INSCR', 'NOTES', 'FORM', 'SEM', 'MISC'
|
||||||
|
@ -31,13 +31,12 @@ import datetime
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from io import StringIO
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import six
|
|
||||||
|
|
||||||
|
from flask import g
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
@ -55,6 +54,7 @@ _scolar_news_editor = ndb.EditableTable(
|
|||||||
"scolar_news",
|
"scolar_news",
|
||||||
"news_id",
|
"news_id",
|
||||||
("date", "authenticated_user", "type", "object", "text", "url"),
|
("date", "authenticated_user", "type", "object", "text", "url"),
|
||||||
|
filter_dept=True,
|
||||||
sortkey="date desc",
|
sortkey="date desc",
|
||||||
output_formators={"date": ndb.DateISOtoDMY},
|
output_formators={"date": ndb.DateISOtoDMY},
|
||||||
input_formators={"date": ndb.DateDMYtoISO},
|
input_formators={"date": ndb.DateDMYtoISO},
|
||||||
@ -119,7 +119,14 @@ def scolar_news_summary(context, n=5):
|
|||||||
|
|
||||||
cnx = ndb.GetDBConnexion()
|
cnx = ndb.GetDBConnexion()
|
||||||
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
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
|
selected_news = {} # (type,object) : news dict
|
||||||
news = cursor.dictfetchall() # la plus récente d'abord
|
news = cursor.dictfetchall() # la plus récente d'abord
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user