[Scodoc-devel] [SVN] Scolar : [1501] recherche semestres par etape

eviennet at lipn.univ-paris13.fr eviennet at lipn.univ-paris13.fr
Lun 1 Fév 23:05:04 CET 2016


Une pièce jointe HTML a été nettoyée...
URL: <https://www-rt.iutv.univ-paris13.fr/pipermail/scodoc-devel/attachments/20160201/7fcdf428/attachment.html>
-------------- section suivante --------------
Modified: branches/ScoDoc7/ZNotes.py
===================================================================
--- branches/ScoDoc7/ZNotes.py	2016-01-29 16:59:53 UTC (rev 1500)
+++ branches/ScoDoc7/ZNotes.py	2016-02-01 22:05:03 UTC (rev 1501)
@@ -885,6 +885,7 @@
         """List all formsemestres matching etape, XML format
         DEPRECATED: use formsemestre_list()
         """
+        log('Warning: calling deprecated XMLgetFormsemestres')
         args = {}
         if etape_apo:
             args['etape_apo'] = etape_apo
@@ -917,6 +918,9 @@
     security.declareProtected(ScoView,'formsemestre_change_lock')
     formsemestre_change_lock = sco_formsemestre_edit.formsemestre_change_lock
 
+    security.declareProtected(ScoView,'view_formsemestre_by_etape')
+    view_formsemestre_by_etape = sco_formsemestre.view_formsemestre_by_etape
+    
     def _check_access_diretud(self, formsemestre_id, REQUEST, required_permission=ScoImplement):
         """Check if access granted: responsable_id or ScoImplement
         Return True|False, HTML_error_page

Modified: branches/ScoDoc7/ZScolar.py
===================================================================
--- branches/ScoDoc7/ZScolar.py	2016-01-29 16:59:53 UTC (rev 1500)
+++ branches/ScoDoc7/ZScolar.py	2016-02-01 22:05:03 UTC (rev 1501)
@@ -562,8 +562,8 @@
                 sem['lockimg'] = lockicon
                 othersems.append(sem)
             # Responsable de formation:
-            user_info = self.Users.user_info(sem['responsable_id'], REQUEST)
-            sem['responsable_name'] = user_info['nomprenom']
+            sco_formsemestre.sem_set_responsable_name(self, sem)
+            
             if showcodes=='1':
                 sem['tmpcode'] = '<td><tt>%s</tt></td>' % sem['formsemestre_id']
             else:
@@ -572,6 +572,7 @@
             args = { 'formsemestre_id' : sem['formsemestre_id'] }
             ins = self.Notes.do_formsemestre_inscription_list( args=args )
             nb = len(ins) # nb etudiants
+            sem['nb_inscrits'] = nb
             if nb > 0:
                 sem['groupicon'] = groupicon
             else:
@@ -609,6 +610,11 @@
             H.append('</table>')
         if not showlocked:
             H.append('<hr/><p><a href="%s?showlocked=1">Montrer les sessions verrouillées</a></p>' % REQUEST.URL0)
+        H.append("""<p><form action="Notes/view_formsemestre_by_etape">
+    Chercher étape courante: <input name="etape_apo" type="text" size="8"></input>    
+        </form
+        </p>
+        """)
         #
         authuser = REQUEST.AUTHENTICATED_USER
         if authuser.has_permission(ScoEtudInscrit,self):

Modified: branches/ScoDoc7/gen_tables.py
===================================================================
--- branches/ScoDoc7/gen_tables.py	2016-01-29 16:59:53 UTC (rev 1500)
+++ branches/ScoDoc7/gen_tables.py	2016-02-01 22:05:03 UTC (rev 1501)
@@ -96,6 +96,7 @@
                  html_next_section='', # html fragment to put after the table
                  html_with_td_classes=False, # put class=column_id in each <td>
                  html_before_table='', # html snippet to put before the <table> in the page
+                 html_empty_element='', # replace table when empty
                  base_url = None,
                  origin=None, # string added to excel and xml versions
                  filename='table', # filename, without extension
@@ -123,7 +124,8 @@
         self.filename = filename
         self.caption = caption
         self.html_header=html_header
-        self.html_before_table = ''
+        self.html_before_table = html_before_table
+        self.html_empty_element = html_empty_element
         self.page_title = page_title
         self.pdf_link=pdf_link
         self.xls_link=xls_link
@@ -256,6 +258,8 @@
 
     def html(self):
         "Simple HTML representation of the table"
+        if self.is_empty() and self.html_empty_element:
+            return self.html_empty_element
         hid = ' id="%s"' % self.table_id
         tablclasses = []
         if self.html_class:

Modified: branches/ScoDoc7/html_sco_header.py
===================================================================
--- branches/ScoDoc7/html_sco_header.py	2016-01-29 16:59:53 UTC (rev 1500)
+++ branches/ScoDoc7/html_sco_header.py	2016-02-01 22:05:03 UTC (rev 1501)
@@ -152,6 +152,7 @@
 .gtrcontent {
    margin-left: %(margin_left)s;
    height: 100%%;
+   margin-bottom: 10px;
 }
 </style>
 """ % params )

Modified: branches/ScoDoc7/sco_formsemestre.py
===================================================================
--- branches/ScoDoc7/sco_formsemestre.py	2016-01-29 16:59:53 UTC (rev 1500)
+++ branches/ScoDoc7/sco_formsemestre.py	2016-02-01 22:05:03 UTC (rev 1501)
@@ -31,6 +31,7 @@
 from sco_utils import *
 from notesdb import *
 from notes_log import log
+from gen_tables import GenTable
 
 import sco_codes_parcours
 
@@ -89,7 +90,7 @@
 def formsemestre_enrich(context, sem):
     """Ajoute champs souvent utiles: titre + annee et dateord (pour tris)
     """
-    # imprts ici pour eviter refs circulaires
+    # imports ici pour eviter refs circulaires
     import sco_formsemestre_edit
     import scolars
     F = context.Notes.formation_list(args={ 'formation_id' :sem['formation_id']})[0]
@@ -134,8 +135,23 @@
     sem['titremois'] =  '%s %s  (%s - %s)' % (sem['titre_num'], sem.get('modalite',''), 
                                             sem['mois_debut'], sem['mois_fin'])
     sem['session_id'] = sco_formsemestre_edit.get_formsemestre_sessionid(context, sem, F, parcours)
-    
+    sem['etapes_apo_str'] = ','.join( [ 
+        sem[k] for k in ('etape_apo', 'etape_apo2', 'etape_apo3', 'etape_apo4')
+        if sem[k] ] )
 
+def sem_set_responsable_name(context, sem):
+    "ajoute champs responsable_name"
+    user_info = context.Users.user_info(sem['responsable_id'])
+    sem['responsable_name'] = user_info['nomprenom']
+
+def sem_in_current_annee_scolaire(context, sem, REQUEST=None):
+    """n'utilise que la date de debut, pivot au 1er aout
+    """
+    y = context.AnneeScolaire(REQUEST)
+    return ( ((sem['annee_debut'] == str(y)) and (sem['mois_debut_ord'] > 7))
+             or ((sem['annee_debut'] == str(y+1)) and (sem['mois_debut_ord'] <= 7)))
+
+        
 def scodoc_get_all_unlocked_sems(context):
     """Liste de tous les semestres non verrouillés de tous les départements"""
     depts = context.list_depts()
@@ -147,37 +163,82 @@
                       if sem['etat'] == '1' ]        
     return semdepts
 
-
-# XXX TODO
-def find_formsemestre_by_etape(context, etape_apo=None, in_annee_scolaire=True):
+def table_formsemestres(context, sems, 
+                        columns_ids=(), sup_columns_ids=(),
+                        html_title = '<h2>Semestres</h2>',
+                        html_next_section='',
+                        REQUEST=None):
+    """Une table presentant des semestres
     """
-    """
-    context.do_formsemestre_list
+    for sem in sems:
+        sem_set_responsable_name(context, sem)
+        sem['_titre_num_target'] = 'formsemestre_status?formsemestre_id=%s' % sem['formsemestre_id']
+    
+    if not columns_ids:
+        columns_ids = (
+            'etat',
+            'modalite', 
+            'mois_debut', 'mois_fin', 
+            'titre_num', 
+            'responsable_name', 
+            'etapes_apo_str'
+        ) 
+    columns_ids += sup_columns_ids
 
+    titles = { 'modalite' : '',
+               'mois_debut' : 'Début',
+               'mois_fin' : 'Fin',
+               'titre_num' : 'Semestre',
+               'responsable_name' : 'Resp.',
+               'etapes_apo_str' : 'Apo.'
+               }
+    if sems:
+        preferences=context.get_preferences(sems[0]['formsemestre_id'])
+    else:
+        preferences=context.get_preferences()
+    tab = GenTable( columns_ids=columns_ids, rows=sems,
+                    titles=titles, 
+                    html_class='gt_table table_leftalign',
+                    html_sortable=True,
+                    html_title = html_title,
+                    html_next_section=html_next_section,
+                    html_empty_element='<p><em>aucun résultat</em></p>',
+                    page_title = 'Semestres',
+                    preferences=preferences )
+    return tab
 
-# # 
-# class SemElem(object):
-#     """Element pédagogique ScoDoc"""
-#     def __init__(self, scodoc_id):
-#         self.scodoc_id = scodoc_id
-    
-#     def get_apo_id(self):
-#         return self.apo_id
-    
-#     def get_scodoc_object(self):
-#         self.scodoc_getter(context, self.scodoc_id)
-        
-# class SemElem_Sem:
-#     scodoc_getter = get_formsemestre
-#     def __init__(self, formsemestre_id, etapes_apo=[]):
-#         self.etapes_apo = etapes_apo
-#         super(SemElem_Sem, self).__init__()
-        
 
-        
-# class SemElem_UE:
-    
+def find_formsemestre_by_etape(context, etape_apo=None, in_annee_scolaire=True, REQUEST=None):
+    """
+    """
+    ds = {} # formsemestre_id : sem
+    if etape_apo:
+        for k in ('etape_apo', 'etape_apo2', 'etape_apo3', 'etape_apo4'):
+            sems = do_formsemestre_list(context, args={ k : etape_apo })
+            for sem in sems:
+                if in_annee_scolaire: # restriction annee en cours
+                    if sem_in_current_annee_scolaire(context, sem, REQUEST=REQUEST):
+                        ds[sem['formsemestre_id']] = sem
+        sems = ds.values()
+    else:
+        sems = [ sem for sem in do_formsemestre_list(context) 
+                 if sem_in_current_annee_scolaire(context, sem, REQUEST=REQUEST) ]
+    sems.sort( key=lambda s: (s['modalite'],s['dateord']) )
+    return sems
 
-# class SemElem_Mod:
-#     pass
-
+def view_formsemestre_by_etape(context, etape_apo=None, format='html', REQUEST=None):
+    """Affiche table des semestres correspondants à l'étape
+    """
+    if etape_apo:
+        html_title = '''<h2>Semestres courants de l'étape <tt>%s</tt></h2>''' % etape_apo
+    else:
+        html_title = '''<h2>Semestres courants</h2>'''
+    tab = table_formsemestres(context,
+        find_formsemestre_by_etape(context, etape_apo=etape_apo),
+        html_title=html_title,
+        html_next_section="""<form action="view_formsemestre_by_etape">
+    Etape: <input name="etape_apo" type="text" size="8"></input>    
+        </form>""",
+        REQUEST=REQUEST)
+    tab.base_url = '%s?etape_apo=%s' % (REQUEST.URL0, etape_apo or '')
+    return tab.make_page(context, format=format, REQUEST=REQUEST)


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