Exemple #1
0
def espetaculos():
    page = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
    page += '<h1>Eventos</h1>'
    ts = NetWorkSpace("database", HOST_TS, PORT_TS)
    for i in ts.listVars(wsName='database', format='dict'):
        page += "<button class=\"show\"><a href=\"/consulta/<" + i + ">\">" + i + "</a></button><br>"
    page += '<br><br><button class="show"><a href="/">Home</a></button>'
    return page
Exemple #2
0
def consulta(espetaculo):

    form = FormCartao(request.form)

    print form.errors
    if request.method == 'POST':
        cartao = request.form['cartao']
        print cartao

    espetaculo = espetaculo.split('<')[1]
    espetaculo = espetaculo.split('>')[0]

    port = PORT_TS
    tsname = espetaculo
    host = HOST_TS

    ts = NetWorkSpace(tsname, host, port)

    seats = ""
    br = 0
    try:
        seats = '<link rel="stylesheet" type="text/css" media="screen" href="../static/index.css" />'
        lista = ts.listVars(wsName=tsname, format='dict')
        if not (lista):
            seats += "<h1> Sinto muito! Evento esgotado. </h1>"
        else:
            seats += '<form action="" method="post">'
            seats += '{{ form.csrf }}'
            seats += '<div class="input text">'
            seats += '{{ form.cartao.label }} {{ form.cartao }}'
            seats += '</div><br>'
            seats += '<button type="submit">Confirmar cartao</button>'
            seats += '</form>'

            if form.validate():
                seats += "<h1> Assentos </h1>"
                for i in sorted(lista):
                    seats += "<a href=\"/compra/<" + i + ">/<" + espetaculo + ">/<" + cartao + ">\"><button>"
                    seats += i
                    seats += "</button></a>"
                    br += 1
                    if (br == 10):
                        seats += "<br>"
                        br = 0

        seats += '<br><br><button class="show"><a href="/">Home</a></button>'
    except:
        raise
        seats = "There's no more seats. Sorry :("

    return render_template_string(seats, form=form)
try:
    from nws.client import NetWorkSpace
except ImportError, e:
    print >> sys.stderr, "unable to import the nws.client python module"
    print >> sys.stderr, "make sure you have nwsclient installed on this machine"
    sys.exit(1)

try:
    ws = NetWorkSpace('snake pit')
except ImportError, e:
    print >> sys.stderr, "make sure you're running the NWS server on this machine"
    print >> sys.stderr, str(e)
    sys.exit(1)

print 'connected, listing contents of netWorkSpace (should be nothing there).'
print ws.listVars()

ws.store('x', 1)
print 'should now see x.'
print ws.listVars()

print 'find (but don\'t consume) x.'
print ws.find('x')
print 'check that it is still there.'
print ws.listVars()

print 'associate another value with x.'
ws.store('x', 2)
print ws.listVars()

print 'consume values for x, should see them in order saved.'