ScoDoc-Lille/app/scodoc/scolog.py

69 lines
2.2 KiB
Python
Raw Permalink Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2022-01-01 14:49:42 +01:00
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
"""Logging des opérations en base de données
"""
2020-09-26 16:19:37 +02:00
2021-07-31 18:01:10 +02:00
from flask import request
from flask_login import current_user
import app.scodoc.notesdb as ndb
2020-09-26 16:19:37 +02:00
2021-07-31 18:01:10 +02:00
def logdb(cnx=None, method=None, etudid=None, msg=None, commit=True):
"Add entry"
2020-09-26 16:19:37 +02:00
if not cnx:
raise ValueError("logdb: cnx is None")
2021-07-31 18:01:10 +02:00
args = {
"authenticated_user": current_user.user_name,
}
2020-09-26 16:19:37 +02:00
args.update({"method": method, "etudid": etudid, "msg": msg})
2021-02-03 22:00:41 +01:00
ndb.quote_dict(args)
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
2020-09-26 16:19:37 +02:00
cursor.execute(
"""INSERT INTO scolog
2021-08-10 12:57:38 +02:00
(authenticated_user,method,etudid,msg)
VALUES
2021-08-10 12:57:38 +02:00
(%(authenticated_user)s,%(method)s,%(etudid)s,%(msg)s)""",
2020-09-26 16:19:37 +02:00
args,
)
if commit:
cnx.commit()
def loglist(cnx, method=None, authenticated_user=None):
2021-01-01 18:40:47 +01:00
"""List of events logged for these method and user"""
2021-02-03 22:00:41 +01:00
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
2020-09-26 16:19:37 +02:00
cursor.execute(
"""SELECT * FROM scolog
WHERE method=%(method)s
AND authenticated_user=%(authenticated_user)s""",
2020-09-26 16:19:37 +02:00
{"method": method, "authenticated_user": authenticated_user},
)
return cursor.dictfetchall()