#!c:/python34/python.exe

__author__ = 'Ben'

from request import request_to_sakila
import cgitb
cgitb.enable()
from jinja2 import Environment, FileSystemLoader
import error

context = {}

cities = request_to_sakila('/city')
if cities[0] == 'K':
    context['cities'] = cities[1]
else:
    error.page('Cannot access city data', cities)
    quit()


ldr = FileSystemLoader('templates')
env = Environment(loader=ldr)
template = env.get_template("address_create_entry.html")
template_rendered = template.render(context)

print("Content-type: text/html")
print()
print(template_rendered)

import cgi
import cgitb
cgitb.enable()

from request import request_to_sakila
from jinja2 import Environment, FileSystemLoader
import error

fldstor = cgi.FieldStorage()

customer_id_list = fldstor.getlist("customer_id")

if len(customer_id_list) != 1:
    error.page("There should be exactly one customer id sumbitted")
    exit()

customer_id = customer_id_list[0]

response = request_to_sakila("/customer/" + str(customer_id))

# error.page("returned from customer id search", response)

context = {}

if response[0] != 'K':
    error.page("Error getting customer data", response[1])
    exit()
cust_info = response[1]
context['cust_info'] = response[1]
__author__ = 'Ben'

from request import request_to_sakila
import cgitb
cgitb.enable()
from jinja2 import Environment, FileSystemLoader
import error
import cgi

fs = cgi.FieldStorage()

values = {}

flist = fs.getlist('address')
if len(flist) != 1 or not flist[0]:
    error.page("address field not properly set")
    quit()
values['address'] = flist[0]

flist = fs.getlist('district')
if len(flist) != 1 or not flist[0]:
    error.page("district field not properly set")
    quit()
values['district'] = flist[0]

flist = fs.getlist('phone')
if len(flist) != 1 or not flist[0]:
    error.page("phone field not properly set")
    quit()
values['phone'] = flist[0]