[scodoc-devel] [SVN] Scolar : [1742] Fichier saisie note: meilleur nom si evaluation sans date.

eviennet at lipn.univ-paris13.fr eviennet at lipn.univ-paris13.fr
Sam 23 Déc 16:18:20 CET 2017


Une pièce jointe HTML a été nettoyée...
URL: https://listes.univ-paris13.fr/pipermail/scodoc-devel/attachments/20171223/e919ac98/attachment.htm 
-------------- section suivante --------------
Modified: branches/ScoDoc7/sco_archives.py
===================================================================
--- branches/ScoDoc7/sco_archives.py	2017-12-23 14:43:42 UTC (rev 1741)
+++ branches/ScoDoc7/sco_archives.py	2017-12-23 15:18:20 UTC (rev 1742)
@@ -63,6 +63,7 @@
 from sco_recapcomplet import make_formsemestre_recapcomplet
 import sco_bulletins_pdf
 
+
 class BaseArchiver:
     def __init__(self, archive_type=''):
         dirs = [ os.environ['INSTANCE_HOME'], 'var', 'scodoc', 'archives' ]
@@ -176,28 +177,13 @@
             GSL.release()
         self.store( archive_id, '_description.txt', description ) 
         return archive_id
-    
-    valid_cars = '-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.!' # no / !
-    valid_cars_set = Set(valid_cars)
-    valid_exp = re.compile('^['+valid_cars+']+$')
-    
-    def sanitize_filename(self, filename):
-        """Keep only valid cars"""
-        sane = ''.join( [ c for c in filename if c in self.valid_cars_set ] )
-        if len(sane) < 2:
-            sane = time.time() + '-' + sane
-        return sane
-    
-    def is_valid_filename(self, filename):
-        """True if filename is safe"""
-        return self.valid_exp.match(filename)
-    
+        
     def store(self, archive_id, filename, data):
         """Store data in archive, under given filename. 
         Filename may be modified (sanitized): return used filename
         The file is created or replaced.
         """
-        filename = self.sanitize_filename(filename)
+        filename = sanitize_filename(filename)
         log("storing %s (%d bytes) in %s" % (filename, len(data), archive_id))
         try:
             GSL.acquire()
@@ -211,7 +197,7 @@
 
     def get(self, archive_id, filename):
         """Retreive data"""
-        if not self.is_valid_filename(filename):
+        if not is_valid_filename(filename):
             log('Archiver.get: invalid filename "%s"' % filename)
             raise ValueError('invalid filename')
         fname = os.path.join(archive_id, filename)

Modified: branches/ScoDoc7/sco_etape_apogee_view.py
===================================================================
--- branches/ScoDoc7/sco_etape_apogee_view.py	2017-12-23 14:43:42 UTC (rev 1741)
+++ branches/ScoDoc7/sco_etape_apogee_view.py	2017-12-23 15:18:20 UTC (rev 1742)
@@ -607,7 +607,7 @@
                                              dest_zip=dest_zip, REQUEST=REQUEST )
     
     basename = context.get_preference('DeptName') + str(annee_scolaire) + '-%s-' % periode + '-'.join(etapes_apo)
-    basename = sco_etape_apogee.ApoCSVArchive.sanitize_filename(unescape_html(basename))
+    basename = sco_archives.sanitize_filename(unescape_html(basename))
     
     dest_zip.close()
     size = data.tell()

Modified: branches/ScoDoc7/sco_saisie_notes.py
===================================================================
--- branches/ScoDoc7/sco_saisie_notes.py	2017-12-23 14:43:42 UTC (rev 1741)
+++ branches/ScoDoc7/sco_saisie_notes.py	2017-12-23 15:18:20 UTC (rev 1742)
@@ -558,7 +558,12 @@
     formsemestre_id = M['formsemestre_id']
     Mod = context.do_module_list( args={ 'module_id' : M['module_id'] } )[0]
     sem = sco_formsemestre.get_formsemestre(context, M['formsemestre_id'])
-    evalname = '%s-%s' % (Mod['code'],DateDMYtoISO(E['jour']))
+    if E['jour']:
+        indication_date = DateDMYtoISO(E['jour'])
+    else:
+        indication_date = sanitize_filename(E['description'])[:12]
+    evalname = '%s-%s' % (Mod['code'],indication_date)
+        
     if E['description']:
         evaltitre = '%s du %s' % (E['description'],E['jour'])
     else:

Modified: branches/ScoDoc7/sco_utils.py
===================================================================
--- branches/ScoDoc7/sco_utils.py	2017-12-23 14:43:42 UTC (rev 1741)
+++ branches/ScoDoc7/sco_utils.py	2017-12-23 15:18:20 UTC (rev 1742)
@@ -416,6 +416,25 @@
     """Try to convert name to a reasonnable filename"""
     return suppress_accents(name).replace(' ', '_')
 
+
+VALID_CARS = '-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.!' # no / !
+VALID_CARS_SET = Set(VALID_CARS)
+VALID_EXP = re.compile('^['+VALID_CARS+']+$')
+
+def sanitize_filename(filename):
+    """Keep only valid chars
+    used for archives filenames
+    """
+    sane = ''.join( [ c for c in filename if c in VALID_CARS_SET ] )
+    if len(sane) < 2:
+        sane = time.time() + '-' + sane
+    return sane
+
+def is_valid_filename(filename):
+    """True if filename is safe"""
+    return VALID_EXP.match(filename)
+
+
 def sendCSVFile(REQUEST,data,filename):
     """publication fichier.
     (on ne doit rien avoir émis avant, car ici sont générés les entetes)


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