[lib/dialogwizard] on peut mettre des champs plus élaborés
Ignore-this: 197a121bac23ae72a086535cc612311c darcs-hash:20090906134550-bd074-801938dc1daca12012adb24aeb4bff939ab75728.gz
This commit is contained in:
parent
feaf2215e6
commit
d79f7ec2f0
3 changed files with 80 additions and 97 deletions
|
@ -45,7 +45,7 @@ from ldap_crans import crans_ldap, script_utilisateur#, blacklist_items, ann_sco
|
|||
sys.path.append('/usr/scripts')
|
||||
from lib.dialogwizard.wizard import Scenario, Running, step_scenario, unit_scenario
|
||||
from lib.dialogwizard.dialogwizard import DialogStepGenerator
|
||||
from ldap_crans import Adherent #, AssociationCrans, Club
|
||||
from ldap_crans import Adherent #, AssociationCrans, Club
|
||||
# from ldap_crans import Machine, MachineFixe, MachineWifi, MachineCrans, BorneWifi
|
||||
# import user_tests
|
||||
|
||||
|
@ -71,16 +71,17 @@ dsgen = DialogStepGenerator(u'Gestion des adhérents et machines du Crans')
|
|||
|
||||
prompt_new_adher = \
|
||||
dsgen.form_step (u"Inscription adhérent", '',
|
||||
[('nom', 'Nom :', 20),
|
||||
('prenom', u'Prénom :', 20),
|
||||
('tel', u'Numéro de téléphone', 13),
|
||||
('chbre', u'Chambre :', 5) ])
|
||||
[{'var': 'nom', 'label': 'Nom :', 'field_len': 20},
|
||||
{'var': 'prenom', 'label': u'Prénom :', 'field_len': 20},
|
||||
{'var': 'tel', 'label': u'Numéro de téléphone', 'field_len': 13},
|
||||
{'var': 'chbre', 'label': u'Chambre :', 'field_len': 5} ])
|
||||
|
||||
prompt_addr_ext = \
|
||||
dsgen.form_step (u"Adresse extérieure de %(nom)s", '',
|
||||
[('addr1', 'Adresse', 40), ('addr2', '', 40),
|
||||
('addr3', 'Code Postal :', 6),
|
||||
('addr4', 'Ville :', 20)])
|
||||
[{'var': 'addr1', 'label': 'Adresse', 'field_len': 40},
|
||||
{'var': 'addr2', 'label': '', 'field_len': 40},
|
||||
{'var': 'addr3', 'label': 'Code Postal :', 'field_len': 6},
|
||||
{'var': 'addr4', 'label': 'Ville :', 'field_len': 20}])
|
||||
|
||||
def prompt_etudes(name):
|
||||
etab_step = \
|
||||
|
@ -137,7 +138,7 @@ def prompt_etudes(name):
|
|||
u'Section :',
|
||||
'etud3')
|
||||
|
||||
section1_step = \
|
||||
section_step = \
|
||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||
u'Choisissez la section :',
|
||||
'etud3',
|
||||
|
@ -145,52 +146,24 @@ def prompt_etudes(name):
|
|||
("A1", "Mathématiques"),
|
||||
("A2", "Physique fondamentale"),
|
||||
("A''2", "Chimie"),
|
||||
{'label': "A'2", 'item': "Physique appliquée",
|
||||
'show_cond': (lambda d: d['etud2'] in ['3','4'])},
|
||||
("A3", "Biochimie"),
|
||||
("B123", "Technologie mécanique"),
|
||||
{'label': "B123", 'item':"Technologie mécanique",
|
||||
'show_cond': (lambda d: d['etud2'] == '1') },
|
||||
{'label': "B1", 'item': "Mécanique",
|
||||
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||
{'label': "B2", 'item': "Génie civil",
|
||||
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||
{'label': "B3", 'item': "Génie mécanique",
|
||||
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||
("EEA", "Électronique, électrotechnique et automatique"),
|
||||
("C", "Art et création industrielle"),
|
||||
("D2", "Economie gestion"),
|
||||
("D3", "Sciences sociales"),
|
||||
("E", "Anglais") ])
|
||||
|
||||
section2_step = \
|
||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||
u'Choisissez la section :',
|
||||
'etud3',
|
||||
[ ("A0", "Informatique"),
|
||||
("A1", "Mathématiques"),
|
||||
("A2", "Physique fondamentale"),
|
||||
("A''2", "Chimie"),
|
||||
("A3", "Biochimie"),
|
||||
("B1", "Mécanique"),
|
||||
("B2", "Génie civil"),
|
||||
("B3", "Génie mécanique"),
|
||||
("EEA", "Électronique, électrotechnique et automatique"),
|
||||
("C", "Art et création industrielle"),
|
||||
("D2", "Economie gestion"),
|
||||
("D3", "Sciences sociales"),
|
||||
("E", "Anglais") ])
|
||||
|
||||
section3_step = \
|
||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||
u'Choisissez la section :',
|
||||
'etud3',
|
||||
[ ("A0", "Informatique"),
|
||||
("A1", "Mathématiques"),
|
||||
("A2", "Physique fondamentale"),
|
||||
("A'2", "Physique appliquée"),
|
||||
("A''2", "Chimie"),
|
||||
("A3", "Biochimie"),
|
||||
("B1", "Mécanique"),
|
||||
("B2", "Génie civil"),
|
||||
("B3", "Génie mécanique"),
|
||||
("B4", "Génie électrique"),
|
||||
("C", "Art et création industrielle"),
|
||||
("D2", "Economie gestion"),
|
||||
("D3", "Sciences sociales"),
|
||||
("E", "Anglais") ])
|
||||
|
||||
section5_step = \
|
||||
labo_step = \
|
||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||
u'Choisissez le laboratoire :',
|
||||
'etud3',
|
||||
|
@ -211,15 +184,9 @@ def prompt_etudes(name):
|
|||
|
||||
ens_scenar = Scenario()
|
||||
ens_scenar.nest(year_ens_step)
|
||||
ens_scenar.case((lambda d: d['etud2']),
|
||||
{ '1': step_scenario(section1_step),
|
||||
'2': step_scenario(section2_step),
|
||||
'3': step_scenario(section3_step),
|
||||
'4': step_scenario(section3_step),
|
||||
'5': step_scenario(section5_step),
|
||||
'6': step_scenario(section5_step),
|
||||
'7': step_scenario(section5_step) },
|
||||
fallback = step_scenario(section_step))
|
||||
ens_scenar.branch((lambda d: d['etud2'] in ['1','2','3','4']),
|
||||
step_scenario(section_step),
|
||||
step_scenario(labo_step))
|
||||
|
||||
other_etab_scenar = Scenario()
|
||||
other_etab_scenar.nest(year_step)
|
||||
|
@ -234,16 +201,16 @@ def prompt_etudes(name):
|
|||
|
||||
return etudes_scenar
|
||||
|
||||
prompt_connexion = \
|
||||
dsgen.form_step (u"Type de connexion",
|
||||
u'Inscription adhérent',
|
||||
'typ', [('1', 'Adhésion'),
|
||||
('2', 'Inscription gratuite')])
|
||||
# prompt_connexion = \
|
||||
# dsgen.form_step (u"Type de connexion",
|
||||
# u'Inscription adhérent',
|
||||
# 'typ', [('1', 'Adhésion'),
|
||||
# ('2', 'Inscription gratuite')])
|
||||
|
||||
prompt_papiers = \
|
||||
dsgen.checklist_step('', u'État administratif de %(nom)s',
|
||||
[('carte', u"Carte d'étudiant %s fourniee" % ann_scol),
|
||||
('paiement%s' % this_year, u'Cotisation %s réglée et charte signée' % ann_scol),
|
||||
[('carte', u"Carte d'étudiant %s-%s fourniee" % (ann_scol, ann_scol+1)),
|
||||
('paiement%s' % ann_scol, u'Cotisation %s réglée et charte signée' % ann_scol),
|
||||
('chartema', u'Charte des membres actifs signée')])
|
||||
|
||||
prompt_login = \
|
||||
|
@ -252,7 +219,7 @@ prompt_login = \
|
|||
|
||||
prompt_mailaddress = \
|
||||
dsgen.input_step(u'Addresse mail extérieure de %(nom)s',
|
||||
'')
|
||||
'', 'mail')
|
||||
|
||||
dummy_scenar = Scenario()
|
||||
dummy_scenar.nest(prompt_new_adher)
|
||||
|
|
|
@ -845,55 +845,51 @@ class Dialog:
|
|||
|
||||
"""
|
||||
self._perform_no_options('--clear')
|
||||
def form(self, text, height=0, width=0, form_height=20, fields=[], auto_place=True, **kwargs):
|
||||
def form(self, text, height=0, width=0, form_height='auto', fields=[], auto_place=True, **kwargs):
|
||||
"""Display a form dialog box.
|
||||
|
||||
text -- text to display in the box
|
||||
height -- height of the box
|
||||
width -- width of the box
|
||||
form_height -- height of the form
|
||||
fields -- a list of tuples, each tuple has the form:
|
||||
(label, item, field_len, [input_len, lpos, ipos])
|
||||
where lpos, ipos are two two-tuples containing y and x positions for label and item
|
||||
fields -- a list of dict, each dict must have the fields
|
||||
label, item, field_len, and may have the fields
|
||||
input_len, xlpos, ylpos, xipos, yipos
|
||||
auto_place -- boolean allowing automatic placement of items
|
||||
|
||||
it returns a tuple of the form (code, results), where results is a
|
||||
it returns a tuple of the form (code, results), where results is a
|
||||
list of the results.
|
||||
|
||||
Notable exceptions:
|
||||
- any exception raised by self._perform()
|
||||
- UnexpectedDialogOutput
|
||||
- PythonDialogReModuleError
|
||||
|
||||
"""
|
||||
"""
|
||||
if form_height == 'auto':
|
||||
form_height = len (fields)
|
||||
cmd = ["--form", text, str(height), str(width), str(form_height)]
|
||||
|
||||
# find the longest label so we can put the input boxes at the
|
||||
# correct offset
|
||||
max_label_len = 0
|
||||
for t in fields:
|
||||
if len(t[0]) > max_label_len:
|
||||
max_label_len = len(t[0]);
|
||||
if len(t['label']) > max_label_len:
|
||||
max_label_len = len(t['label']);
|
||||
|
||||
line = 1
|
||||
for t in fields:
|
||||
label = t[0]
|
||||
item = t[1]
|
||||
field_len = str(t[2])
|
||||
if len(t) < 4:
|
||||
input_len = field_len
|
||||
else:
|
||||
input_len = str(t[3])
|
||||
if auto_place or len(t) < 6:
|
||||
ylpos = line
|
||||
xlpos = 1
|
||||
yipos = line
|
||||
xipos = max_label_len + 2
|
||||
else:
|
||||
ylpos, xlpos = t[4]
|
||||
yipos, xipos = t[5]
|
||||
try:
|
||||
l = [ t['label'] ]
|
||||
if auto_place:
|
||||
l += [line, 1, t.get('item',''), line, max_label_len + 2]
|
||||
else:
|
||||
l += [ t['ylpos'], t['xlpos'], t.get('item', ''), t['yipos'], t['xipos'] ]
|
||||
l += [ t['field_len'], t.get('input_len', '') ]
|
||||
l = [ unicode(f) for f in l ]
|
||||
except Exception, e:
|
||||
raise e
|
||||
|
||||
cmd.extend(((label, str(ylpos), str(xlpos), item, str(yipos), str(xipos), field_len, input_len)))
|
||||
cmd += l
|
||||
line += 1
|
||||
|
||||
(code, output) = self._perform(*(cmd,), **kwargs)
|
||||
|
|
|
@ -25,19 +25,33 @@ class DialogStepGenerator():
|
|||
if rc == 2: really_quit(dico)
|
||||
if rc == 1: raise PreviousStep
|
||||
|
||||
def _skim_choices(self, choices, dico):
|
||||
return [ f for f in choices if f.get('show_cond', lambda x : True)(dico) ]
|
||||
|
||||
def form_step(self, title, enonce, form, **kw):
|
||||
def fn(dico, default):
|
||||
fields = [ ( field[1], default.get(field[0], dico.get(field[0], ''))) + field[2:] for field in form ]
|
||||
rc, res = self.d.form(enonce, fields = fields, title=title, **kw)
|
||||
sform = self._skim_choices(form, dico)
|
||||
for field in sform:
|
||||
item = default.get(field['var'], dico.get(field['var'], ''))
|
||||
field['item'] = item
|
||||
rc, res = self.d.form(enonce, fields = sform, title=title, **kw)
|
||||
self._check_rc(rc)
|
||||
for field, val in izip (form, res):
|
||||
dico[field[0]] = val
|
||||
for field, val in izip (sform, res):
|
||||
dico[field['var']] = val
|
||||
return dico
|
||||
return Step(fn)
|
||||
|
||||
def select_step(self, title, enonce, var, choix, **kw):
|
||||
def fn(dico, default):
|
||||
rc, res = self.d.menu(enonce, choices = choix, title = title, **kw)
|
||||
schoix = []
|
||||
for c in choix:
|
||||
try:
|
||||
schoix.append((c[0], c[1]))
|
||||
except Exception,e:
|
||||
if c.get('show_cond', lambda x : True)(dico):
|
||||
schoix.append((c['label'], c['item']))
|
||||
print schoix
|
||||
rc, res = self.d.menu(enonce, choices = schoix, title = title, **kw)
|
||||
self._check_rc(rc)
|
||||
dico[var] = res
|
||||
return dico
|
||||
|
@ -53,8 +67,14 @@ class DialogStepGenerator():
|
|||
|
||||
def checklist_step(self, title, enonce, liste):
|
||||
def fn(dico, default):
|
||||
choix = [var, txt, dico.get(var, 'off') for var, txt in liste]
|
||||
rc, res = self.d.checklist(enonce, title = title, choices = choix, **kw)
|
||||
sliste = []
|
||||
for c in liste:
|
||||
try:
|
||||
sliste.append((c[0], c[1], dico.get(c[0], 'off')))
|
||||
except Exception,e:
|
||||
if c.get('show_cond', lambda x : True)(dico):
|
||||
sliste.append((c['var'], c['item'], dico.get(c['var'], 'off')))
|
||||
rc, res = self.d.checklist(enonce, title = title, choices = sliste, **kw)
|
||||
self._check_rc(rc)
|
||||
for tag, item, status in liste:
|
||||
if tag in res:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue