[Scodoc-devel] [SVN] Scolar : [1538] - autocomplete simple sur recherche etudiant par nom

eviennet at lipn.univ-paris13.fr eviennet at lipn.univ-paris13.fr
Mar 26 Juil 15:46:28 CEST 2016


Une pièce jointe HTML a été nettoyée...
URL: <https://www-rt.iutv.univ-paris13.fr/pipermail/scodoc-devel/attachments/20160726/d995e78c/attachment.html>
-------------- section suivante --------------
Modified: branches/ScoDoc7/ZAbsences.py
===================================================================
--- branches/ScoDoc7/ZAbsences.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/ZAbsences.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -836,7 +836,6 @@
             gr_tit = p + '<span class="fontred">' + groups_infos.groups_titles + '</span>'
         
         H = [ self.sco_header(page_title='Saisie hebdomadaire des absences',
-                              init_jquery_ui=True,
                               init_qtip=True,
                               javascripts=[
                                   'js/etud_info.js',
@@ -967,7 +966,6 @@
             
         
         H = [ self.sco_header(page_title='Saisie des absences',
-                              init_jquery_ui=True,
                               init_qtip = True,
                               javascripts=[
                                   'js/etud_info.js',
@@ -1288,7 +1286,6 @@
                        html_header=self.sco_header(
                            REQUEST, 
                            page_title=title, 
-                           init_jquery_ui=True,
                            init_qtip = True,
                            javascripts=['js/etud_info.js']
                            ),
@@ -1423,8 +1420,7 @@
         étant sur le portail étudiant).
         """
         etud = self.getEtudInfo(etudid=etudid, filled=1, REQUEST=REQUEST)[0]
-        H = [ self.sco_header(REQUEST,page_title="Billet d'absence de %s" % etud['nomprenom'], 
-                              init_jquery_ui=True) ]
+        H = [ self.sco_header(REQUEST,page_title="Billet d'absence de %s" % etud['nomprenom']) ]
         tf = TrivialFormulator(
             REQUEST.URL0, REQUEST.form, 
             (('etudid',  { 'input_type' : 'hidden' }),

Modified: branches/ScoDoc7/ZScoUsers.py
===================================================================
--- branches/ScoDoc7/ZScoUsers.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/ZScoUsers.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -513,7 +513,7 @@
              auth_dept = ''
          #
          edit = int(edit)
-         H = [self.sco_header(REQUEST, init_jquery_ui=True, bodyOnLoad="init_tf_form('')")]
+         H = [self.sco_header(REQUEST, bodyOnLoad="init_tf_form('')")]
          F = self.sco_footer(REQUEST)             
          if edit:
              if not user_name:

Modified: branches/ScoDoc7/ZScolar.py
===================================================================
--- branches/ScoDoc7/ZScolar.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/ZScolar.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -849,6 +849,9 @@
     
     security.declareProtected(ScoView, "search_etud_in_dept")
     search_etud_in_dept = sco_find_etud.search_etud_in_dept
+
+    security.declareProtected(ScoView, "search_etud_by_name")
+    search_etud_by_name = sco_find_etud.search_etud_by_name
     
     security.declareProtected(ScoView, "fillEtudsInfo")
     def fillEtudsInfo(self,etuds):

Modified: branches/ScoDoc7/html_sco_header.py
===================================================================
--- branches/ScoDoc7/html_sco_header.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/html_sco_header.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -140,6 +140,7 @@
     if init_jquery_ui:
         H.append('<script language="javascript" type="text/javascript" src="/ScoDoc/static/libjs/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>')
         # H.append('<script language="javascript" type="text/javascript" src="/ScoDoc/static/libjs/jquery-ui/js/jquery-ui-i18n.js"></script>')
+        H.append('<script language="javascript" type="text/javascript" src="/ScoDoc/static/js/scodoc.js"></script>')
     if init_google_maps:
         H.append('<script type="text/javascript" src="/ScoDoc/static/libjs/jquery.ui.map.full.min.js"></script>')
 
@@ -156,49 +157,6 @@
 }
 </style>
 """ % params )
-    # jQuery initialization
-    if init_jquery_ui:
-        H.append( """<script language="javascript" type="text/javascript">
-           $(function() {
-		$(".datepicker").datepicker({
-                      showOn: 'button', 
-                      buttonImage: '/ScoDoc/static/icons/calendar_img.png', 
-                      buttonImageOnly: true,
-                      dateFormat: 'dd/mm/yy',   
-                      duration : 'fast',                   
-                  });
-        $('.datepicker').datepicker('option', $.extend({showMonthAfterYear: false},
-         $.datepicker.regional['fr']));
-
-         /* Barre menu */
-        var sco_menu_position = {my: "left top", at: "left bottom"};
-       $("#sco_menu").menu({
-        position: sco_menu_position,
-        blur: function() {
-            $(this).menu("option", "position", sco_menu_position);
-        },
-        focus: function(e, ui) {
-            if ($("#sco_menu").get(0) !== $(ui).get(0).item.parent().get(0)) {
-                $(this).menu("option", "position", {my: "left top", at: "right top"});
-            }
-        }
-        }).mouseleave(function(x, y) {
-        $( "#sco_menu" ).menu('collapseAll');
-        });
-
-        $("#sco_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
-
-        /* Les menus isoles dropdown */
-        $(".sco_dropdown_menu").menu({
-        position: sco_menu_position
-        }).mouseleave(function(x, y) {
-        $( ".sco_dropdown_menu" ).menu('collapseAll');
-        }
-        );
-        $(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
-        
-	    });
-        </script>""" )
     # Scripts de la page:
     if scripts:
         H.append( """<script language="javascript" type="text/javascript">""" )

Modified: branches/ScoDoc7/html_sidebar.py
===================================================================
--- branches/ScoDoc7/html_sidebar.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/html_sidebar.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -78,7 +78,7 @@
     
     H.append("""<div class="box-chercheetud">Chercher étudiant:<br/>
 <form action="%(ScoURL)s/search_etud_in_dept">
-<div><input type="text" size="12" name="expnom"></input></div>
+<div><input type="text" size="12" id="in-expnom" name="expnom"></input></div>
 </form></div>
 <div class="etud-insidebar">
 """ % params )

Modified: branches/ScoDoc7/sco_abs_views.py
===================================================================
--- branches/ScoDoc7/sco_abs_views.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_abs_views.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -112,7 +112,7 @@
                 menu_module += """<option value="%(modimpl_id)s">%(modname)s</option>\n""" % {'modimpl_id': modimpl['moduleimpl_id'], 'modname': modimpl['module']['code']}
         menu_module += """</select></p>"""
 
-    H = [ context.sco_header(REQUEST,page_title="Signalement d'une absence pour %(nomprenom)s" % etud, init_jquery_ui=True ),
+    H = [ context.sco_header(REQUEST,page_title="Signalement d'une absence pour %(nomprenom)s" % etud ),
           """<table><tr><td>
           <h2>Signalement d'une absence pour %(nomprenom)s</h2>
           </td><td>
@@ -201,7 +201,7 @@
     # brute-force portage from very old dtml code ...
     etud = context.getEtudInfo(filled=1, REQUEST=REQUEST)[0]
     etudid = etud['etudid']
-    H = [ context.sco_header(REQUEST,page_title="Justification d'une absence pour %(nomprenom)s" % etud, init_jquery_ui=True ),
+    H = [ context.sco_header(REQUEST,page_title="Justification d'une absence pour %(nomprenom)s" % etud ),
           """<table><tr><td>
           <h2>Justification d'une absence pour %(nomprenom)s</h2>
           </td><td>
@@ -285,7 +285,7 @@
     etud = context.getEtudInfo(filled=1, REQUEST=REQUEST)[0]
     etudid = etud['etudid']
     
-    H = [ context.sco_header(REQUEST,page_title="Annulation d'une absence pour %(nomprenom)s" % etud, init_jquery_ui=True ),
+    H = [ context.sco_header(REQUEST,page_title="Annulation d'une absence pour %(nomprenom)s" % etud ),
           """<table><tr><td>
           <h2><font color="#FF0000">Annulation</font> d'une absence pour %(nomprenom)s</h2>
           </td><td>
@@ -395,7 +395,7 @@
 def EtatAbsences(context, REQUEST=None):
     """Etat des absences: choix du groupe"""
     # crude portage from 1999 DTML
-    H = [ context.sco_header(REQUEST,page_title="Etat des absences", init_jquery_ui=True),
+    H = [ context.sco_header(REQUEST,page_title="Etat des absences"),
           """<h2>Etat des absences pour un groupe</h2>
 <form action="EtatAbsencesGr" method="GET">""",
           formChoixSemestreGroupe(context),

Modified: branches/ScoDoc7/sco_edit_ue.py
===================================================================
--- branches/ScoDoc7/sco_edit_ue.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_edit_ue.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -26,7 +26,7 @@
 ##############################################################################
 
 """Ajout/Modification/Supression UE
-(portage from DTML)
+
 """
 from notesdb import *
 from sco_utils import *

Modified: branches/ScoDoc7/sco_evaluations.py
===================================================================
--- branches/ScoDoc7/sco_evaluations.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_evaluations.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -275,7 +275,7 @@
  'evaluation_type': 0,
  'heure_debut': datetime.time(8, 0),
  'heure_fin': datetime.time(9, 30),
- 'jour': datetime.date(2015, 11, 3),
+ 'jour': datetime.date(2015, 11, 3), // vide => 1/1/1
  'moduleimpl_id': 'GEAMIP80490',
  'note_max': 20.0,
  'numero': 0,
@@ -290,6 +290,7 @@
     res = cursor.dictfetchall()
     # etat de chaque evaluation:
     for r in res:
+        r['jour'] = r['jour'] or datetime.date( 1, 1, 1 ) # pour les comparaisons
         r['etat'] = do_evaluation_etat(context, r['evaluation_id'])
     
     return res
@@ -675,10 +676,7 @@
 
     dest_url = 'moduleimpl_status?moduleimpl_id=%s' % M['moduleimpl_id']
     if  tf[0] == 0:
-        head = context.sco_header(
-            REQUEST, 
-            page_title=page_title,
-            init_jquery_ui=True)
+        head = context.sco_header(REQUEST, page_title=page_title)
         return head + '\n'.join(H) + '\n' + tf[1] + help + context.sco_footer(REQUEST)
     elif tf[0] == -1:
         return REQUEST.RESPONSE.redirect( dest_url )

Modified: branches/ScoDoc7/sco_find_etud.py
===================================================================
--- branches/ScoDoc7/sco_find_etud.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_find_etud.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -171,6 +171,28 @@
     context.fillEtudsInfo(etuds)
     return etuds
 
+def search_etud_by_name(context, term, REQUEST=None):
+    """Recherche noms étudiants par début du nom, pour autocomplete
+    Renvoie une liste de nom en JSON
+    """
+    cnx = context.GetDBConnexion()
+    #term = strupper(term) # conserve les accents
+    term = term.upper()
+    if not ALPHANUM_EXP.match(term): # mais n'autorise pas les accents ;-)
+        data = []
+    else:
+        r = SimpleDictFetch(
+            context, 
+            "SELECT nom, prenom FROM identite WHERE nom LIKE %(beginning)s", 
+            {'beginning' : term+'%'})
+        data = [ { 
+            'label' : '%s %s' % (x['nom'], scolars.format_prenom(x['prenom'])),
+            'value' : x['nom'] 
+            }
+            for x in r ]
+    #log(data)
+    return sendJSON(REQUEST, data)
+    
 # ---------- Recherche sur plusieurs département
 
 def form_search_etud_in_accessible_depts(context, REQUEST):

Modified: branches/ScoDoc7/sco_formsemestre_edit.py
===================================================================
--- branches/ScoDoc7/sco_formsemestre_edit.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_formsemestre_edit.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -50,7 +50,6 @@
 def formsemestre_createwithmodules(context, REQUEST=None):
     """Page création d'un semestre"""
     H = [ context.sco_header(REQUEST, page_title='Création d\'un semestre',
-                             init_jquery_ui=True,
                              javascripts=['libjs/AutoSuggest.js',
                              ],
                              cssstyles=['css/autosuggest_inquisitor.css'], 
@@ -69,7 +68,6 @@
     sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
     F = context.formation_list( args={ 'formation_id' : sem['formation_id'] } )[0]
     H = [ context.html_sem_header(REQUEST, 'Modification du semestre', sem,
-                                  init_jquery_ui=True,
                                   javascripts=['libjs/AutoSuggest.js'],
                                   cssstyles=['css/autosuggest_inquisitor.css'], 
                                   bodyOnLoad="init_tf_form('')"
@@ -582,7 +580,6 @@
     
     H = [
         context.html_sem_header(REQUEST, 'Copie du semestre', sem,
-                                init_jquery_ui=True,
                                 javascripts=['libjs/AutoSuggest.js'],
                                 cssstyles=['css/autosuggest_inquisitor.css'],
                                 bodyOnLoad="init_tf_form('')"),

Modified: branches/ScoDoc7/sco_formsemestre_validation.py
===================================================================
--- branches/ScoDoc7/sco_formsemestre_validation.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_formsemestre_validation.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -820,7 +820,6 @@
     Fo = context.formation_list( args={ 'formation_id' : sem['formation_id'] } )[0]
     
     H = [ context.sco_header(REQUEST, page_title="Validation UE",
-                             init_jquery_ui=True,
                              javascripts=[ 'js/validate_previous_ue.js'
                                            ]),
           '<table style="width: 100%"><tr><td>',

Modified: branches/ScoDoc7/sco_groups.py
===================================================================
--- branches/ScoDoc7/sco_groups.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_groups.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -590,7 +590,6 @@
     suppricon= icontag('delete_small_img', border='0', alt='supprimer', title='Supprimer')
     #
     H = [ context.sco_header(REQUEST, page_title="Partitions...",
-                             init_jquery_ui=True,
                              javascripts=[ 'js/editPartitionForm.js']),
           """<script type="text/javascript">
           function checkname() {

Modified: branches/ScoDoc7/sco_lycee.py
===================================================================
--- branches/ScoDoc7/sco_lycee.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_lycee.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -70,7 +70,6 @@
         return t
     H = [ context.sco_header(REQUEST, page_title=tab.page_title,
                              init_google_maps=True,
-                             init_jquery_ui=True,
                              init_qtip = True,
                              javascripts=[
                                  'js/etud_info.js',
@@ -146,7 +145,6 @@
     F = [ sco_report.tsp_form_primo_group(REQUEST, only_primo, no_grouping, formsemestre_id, format) ]    
     H = [ context.sco_header(REQUEST, page_title=tab.page_title,
                              init_google_maps=True,
-                             init_jquery_ui=True,
                              init_qtip = True,
                              javascripts=[
                                  'js/etud_info.js',

Modified: branches/ScoDoc7/sco_tag_module.py
===================================================================
--- branches/ScoDoc7/sco_tag_module.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_tag_module.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -146,12 +146,11 @@
 
 # API
 
-VALID_EXP = re.compile('^[a-zA-Z0-9_\-]+$')
 def module_tag_search(context, term, REQUEST=None):
     """List all used tag names (for auto-completion)"""
     # restrict charset to avoid injections
     log('module_tag_search %s' % term)
-    if not VALID_EXP.match(term):
+    if not ALPHANUM_EXP.match(term):
         data = []
     else:
         r = SimpleDictFetch(

Modified: branches/ScoDoc7/sco_ue_external.py
===================================================================
--- branches/ScoDoc7/sco_ue_external.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_ue_external.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -183,7 +183,6 @@
     
     H = [ 
         context.html_sem_header(REQUEST, "Ajout d'une UE externe pour %(nomprenom)s" % etud, sem,
-                                init_jquery_ui=True,
                                 javascripts=['js/sco_ue_external.js'],
                                 ) 
         ]

Modified: branches/ScoDoc7/sco_utils.py
===================================================================
--- branches/ScoDoc7/sco_utils.py	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/sco_utils.py	2016-07-26 13:46:28 UTC (rev 1538)
@@ -362,8 +362,9 @@
         doc._pop()
     return doc
 
-# Expression used to check noms/prenoms
+# Expressions used to check noms/prenoms
 FORBIDDEN_CHARS_EXP = re.compile( r'[*\|~\(\)\\]' )
+ALPHANUM_EXP = re.compile('^[a-zA-Z0-9_\-]+$')
 
 def strnone(s):
     "convert s to string, '' if s is false"

Modified: branches/ScoDoc7/static/css/scodoc.css
===================================================================
--- branches/ScoDoc7/static/css/scodoc.css	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/static/css/scodoc.css	2016-07-26 13:46:28 UTC (rev 1538)
@@ -2499,3 +2499,9 @@
 span.sco_tag_edit .tag-editor-delete {
     height: 20px;
 }
+
+/* Autocomplete noms */
+.ui-menu-item {
+    font-family:   "Helvetica Neue",Helvetica,Arial,sans-serif;
+    font-size: 11pt;
+}
\ No newline at end of file

Modified: branches/ScoDoc7/static/js/module_tag_editor.js
===================================================================
--- branches/ScoDoc7/static/js/module_tag_editor.js	2016-07-26 05:37:41 UTC (rev 1537)
+++ branches/ScoDoc7/static/js/module_tag_editor.js	2016-07-26 13:46:28 UTC (rev 1538)
@@ -13,7 +13,7 @@
                    });
         },
         autocomplete: {
-            delay: 0, // show suggestions immediately
+            delay: 200, // ms before suggest
             position: { collision: 'flip' }, // automatic menu position up/down
             source: "module_tag_search"
         },

Added: branches/ScoDoc7/static/js/scodoc.js
===================================================================
--- branches/ScoDoc7/static/js/scodoc.js	                        (rev 0)
+++ branches/ScoDoc7/static/js/scodoc.js	2016-07-26 13:46:28 UTC (rev 1538)
@@ -0,0 +1,52 @@
+// JS for all ScoDoc pages (using jQuery UI)
+
+
+$(function() {
+    // Autocomplete recherche etudiants par nom
+    $("#in-expnom").autocomplete(
+        {
+            delay: 300, // wait 300ms before suggestions
+            minLength: 2, // min nb of chars before suggest
+            position: { collision: 'flip' }, // automatic menu position up/down
+            source: "search_etud_by_name"
+        });    
+    
+    // Date picker
+	$(".datepicker").datepicker({
+        showOn: 'button', 
+        buttonImage: '/ScoDoc/static/icons/calendar_img.png', 
+        buttonImageOnly: true,
+        dateFormat: 'dd/mm/yy',   
+        duration : 'fast',                   
+    });
+    $('.datepicker').datepicker('option', $.extend({showMonthAfterYear: false},
+                                                   $.datepicker.regional['fr']));
+
+    /* Barre menu */
+    var sco_menu_position = {my: "left top", at: "left bottom"};
+    $("#sco_menu").menu({
+        position: sco_menu_position,
+        blur: function() {
+            $(this).menu("option", "position", sco_menu_position);
+        },
+        focus: function(e, ui) {
+            if ($("#sco_menu").get(0) !== $(ui).get(0).item.parent().get(0)) {
+                $(this).menu("option", "position", {my: "left top", at: "right top"});
+            }
+        }
+        }).mouseleave(function(x, y) {
+            $( "#sco_menu" ).menu('collapseAll');
+        });
+
+    $("#sco_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
+
+    /* Les menus isoles dropdown */
+    $(".sco_dropdown_menu").menu({
+        position: sco_menu_position
+    }).mouseleave(function(x, y) {
+        $( ".sco_dropdown_menu" ).menu('collapseAll');
+    }
+                 );
+    $(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
+    
+});
\ No newline at end of file


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