[Scodoc-devel] [SVN] Scolar : [1520] Debut implementation tags sur modules pour avis de poursuites d' etude a la grenobloise.

eviennet at lipn.univ-paris13.fr eviennet at lipn.univ-paris13.fr
Dim 10 Juil 19:21:51 CEST 2016


Une pièce jointe HTML a été nettoyée...
URL: <https://www-rt.iutv.univ-paris13.fr/pipermail/scodoc-devel/attachments/20160710/d97baa29/attachment.html>
-------------- section suivante --------------
Modified: branches/ScoDoc7/VERSION.py
===================================================================
--- branches/ScoDoc7/VERSION.py	2016-07-10 13:14:42 UTC (rev 1519)
+++ branches/ScoDoc7/VERSION.py	2016-07-10 17:21:51 UTC (rev 1520)
@@ -1,7 +1,7 @@
 # -*- mode: python -*-
 # -*- coding: utf-8 -*-
 
-SCOVERSION = "7.3a"
+SCOVERSION = "7.4b"
 
 SCONAME = "ScoDoc"
 
@@ -9,9 +9,9 @@
 
 <h5>Année 2016</h4>
 <ul>
+<li>Export des résultats vers Apogée pour un ensemble de semestre.</lI>
 <li>Enregistrement du classement lors de l'admission</li>
 <li>Modification du calcul des coefficients des UE capitalisées</li>
-<li>Archivage des fichiers d'export Apogée</li>
 </ul>
 
 <h4>Année 2015</h4>

Modified: branches/ScoDoc7/config/postupgrade-db.py
===================================================================
--- branches/ScoDoc7/config/postupgrade-db.py	2016-07-10 13:14:42 UTC (rev 1519)
+++ branches/ScoDoc7/config/postupgrade-db.py	2016-07-10 17:21:51 UTC (rev 1520)
@@ -448,6 +448,19 @@
     semset_id text REFERENCES notes_semset (semset_id) ON DELETE CASCADE,
     PRIMARY KEY (formsemestre_id, semset_id)
     ) WITH OIDS;""", ] )
+
+    # ModuleTags
+    check_table( cnx, 'notes_tags', [
+        """CREATE TABLE notes_tags (
+	tag_id text default notes_newid('TAG') PRIMARY KEY,
+    title text UNIQUE NOT NULL
+    ) WITH OIDS;""", ] )
+    check_table( cnx, 'notes_modules_tags', [
+        """CREATE TABLE notes_modules_tags (
+	tag_id text REFERENCES notes_tags(tag_id) ON DELETE CASCADE,
+    module_id text REFERENCES notes_modules(module_id) ON DELETE CASCADE,
+    PRIMARY KEY (tag_id, module_id)
+    ) WITH OIDS;;""", ] )
     
     # Add here actions to performs after upgrades:
     

Modified: branches/ScoDoc7/misc/createtables.sql
===================================================================
--- branches/ScoDoc7/misc/createtables.sql	2016-07-10 13:14:42 UTC (rev 1519)
+++ branches/ScoDoc7/misc/createtables.sql	2016-07-10 17:21:51 UTC (rev 1520)
@@ -323,6 +323,18 @@
     code_apogee text  -- id de l'element pedagogique Apogee correspondant
 ) WITH OIDS;
 
+CREATE TABLE notes_tags (
+	tag_id text default notes_newid('TAG') PRIMARY KEY,
+    title text UNIQUE NOT NULL
+) WITH OIDS;
+
+CREATE TABLE notes_modules_tags (
+	tag_id text REFERENCES notes_tags(tag_id) ON DELETE CASCADE,
+    module_id text REFERENCES notes_modules(module_id) ON DELETE CASCADE,
+    PRIMARY KEY (tag_id, module_id)
+) WITH OIDS;
+    
+
 -- Mise en oeuvre d'un semestre de formation
 CREATE TABLE notes_formsemestre (
 	formsemestre_id text default notes_newid('SEM') PRIMARY KEY,

Added: branches/ScoDoc7/sco_tag_module.py
===================================================================
--- branches/ScoDoc7/sco_tag_module.py	                        (rev 0)
+++ branches/ScoDoc7/sco_tag_module.py	2016-07-10 17:21:51 UTC (rev 1520)
@@ -0,0 +1,158 @@
+# -*- mode: python -*-
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+# Gestion scolarite IUT
+#
+# Copyright (c) 2001 - 2016 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 at viennet.net
+#
+##############################################################################
+
+"""Gestion des tags sur les modules
+
+   Implementation expérimentale (Jul. 2016) pour grouper les modules sur
+   les avis de poursuites d'études.
+"""
+
+from sco_utils import *
+from notesdb import *
+from notes_log import log
+
+# Opérations à implementer:
+#  + liste des modules des formations de code donné (formation_code) avec ce tag
+#  + liste de tous les noms de tag
+#  + tag pour un nom
+#  + creer un tag (nom)
+#  + lier un tag à un module
+#  + enlever un tag d'un module (si c'est le dernier, supprimer le tag lui même)
+
+class ModuleTag:
+    def __init__(self, context, title, module_id=''):
+        """Load tag, or create if does not exist
+        """
+        self.context = context
+        self.title = title.strip()
+        if not self.title:
+            raise ScoValueError('invalid empty tag')
+        r = SimpleDictFetch(context, "SELECT * FROM notes_tags WHERE title = %(title)s",
+                            { 'title' : self.title } )
+        if r:
+            self.tag_id = r[0]['tag_id']
+        else:
+            # Create new tag:
+            cnx = context.GetDBConnexion()
+            oid = DBInsertDict(cnx, 'notes_tags', { 'title' : self.title }, commit=True)
+            self.tag_id = SimpleDictFetch(
+                context, "SELECT tag_id FROM notes_tags WHERE oid=%(oid)s", {'oid':oid})[0]['tag_id']
+        if module_id:
+            self.tag_module(module_id)
+
+    def __repr__(self): # debug
+        return '<tag "%s">' % self.title
+
+    def delete(self):
+        """Delete this tag.
+        This object should not be used after this call !
+        """
+        args = { 'tag_id' : self.tag_id }
+        SimpleQuery(
+            self.context,
+            '''DELETE FROM notes_tags t WHERE t.tag_id = %(tag_id)s''', args )
+    
+    def tag_module(self, module_id):
+        """Associate tag to module"""
+        args = { 'module_id' : module_id, 'tag_id' : self.tag_id }
+        r = SimpleDictFetch(
+            self.context, 
+            '''SELECT * FROM notes_modules_tags mt
+            WHERE mt.module_id = %(module_id)s AND mt.tag_id = %(tag_id)s
+            ''', args )
+        if not r:
+            log('tag module %s with %s' % (module_id, self.title))
+            cnx = self.context.GetDBConnexion()
+            DBInsertDict(cnx, 'notes_modules_tags', args, commit=True)
+    
+    def remove_tag_from_module(self, module_id):
+        """Remove tag from module.
+        If no more modules tagged with this tag, delete it.
+        Return True if Tag still exists.
+        """
+        args = { 'module_id' : module_id, 'tag_id' : self.tag_id }
+        SimpleQuery(
+            self.context,
+            '''DELETE FROM notes_modules_tags mt
+            WHERE mt.module_id = %(module_id)s AND mt.tag_id = %(tag_id)s
+            ''', args )
+        r = SimpleDictFetch(
+            self.context, 
+            '''SELECT * FROM notes_modules_tags mt WHERE tag_id = %(tag_id)s
+            ''', args)
+        if not r:
+            # tag no more used, delete
+            SimpleQuery(
+                self.context,
+                '''DELETE FROM notes_tags t WHERE t.tag_id = %(tag_id)s''', args )
+
+    def list_modules(self, formation_code=''):
+        """Liste des modules des formations de code donné (formation_code) avec ce tag
+        """
+        args = { 'tag_id' : self.tag_id }
+        if not formation_code:
+            # tous les modules de toutes les formations !            
+            r = SimpleDictFetch(
+                self.context, 
+                '''SELECT module_id FROM notes_modules_tags WHERE tag_id = %(tag_id)s
+                ''', args)
+        else:
+            args['formation_code'] = formation_code
+            r = SimpleDictFetch(
+                self.context, 
+                '''SELECT mt.module_id 
+                FROM notes_modules_tags mt, notes_modules m, notes_formations f
+                WHERE mt.tag_id = %(tag_id)s 
+                AND m.module_id = mt.module_id 
+                AND m.formation_id = f.formation_id
+                AND f.formation_code = %(formation_code)s
+                ''', args)
+        return [ x['module_id'] for x in r ]
+        
+def tag_list_all(context):
+    """List all used tag names (for auto-completion)"""
+    r = SimpleDictFetch(context, "SELECT title FROM notes_tags", {})
+    return [ x['title'] for x in r ]
+
+
+"""Tests:
+from debug import *
+from sco_tag_module import *
+context = go_dept(app, 'RT').Notes
+
+t = ModuleTag(context, 'essai')
+t.tag_module('totoro') # error (module invalide)
+t.tag_module('MOD21460')
+t.delete() # detruit tag et assoc
+t = ModuleTag(context, 'essai2')
+t.tag_module('MOD21460')
+t.tag_module('MOD21464')
+t.list_modules()
+t.list_modules(formation_code='ccc') # empty list
+t.list_modules(formation_code='FCOD2')
+tag_list_all(context)
+"""

Modified: branches/ScoDoc7/static/icons/scologo_img.png
===================================================================
(Binary files differ)


Plus d'informations sur la liste de diffusion Scodoc-devel