Пример #1
0
def index(req):

    #recent_data = urllib2.urlopen("http://imaj-app.lddi.org:8010/list/recent")
    #pop_data = urllib2.urlopen("http://imaj-app.lddi.org:8010/list/popular")

    recent_data = urllib2.urlopen("http://localhost:8010/list/recent")
    pop_data = urllib2.urlopen("http://localhost:8010/list/popular")

    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/index.tmpl')
    
    r_data = json.load(recent_data)
    """ a list, but all elements are dictionaries """
    t.recent = r_data["images"]
   
    """ add more element into each dict, viewurl which involves /view? and 
       the value of imagekey """
    for each in r_data["images"]:
        each["viewurl"] = "view?imagekey=" + each["imagekey"]

    p_data = json.load(pop_data)
    t.popular = p_data["images"]

    for each in p_data["images"]:
        each["viewurl"] = "view?imagekey=" + each["imagekey"]


    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')

    m.main = t.__str__()

    req.content_type = "text/html"
    req.write(m.__str__())
Пример #2
0
def popular(req):
    
    query = req.form.getfirst("nextratesort", "false")

    request = "http://localhost:8010/list/popular"

    if query is not "false":
	request += "?nextratesort=" + query

    pop_data = urllib2.urlopen(request)

    #return pop_data.read()
    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/popular.tmpl')
    
    """ a list, but all elements are dictionaries """
    p_data = json.load(pop_data)
    t.imagelist = p_data["images"]

    t.nextratesort = p_data["nextratesort"]

    """ add more element into each dict, viewurl which involves /view? and 
    the value of imagekey """
    for each in p_data["images"]:
        each["viewurl"] = "/view?imagekey=" + each["imagekey"]


    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')

    m.main = t.__str__()

    req.content_type = "text/html"
    req.write(m.__str__())
Пример #3
0
def recent(req):

    query = req.form.getfirst("nextsubmitdate", "false")
    
    request = "http://localhost:8010/list/recent"
    if query is not "false":
        request += '?nextsubmitdate=' + query

    recent_data = urllib2.urlopen(request)
    #return recent_data.read()

    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/recent.tmpl')
    r_data = json.load(recent_data)
    t.imagelist = r_data["images"]
   
    t.nextsubmitdate = r_data["nextsubmitdate"]

    """ Add link for each image """
    for each in r_data["images"]:
        each["viewurl"] = "/view?imagekey=" + each["imagekey"]

    #return r_data["images"]
    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')

    m.main = t.__str__()

    req.content_type = "text/html"
    req.write(m.__str__())
Пример #4
0
def complete_tmpl(req, msg, resp):
    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/submitcomplete.tmpl')
    t.return_msg = resp
    t.submit_msg = msg

    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')
    m.main = t.__str__()

    req.content_type = "text/html"
    req.write(m.__str__())
Пример #5
0
def tmpl(req):
    t= Template(file='/home/yuanzheng/Public/public_html/cs462/lab2/test.tmpl')
    t.title="Recent Images"
    t.body="this is text"

    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab2/template.tmpl')
    m.main = t.__str__()


    req.content_type = "text/html"
    req.write(m.__str__())
Пример #6
0
def submit_page(req, error):
   
    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/submit.tmpl')

    t.errorlist = error

    if len(error) is not 0:
        imageurl = req.form.getfirst("imageurl")
        detailurl = req.form.getfirst("detailurl")
        tags = req.form.getfirst("tags")
        description = req.form.getfirst("description")
        submituser = req.form.getfirst("submituser")
        t.f = {'imageurl':imageurl, 'detailurl':detailurl, 'tags':tags, 'description':description, 'submituser':submituser}
    else:
        t.f = {'imageurl':"", 'detailurl':"", 'tags':"", 'description':"", 'submituser':""}

    
    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')

    m.main = t.__str__()
    
    req.content_type = "text/html"
    req.write(m.__str__())
Пример #7
0
def view(req):

    """ get the request """
    imagekey = req.form.getfirst("imagekey","")
    imagekey = cgi.escape(imagekey)
    
    """ build a new url, and send request to appServer """
    url = "http://localhost:8010/image?imagekey=" + imagekey

    """  urlopen() GET Request     """
    imagedata = urllib2.urlopen(url)
    #return imagedata.read()
    i_data = json.load(imagedata)


    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/view.tmpl')
    t.image = i_data

    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')

    m.main = t.__str__()

    req.content_type = "text/html"
    req.write(m.__str__())
Пример #8
0
def submit_error(data):
    t=Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/submitcomplete.tmpl')                                                                  
    m = Template(file='/home/yuanzheng/Public/public_html/cs462/lab3/WebServer/site_tmpl/template.tmpl')                                                               
    m.main = t.__str__()
    req.content_type = "text/html"
    req.write(m.__str__())