Ejemplo n.º 1
0
 def prepare(self):
     print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
     print("prepare")
     super(BaseController, self).prepare()
     website_id = self.request.headers.get("X-Website-ID")
     if website_id:
         website_id = int(website_id)
     else:
         res = get_model("website").search([["state", "=", "active"]])
         if not res:
             raise Exception("No website found")
         website_id = res[0]
     self.website_id = website_id
     website = get_model("website").browse(website_id)
     template.set_active_theme(website.theme_id.id)
     browse_ctx = {
         "website_id":
         website.id,
         "theme_id":
         website.theme_id.id,
         "sale_channel_id":
         website.sale_channel_id.id,
         "pricelist_id":
         website.sale_channel_id.pricelist_id.id
         if website.sale_channel_id else None,
     }
     lang = self.get_argument("set_lang", None)
     if lang:
         set_active_locale(lang)
         self.set_cookie("locale", lang)
     ctx = {}
     ctx["website"] = website
     ctx["database"] = get_active_db()
     ctx["locale"] = get_active_locale()
     ctx["ga_script"] = website.ga_script
     ctx["linklists"] = get_model("cms.linklist").search_browse([])
     ctx["product_groups"] = get_model("product.group").search_browse(
         [], context=browse_ctx)
     ctx["countries"] = get_model("country").search_browse([])  # XXX
     cart_id = self.get_cookie("cart_id", None)
     if cart_id:
         cart_id = int(cart_id)
         res = get_model("ecom.cart").search([["id", "=", cart_id]])
         if res:
             ctx["cart"] = get_model("ecom.cart").browse(cart_id)
         else:  # handle invalid cart_id cookie
             self.clear_cookie("cart_id")
     user_id = self.get_cookie("user_id", None)
     if user_id:
         user_id = int(user_id)
         user = get_model("base.user").browse(user_id)
         ctx["customer"] = user.contact_id
     offset = self.get_argument("offset", None)
     if offset:
         ctx["offset"] = int(offset)
     ctx["url"] = self.request.uri
     self.context = ctx
Ejemplo n.º 2
0
 def prepare(self):
     print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
     print("prepare")
     super(BaseController,self).prepare()
     website_id=self.request.headers.get("X-Website-ID")
     if website_id:
         website_id=int(website_id)
     else:
         res=get_model("website").search([["state","=","active"]])
         if not res:
             raise Exception("No website found")
         website_id=res[0]
     self.website_id=website_id
     website=get_model("website").browse(website_id)
     template.set_active_theme(website.theme_id.id)
     browse_ctx={
         "website_id": website.id,
         "theme_id": website.theme_id.id,
         "sale_channel_id": website.sale_channel_id.id,
         "pricelist_id": website.sale_channel_id.pricelist_id.id if website.sale_channel_id else None,
     }
     lang=self.get_argument("set_lang",None)
     if lang:
         set_active_locale(lang)
         self.set_cookie("locale",lang)
     ctx={}
     ctx["website"]=website
     ctx["database"]=get_active_db()
     ctx["locale"]=get_active_locale()
     ctx["ga_script"]=website.ga_script
     ctx["linklists"]=get_model("cms.linklist").search_browse([])
     ctx["product_groups"]=get_model("product.group").search_browse([],context=browse_ctx)
     ctx["countries"]=get_model("country").search_browse([]) # XXX
     cart_id=self.get_cookie("cart_id",None)
     if cart_id:
         cart_id=int(cart_id)
         res=get_model("ecom.cart").search([["id","=",cart_id]])
         if res:
             ctx["cart"]=get_model("ecom.cart").browse(cart_id)
         else: # handle invalid cart_id cookie
             self.clear_cookie("cart_id")
     user_id=self.get_cookie("user_id",None)
     if user_id:
         user_id=int(user_id)
         user=get_model("base.user").browse(user_id)
         ctx["customer"]=user.contact_id
     offset=self.get_argument("offset",None)
     if offset:
         ctx["offset"]=int(offset)
     ctx["url"]=self.request.uri
     self.context=ctx
Ejemplo n.º 3
0
 def get(self):
     #url="https://v5.inspection.in.th/inspectionreport/checkqr?id=1541844&password=f45681f1"
     current_local=get_active_locale()
     set_active_user(1) #admin
     set_active_locale('th_TH')
     db=get_connection() # prevent to error get transaction
     try:
         db.begin()
         id=self.get_argument("id")
         if not id:
             self.write("Missing ID")
             return
         password=self.get_argument("password")
         if not password:
             self.write("Missing Password")
             return
         ctx={
             'obj': None,
         }
         #res=db.query("select * from inspection where number=%s and password=%s",id,password)
         dom=[
             ['number','=', id],
             ['password','=', password]
         ]
         res=get_model("inspection").search_read(dom)
         if res:
             #t0=res[-1]['date']
             #t1=t0.split(" ")
             #res[-1]['date']='%s %s'%(sale_utils.date2thai(t1[0], format='%(d)s %(Tm)s %(BY)s'), t1[1])
             #res[-1]['date_register']=sale_utils.date2thai(res[-1]['date_register'], format='%(d)s %(Tm)s %(BY)s')
             ctx['obj']=res[-1]
         else:
             ctx['nothing']=True
         data=ctx['obj']
         html=render("checkqr",context=ctx, data=data)
         self.write(html)
     except Exception as e:
         self.write("ERROR : %s"%str(e))
     finally:
         if db:
             db.commit()
     set_active_locale(current_local)
Ejemplo n.º 4
0
 def get_block(self, name, page_id=None, post_id=None, context={}):
     # print("get_block",name,page_id,post_id)
     dbname = get_active_db()
     lang = get_active_locale()
     key = (dbname, name, page_id, post_id, lang)
     if key in _block_cache:
         #print("...cache hit")
         return _block_cache[key]
     #print("...cache miss")
     cond = [["name", "=", name]]
     if page_id:
         cond.append(["related_id", "=", "cms.page,%d" % page_id])
     if post_id:
         cond.append(["related_id", "=", "cms.blog.post,%d" % post_id])
     res = self.search(cond)
     if res:
         block = self.read(res, ["html"])[0]
     else:
         block = None
     _block_cache[key] = block
     return block
Ejemplo n.º 5
0
 def get_block(self, name, page_id=None, post_id=None, context={}):
     # print("get_block",name,page_id,post_id)
     dbname = get_active_db()
     lang = get_active_locale()
     key = (dbname, name, page_id, post_id, lang)
     if key in _block_cache:
         #print("...cache hit")
         return _block_cache[key]
     #print("...cache miss")
     cond = [["name", "=", name]]
     if page_id:
         cond.append(["related_id", "=", "cms.page,%d" % page_id])
     if post_id:
         cond.append(["related_id", "=", "cms.blog.post,%d" % post_id])
     res = self.search(cond)
     if res:
         block = self.read(res, ["html"])[0]
     else:
         block = None
     _block_cache[key] = block
     return block
Ejemplo n.º 6
0
 def translate(self, original):
     lang = get_active_locale()
     cache = self._get_cache()
     return cache.get((original, lang))