-
Notifications
You must be signed in to change notification settings - Fork 2
/
comando_acrescentar_trecho_IMP.py
38 lines (31 loc) · 1.09 KB
/
comando_acrescentar_trecho_IMP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Implementação do módulo {comando_acrescentar_trecho}.
import html_pag_trecho
import trecho
import sessao
import poltrona
from utils_testes import erro_prog, mostra
from valida_campo import ErroAtrib
import re
import sys
def msg_campo_obrigatorio(nome_do_campo):
return "O campo %s é obrigatório." % nome_do_campo
def processa(ses, atrs):
try:
# Separa o atributo 'poltronas' em {val_pos}:
if 'poltronas' in atrs:
esp_pols = atrs['poltronas'] # String que especfica poltronas e preços.
del atrs['poltronas']
else:
raise ErroAtrib("Coloque as poltronas do trecho.\"")
# Tenta criar o trecho:
assert 'encerrado' in atrs
if atrs['encerrado'] == 'on': atrs['encerrado'] = True # Necessario?
trc = trecho.cria(atrs)
pols = poltrona.cria_conjunto(trc, esp_pols)
# Mostra o trecho criado:
pag = html_pag_trecho.gera(ses, trc, None, "Trecho criado")
except ErroAtrib as ex:
erros = ex.args[0]
# Repete a página de acrescentar trecho com os mesmos argumentos e mens de erro:
pag = html_pag_trecho.gera(ses, None, atrs, erros)
return pag