Rev 172 | Rev 241 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
# -*- coding: utf-8 -*-"""Main Controller"""from tg import expose, flash, require, url, request, redirectfrom pylons.i18n import ugettext as _, lazy_ugettext as l_from wiki20.lib.base import BaseControllerfrom wiki20.model import DBSession, metadatafrom wiki20.controllers.error import ErrorControllerfrom wiki20.processors.RequestProcessors import process_gauravfrom datastore.DataAccessor import DataHelperfrom datastore.DataCodeAccessor import *from xml.etree.ElementTree import *import urllibfrom tg import tmpl_contextfrom wiki20.widgets.infibeam_form import create_infibeam_form__all__ = ['RootController']class RootController(BaseController):"""The root controller for the Wiki-20 application.All the other controllers and WSGI applications should be mounted on thiscontroller. For example::panel = ControlPanelController()another_app = AnotherWSGIApplication()Keep in mind that WSGI applications shouldn't be mounted directly: Theymust be wrapped around with :class:`tg.controllers.WSGIAppController`."""error = ErrorController()@expose('wiki20.templates.index')def index(self):"""Handle the front-page."""return dict(page='index')@expose('wiki20.templates.about')def about(self):"""Handle the 'about' page."""return dict(page='about')@expose('wiki20.templates.gaurav')def gaurav(self, **data):""" Handle gaurav url"""print dataret_val = process_gaurav(data)return ret_val@expose('wiki20.templates.compare')def compare(self):""" Handle compare url"""str1 = ""da = DataHelper()models = da.get_all_models()ret_val = {}for m in models:name = m.modelstr1 = str1 + "<option value="#str1 = str1 + "/'"str1 = str1 + unicode(name, "iso-8859-1")#str1 = str1 + "/'"str1 = str1 + ">"str1 = str1 + unicode(name, "iso-8859-1")str1 = str1 + "</option>"#print data#ret_val = process_compare(data)ret_val['val1'] = str1return ret_val@expose('wiki20.templates.compare_model')def compare_model(self,**data):model = data['model']da = DataHelper()mid = da.get_modbyModel(model).idmodels_list = da.get_prbyMid(mid)sorted(models_list, key=lambda prices: prices.supplier_id)leng = len(models_list)print "length is :"print lengprice_list = []vendor_list = []while leng>0:price_list.append(0)#['infibeam','indiaplaza','mobilestore','univercell']leng = leng -1max = 0index = 0for m in models_list:price_list[index] = m.final_priceindex = index + 1s_info = ""s_info = s_info + str(da.get_supp_byId(m.supplier_id).name)if str(m.extra_info) != "":s_info = s_info + " with "s_info = s_info + str(m.extra_info)vendor_list.append(s_info)if(m.final_price > max):max = m.final_pricerange = 0if max<3000:range = 3000elif max>=3000 and max<5000:range = 5000elif max>=5000 and max<7000:range = 7000elif max>=7000 and max<10000:range = 10000elif max>=10000 and max<15000:range = 15000elif max>=15000 and max<20000:range = 20000elif max>=20000 and max<25000:range = 25000elif max>=25000 and max<30000:range = 30000elif max>=30000 and max<50000:range = 50000str3 = ""for p in price_list:str3 = str3 + str(p)str3 = str3 + ","str3 = str3[0:len(str3)-1]str4 = ""for v in vendor_list:str4 = str4 + vstr4 = str4 + "|"str4 = str4[0:len(str4)-1]ret_val = {}ret_val['val1'] = str3ret_val['val2'] = str4#ret_val['val1'] = price_list#ret_val['val2'] = vendor_liststr1 = ""models = da.get_all_models()for m in models:name = m.modelstr1 = str1 + "<option value="#str1 = str1 + "/'"str1 = str1 + unicode(name, "iso-8859-1")#str1 = str1 + "/'"if str(name) == str(model):str1 = str1 + " selected=yes"str1 = str1 + ">"str1 = str1 + unicode(name, "iso-8859-1")str1 = str1 + "</option>"ret_val['val3'] = str1ret_val['val4'] = rangestr2 = ""str2 = str2 + '<table align = "right"><tr><th>'str2 = str2 + "vendor"str2 = str2 + "</th><th>"str2 = str2 + "price"str2 = str2 + "</th></tr>"leng = len(vendor_list)j = 0while(j<leng):str2 = str2 + "<tr><td>"str2 = str2 + str(vendor_list[j])str2 = str2 + "</td><td>"str2 = str2 + str(price_list[j])str2 = str2 + "</td></tr>"j = j+1str2 = str2 + "</table>"ret_val['val5'] = str2return ret_val@expose(template="wiki20.templates.model" , content_type='text/xml')def model(self, **data):#print " I m in "id = int(data['id'])str1 = brandname = modelname = extra_i = sup_name = sup_site = sup_lastcrawled = ""quoted_p = final_p = 0da = DataHelper()mo = da.get_modbyId(id)brandname = mo.brandmodelname = mo.modelprlist = da.get_prbyMid(id)#print len(prlist)str1 = str1 + "<Mobile><mid>"str1 = str1 + str(id)str1 = str1 + "</mid><barandname>"str1 = str1 + unicode(brandname, "iso-8859-1")str1 = str1 + "</barandname><modelname>"str1 = str1 + unicode(modelname, "iso-8859-1")str1 = str1 + "</modelname>"sorted(prlist, key=lambda prices: prices.supplier_id)prev_sid = -1ct = 0for pr in prlist:quoted_p = pr.quoted_pricefinal_p = pr.final_priceextra_i = pr.extra_infopid = pr.idsid = pr.supplier_idsu = da.get_supp_byId(sid)sup_name = su.namesup_site = su.sitesup_lastcrawled = su.last_crawled'''print brandnameprint modelnameprint quoted_pprint final_pprint extra_iprint sup_nameprint sup_siteprint sup_lastcrawled'''if sid != prev_sid:if ct != 0:str1 = str1 + "</Supplier>";str1 = str1 + "<Supplier>";str1 = str1 + "<name>"str1 = str1 + unicode(sup_name, "iso-8859-1")str1 = str1 + "</name><sid>"str1 = str1 + str(sid)str1 = str1 + "</sid><site>"str1 = str1 + unicode(sup_site, "iso-8859-1")str1 = str1 + "</site><last_updated>"str1 = str1 + str(sup_lastcrawled)str1 = str1 + "</last_updated>"prev_sid = sidct = ct+1str1 = str1 + "<Price><pid>"str1 = str1 + str(pid)str1 = str1 + "</pid><quotedprice>"str1 = str1 + str(quoted_p)str1 = str1 + "</quotedprice><finalprice>"str1 = str1 + str(final_p)str1 = str1 + "</finalprice><extrainfo>"str1 = str1 + unicode(extra_i, "iso-8859-1")str1 = str1 + "</extrainfo></Price>"#str1 = str1 + "</Supplier>"#root = Element(str1)#xml_elem = xml.etree.ElementTree.fromstring(str1)str1 = str1 + "</Supplier>";str1 = str1 + "</Mobile>"ret_val = {}ret_val['val1'] = urllib.unquote(str1)#root#tree = ElementTree(root)#tree.write("/home/gaurav/code/TG2Test/src/wiki20/templates/model.html")print str1return ret_val@expose(template="wiki20.templates.modelIds" , content_type='text/xml')def mobileIds(self):da = DataHelper()mobiles = da.get_all_models()str1 = ""for m in mobiles:id = m.idmodel = m.modelbrand = m.brandstr1 = str1 + "<Mobile><id>"str1 = str1 + str(id)str1 = str1 + "</id><model>"str1 = str1 + unicode(model, "iso-8859-1")str1 = str1 + "</model><vendor>"str1 = str1 + unicode(brand, "iso-8859-1")str1 = str1 + "</vendor></Mobile>"ret_val = {}print str1ret_val['val1'] = urllib.unquote(str1)#rootreturn ret_val@expose('wiki20.templates.infibeam_form')def form_infibeam(self, **kw):#"""Show form to add data record for infibeam."""tmpl_context.form = create_infibeam_formreturn dict(modelname='code_words',page='Infibeam Data')@expose()def save_infibeam(self, **kw):"""Create a infibeam object and save it to the database."""initialize_table()set_code_word("INFIBEAM_DOMAINNAME",kw['INFIBEAM_DOMAINNAME'],"")print kw['INFIBEAM_DOMAINNAME']set_code_word("INFIBEAM_NO",kw['INFIBEAM_NO'],"")print kw['INFIBEAM_NO']set_code_word("INFIBEAM_CT",kw['INFIBEAM_CT'],"")set_code_word("INFIBEAM_URL",kw['INFIBEAM_URL'],"")set_code_word("INFIBEAM_HOMEPAGE",kw['INFIBEAM_HOMEPAGE'],"")set_code_word("INFIBEAM_REFERER",kw['INFIBEAM_REFERER'],"")set_code_word("INFIBEAM_VATPLUSTAX",kw['INFIBEAM_VATPLUSTAX'],"")set_code_word("INFIBEAM_REMOVELIST",kw['INFIBEAM_REMOVELIST'],"")set_code_word("INFIBEAM_XPATH1",kw['INFIBEAM_XPATH1'],"")set_code_word("INFIBEAM_XPATH2",kw['INFIBEAM_XPATH2'],"")set_code_word("INFIBEAM_XPATH3",kw['INFIBEAM_XPATH3'],"")flash("Data successfully saved.")redirect("form_infibeam")