From c9310d358e16d21a90af61bac95d7684815258b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 4 Jul 2021 12:32:13 +0200 Subject: [PATCH] page accueil ScoDoc8 (prototype) --- app/__init__.py | 9 +++--- app/auth/models.py | 40 ++++++++++++++++++++++++++ app/main/routes.py | 46 +++++++++++++++++++++++++++-- app/scodoc/sco_users.py | 27 +----------------- app/templates/base.html | 7 ++++- app/templates/main/index.html | 18 ++++++++---- app/templates/scodoc.html | 31 ++++++++++++++++++++ app/views/__init__.py | 3 +- app/views/scodoc.py | 54 +++++++++++++++++++++++++++++++++++ scodoc_manager.py | 1 - 10 files changed, 195 insertions(+), 41 deletions(-) create mode 100644 app/templates/scodoc.html create mode 100644 app/views/scodoc.py diff --git a/app/__init__.py b/app/__init__.py index 9c0829367..848d5146d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -72,11 +72,16 @@ def create_app(config_class=Config): app.register_blueprint(essais_bp, url_prefix="/Essais") + from app.main import bp as main_bp + from app.views import scodoc_bp from app.views import scolar_bp from app.views import notes_bp from app.views import users_bp from app.views import absences_bp + app.register_blueprint(main_bp) # XXX à enlever en production #sco8 + # https://scodoc.fr/ScoDoc + app.register_blueprint(scodoc_bp) # https://scodoc.fr/ScoDoc/RT/Scolarite/... app.register_blueprint(scolar_bp, url_prefix="/ScoDoc//Scolarite") # https://scodoc.fr/ScoDoc/RT/Scolarite/Notes/... @@ -88,10 +93,6 @@ def create_app(config_class=Config): absences_bp, url_prefix="/ScoDoc//Scolarite/Absences" ) - from app.main import bp as main_bp - - app.register_blueprint(main_bp) - if not app.debug and not app.testing: if app.config["MAIL_SERVER"]: auth = None diff --git a/app/auth/models.py b/app/auth/models.py index 7b0b2052a..37e687519 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -13,6 +13,7 @@ from time import time from flask import current_app, url_for, g from flask_login import UserMixin, AnonymousUserMixin + from werkzeug.security import generate_password_hash, check_password_hash import jwt @@ -54,6 +55,8 @@ class User(UserMixin, db.Model): self.roles = [] self.user_roles = [] super(User, self).__init__(**kwargs) + self._format_noms() + # Ajoute roles: if ( not self.roles and self.email @@ -127,6 +130,13 @@ class User(UserMixin, db.Model): "prenom": (self.prenom or "").encode("utf-8"), # sco8 "roles_string": self.get_roles_string(), # eg "Ens_RT, Ens_Info" "user_name": self.user_name.encode("utf-8"), # sco8 + # Les champs calculés: + "nom_fmt": self.get_nom_fmt(), + "prenom_fmt": self.get_prenom_fmt(), + "nomprenom": self.get_nomprenom(), + "prenomnom": self.get_prenomnom(), + "nomplogin": self.get_nomplogin(), + "nomcomplet": self.get_nomcomplet(), } if include_email: data["email"] = self.email or "" @@ -151,6 +161,7 @@ class User(UserMixin, db.Model): for r_d in data["roles_string"].split(","): role, dept = UserRole.role_dept_from_string(r_d) self.add_role(role, dept) + self._format_noms() def get_token(self, expires_in=3600): now = datetime.utcnow() @@ -252,6 +263,35 @@ class User(UserMixin, db.Model): else: return None + def get_nom_fmt(self): + """Nom formatté: "Martin" """ + if self.nom: + return sco_etud.format_nom(self.nom, uppercase=False) + else: + return self.user_name + + def get_prenom_fmt(self): + """Prénom formaté (minuscule capitalisées)""" + return sco_etud.format_prenom(self.prenom) + + def get_nomprenom(self): + """Nom capitalisé suivi de l'initiale du prénom: + Viennet E. + """ + prenom_abbrv = scu.abbrev_prenom(sco_etud.format_prenom(self.prenom)) + return (self.get_nom_fmt() + " " + prenom_abbrv).strip() + + def get_prenomnom(self): + """L'initiale du prénom suivie du nom: "J.-C. Dupont" """ + prenom_abbrv = scu.abbrev_prenom(sco_etud.format_prenom(self.prenom)) + return (prenom_abbrv + " " + self.get_nom_fmt()).strip() + + def get_nomcomplet(self): + "Prénom et nom complets" + return sco_etud.format_prenom(self.prenom) + " " + self.get_nom_fmt() + + # nomnoacc était le nom en minuscules sans accents (inutile) + class AnonymousUser(AnonymousUserMixin): def has_permission(self, perm, dept=None): diff --git a/app/main/routes.py b/app/main/routes.py index 5d4b9e5a3..a5cd8af5d 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -1,4 +1,36 @@ -# -*- coding: UTF-8 -* +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +############################################################################## +# +# ScoDoc +# +# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved. +# +# 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 +# +############################################################################## + +""" +Module main: essais divers + +Emmanuel Viennet, 2021 +""" + import pprint from pprint import pprint as pp import functools @@ -10,11 +42,19 @@ import flask from flask import request, render_template, redirect from flask_login import login_required + from app.main import bp - from app.decorators import scodoc7func, admin_required +from app.scodoc import VERSION -context = None +context = None # temporaire pour #sco8 + + +# ------------------------------------------------------------- +# +# ESSAIS DIVERS pour #sco8 +# +# ------------------------------------------------------------- @bp.route("/") diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index fb6416d6d..e32a6373c 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -285,7 +285,7 @@ def user_info(user_name=None, user=None): "nom_fmt": user_name, "nomcomplet": user_name, "nomplogin": user_name, - "nomnoacc": scu.suppress_accents(user_name), + # "nomnoacc": scu.suppress_accents(user_name), "passwd_temp": 0, "status": "", "date_expiration": None, @@ -294,31 +294,6 @@ def user_info(user_name=None, user=None): # Ensure we never publish password hash if "password_hash" in info: del info["password_hash"] - # - p = format_prenom(info["prenom"]) - if info["nom"]: - n = format_nom( - info["nom"], uppercase=False - ) # strcapitalize(strlower(info['nom'])) - else: - n = user_name - - prenom_abbrv = scu.abbrev_prenom(p) - # nomprenom est le nom capitalisé suivi de l'initiale du prénom - info["nomprenom"] = (n + " " + prenom_abbrv).strip() - # prenomnom est l'initiale du prénom suivie du nom - info["prenomnom"] = (prenom_abbrv + " " + n).strip() - # nom_fmt et prenom_fmt: minuscule capitalisé - info["nom_fmt"] = n - info["prenom_fmt"] = sco_etud.format_prenom(p) - # nomcomplet est le prenom et le nom complets - info["nomcomplet"] = info["prenom_fmt"] + " " + info["nom_fmt"] - # nomplogin est le nom en majuscules suivi du prénom et du login - # e.g. Dupont Pierre (dupont) - info["nomplogin"] = "%s %s (%s)" % (scu.strupper(n), p, info["user_name"]) - # nomnoacc est le nom en minuscules sans accents - info["nomnoacc"] = scu.suppress_accents(scu.strlower(info["nom"])) - return info diff --git a/app/templates/base.html b/app/templates/base.html index 33c6df8bb..321d41ac5 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,5 +1,10 @@ {% extends 'bootstrap/base.html' %} +{% block styles %} +{{super()}} + +{% endblock %} + {% block title %} {% if title %}{{ title }} - ScoDoc{% else %}Welcome to ScoDoc{% endif %} {% endblock %} @@ -15,7 +20,7 @@ - ScoDoc + ScoDoc