コード例 #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
コード例 #2
0
ファイル: cms_base.py プロジェクト: Sorawit123/netforce
 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
コード例 #3
0
 def prepare(self):
     print(">>> [%s] %s %s %d" %
           (time.strftime("%Y-%m-%d %H:%M:%S"), self.request.method,
            self.request.uri, os.getpid()))
     dbname = None
     if config.get("database"):
         dbname = config.get("database")
     elif config.get("database_from_domain"):
         request = self.request
         host = request.host
         subdom = host.split(".", 1)[0]
         if subdom not in ("all", "clients"):  # XXX
             dbname = subdom.replace("-", "_")
     elif config.get("database_from_http_header"):
         dbname = self.request.headers.get("X-Database")
     if not dbname:
         dbname = self.get_cookie("dbname")
     database.set_active_db(dbname)
     schema = None
     if config.get("schema"):
         schema = config.get("schema")
     elif self.request.headers.get("X-Schema"):
         schema = self.request.headers.get("X-Schema")
     elif self.get_cookie("schema"):
         schema = self.get_cookie("schema")
     database.set_active_schema(schema)
     template.set_active_theme(None)
     locale = self.get_cookie("locale") or "en_US"
     netforce.locale.set_active_locale(locale)
     user_id = self.get_cookie("user_id")
     if user_id and dbname:
         user_id = int(user_id)
         token = utils.url_unescape(self.get_cookie("token"))
         if utils.check_token(dbname, user_id, token):
             access.set_active_user(user_id)
         else:
             print("WARNING: wrong token! (dbname=%s user_id=%s token=%s)" %
                   (dbname, user_id, token))
             self.clear_cookie("user_id")
             raise Exception("Invalid token")
     else:
         access.set_active_user(None)
     ip_addr = self.request.headers.get(
         "X-Real-IP") or self.request.remote_ip
     access.set_ip_addr(ip_addr)
     company_id = self.get_cookie("company_id")
     if company_id:
         company_id = int(company_id)
         access.set_active_company(company_id)
     else:
         access.set_active_company(None)
コード例 #4
0
ファイル: controller.py プロジェクト: Sorawit123/netforce
 def prepare(self):
     print(">>> [%s] %s %s %d" %
           (time.strftime("%Y-%m-%d %H:%M:%S"), self.request.method, self.request.uri, os.getpid()))
     dbname = None
     if config.get("database"):
         dbname = config.get("database")
     elif config.get("database_from_domain"):
         request = self.request
         host = request.host
         subdom = host.split(".", 1)[0]
         if subdom not in ("all", "clients"):  # XXX
             dbname = subdom.replace("-", "_")
     elif config.get("database_from_http_header"):
         dbname = self.request.headers.get("X-Database")
     if not dbname:
         dbname = self.get_cookie("dbname")
     database.set_active_db(dbname)
     schema = None
     if config.get("schema"):
         schema = config.get("schema")
     elif self.request.headers.get("X-Schema"):
         schema = self.request.headers.get("X-Schema")
     elif self.get_cookie("schema"):
         schema = self.get_cookie("schema")
     database.set_active_schema(schema)
     template.set_active_theme(None)
     locale = self.get_cookie("locale") or "en_US"
     netforce.locale.set_active_locale(locale)
     user_id = self.get_cookie("user_id")
     if user_id and dbname:
         user_id = int(user_id)
         token = utils.url_unescape(self.get_cookie("token"))
         if utils.check_token(dbname, user_id, token):
             access.set_active_user(user_id)
         else:
             print("WARNING: wrong token! (dbname=%s user_id=%s token=%s)" % (dbname, user_id, token))
             self.clear_cookie("user_id")
             raise Exception("Invalid token")
     else:
         access.set_active_user(None)
     ip_addr = self.request.headers.get("X-Real-IP") or self.request.remote_ip
     access.set_ip_addr(ip_addr)
     company_id = self.get_cookie("company_id")
     if company_id:
         company_id = int(company_id)
         access.set_active_company(company_id)
     else:
         access.set_active_company(None)