当前位置: 首页>>代码示例>>Python>>正文


Python database.get_active_db函数代码示例

本文整理汇总了Python中netforce.database.get_active_db函数的典型用法代码示例。如果您正苦于以下问题:Python get_active_db函数的具体用法?Python get_active_db怎么用?Python get_active_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_active_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

 def post(self):
     fname = self.get_argument("filename", None)
     print(">>> upload %s" % fname)
     if self.request.headers.get("Content-Type") == "image/jpeg":
         data = self.request.body
     else:
         info = self.request.files["file"]
         data = info[0]["body"]
         if not fname:
             fname = info[0]["filename"]
     print("data size: %s" % len(data))
     rand = base64.urlsafe_b64encode(os.urandom(8)).decode()
     res = os.path.splitext(fname)
     basename, ext = res
     fname2 = basename + "," + rand + ext
     dbname = get_active_db()
     fdir = os.path.join("static", "db", dbname, "files")
     if not os.path.exists(fdir):
         os.makedirs(fdir)
     path = os.path.join(fdir, fname2)
     open(path, "wb").write(data)
     self.write(fname2)
     if ext.lower() in (".jpg", ".jpeg", ".png", ".gif"):
         fname3 = basename + "-resize-256" + "," + rand + ext
         path_thumb = os.path.join(fdir, fname3)
         os.system(r"convert -resize 256x256\> '%s' '%s'" % (path, path_thumb))
         fname4 = basename + "-resize-512" + "," + rand + ext
         path_thumb2 = os.path.join(fdir, fname4)
         os.system(r"convert -resize 512x512\> '%s' '%s'" % (path, path_thumb2))
         fname5 = basename + "-resize-128" + "," + rand + ext
         path_thumb3 = os.path.join(fdir, fname5)
         os.system(r"convert -resize 128x128\> '%s' '%s'" % (path, path_thumb3))
     print("<<< upload %s" % fname)
开发者ID:jzoldyck,项目名称:netforce,代码行数:33,代码来源:upload.py

示例2: create_thumbnails

 def create_thumbnails(self,ids,context={}):
     print("Product.create_thumbnails",ids)
     for obj in self.browse(ids):
         if not obj.image:
             continue
         dbname = database.get_active_db()
         if not dbname:
             return None
         fdir = os.path.join(os.getcwd(), "static", "db", dbname, "files")
         path=os.path.join(fdir,obj.image)
         basename,ext=os.path.splitext(obj.image)
         res = "," in basename
         if not res:
             rand = base64.urlsafe_b64encode(os.urandom(8)).decode()
             res = os.path.splitext(obj.image)
             basename, ext = res
             fname2 = basename + "," + rand + ext
             #rename image
             dest_path=fdir+"/"+fname2
             print("destination path and file name ",dest_path)
             cmd="cp %s %s"%(path, dest_path)
             os.system(cmd)
             obj.write({
                 'image': fname2,
             })
             utils.create_thumbnails(fname2)
         else:
             print ("called",obj.image)
             utils.create_thumbnails(obj.image)
开发者ID:nfco,项目名称:netforce,代码行数:29,代码来源:product.py

示例3: generals

 def generals(self, params,context={}):
     print_color("interface.generals.params%s" % params, "yellow")
     company_id = params.get("company_id")
     cashier_id = params.get("cashier_id")
     url = params.get("url")
     cashier_name = None
     if cashier_id:
         cs = get_model("pos.register").browse(int(cashier_id))
         cashier_name = cs.name
     theme = 'blue'
     if company_id:
         for c in get_model("pos.shop").search_browse([['company_id','=',company_id]]):
             theme = c.theme
     st = get_model("settings").browse(1)
     pos_st = get_model("pos.settings").browse(1)
     version=st.version
     menu=[
         {'key': 'current_sale', 'value' : 'Current Sale', 'active' : False},
         {'key': 'retreive_sale', 'value' : 'Retreive Sale', 'active' : False},
         {'key': 'complete_sale', 'value' : 'Complete Sale', 'active' : False},
     ]
     for m in menu:
         if m['key'] == url:
             m['active']=True
     return {
         'version' : version,
         'pos_theme' : pos_st.pos_theme,
         'theme' : theme,
         'dbname': get_active_db(),
         'cashier_name':cashier_name,
         'menu':menu
         }
开发者ID:anastue,项目名称:netforce_pos,代码行数:32,代码来源:pos_interface.py

示例4: get_ratio

 def get_ratio(self, uom_id):
     dbname = database.get_active_db()
     if (dbname, uom_id) in _cache:
         return _cache[(dbname, uom_id)]
     obj = self.browse(uom_id)
     _cache[(dbname, uom_id)] = obj.ratio
     return obj.ratio
开发者ID:jzoldyck,项目名称:netforce,代码行数:7,代码来源:uom.py

示例5: login

 def login(self, context={}):
     set_active_user(None)
     data = context["data"]
     db_name = data.get("db_name")
     if not db_name:
         raise Exception("Missing db name")
     database.set_active_db(db_name)
     login = data["login"]
     password = data["password"]
     user_id = get_model("base.user").check_password(login, password)
     if not user_id:
         audit_log("Invalid login (%s)" % login)
         db = database.get_connection()
         db.commit()
         raise Exception("Invalid login")
     try:
         print("login ok", login)
         set_active_user(1)
         user = get_model("base.user").browse(user_id)
         if user.profile_id.prevent_login or not user.active:
             raise Exception("User not allowed to login")
         t = time.strftime("%Y-%m-%d %H:%M:%S")
         user.write({"lastlog": t})
         profile = user.profile_id
         action = profile.home_action or "account_board"
         token = new_token(db_name, user_id)
         db = database.get_connection()
         res = db.get("SELECT * FROM pg_class WHERE relname='settings'")
         settings = get_model("settings").browse(1)
         version = settings.version
         mod_version = get_module_version()
         if version != mod_version:
             raise Exception("Database version (%s) is different than modules version (%s), please upgrade database before login." % (
                 version, mod_version))
         company_id = user.company_id.id or profile.login_company_id.id
         if not company_id:
             res = get_model("company").search([["parent_id", "=", None]])
             if not res:
                 raise Exception("No company found")
             company_id = res[0]
         comp = get_model("company").browse(company_id)
         return {
             "cookies": {
                 "dbname": database.get_active_db(),
                 "user_id": user_id,
                 "token": token,
                 "user_name": user.name,
                 "package": settings.package,
                 "company_id": company_id,
                 "company_name": comp.name,
             },
             "next": {
                 "type": "url",
                 "url": "/ui#name=%s" % action,
             },
             "login_action": action,
         }
     finally:
         set_active_user(user_id)
         audit_log("Login")
开发者ID:cyberhck,项目名称:netforce,代码行数:60,代码来源:login.py

示例6: cal_dimension

 def cal_dimension(self, ids, context={}):
     all_vals = {}
     dbname = database.get_active_db()
     for obj in self.browse(ids):
         master_img = obj.product_id.image
         master_path = os.path.join("static/db/", dbname, "files", master_img)
         frame = int(obj.get("rotate_frame"))
         column = int(obj.get("rotate_footage"))
         row = 1
         if frame and column:
             row = frame / column
         vals = {}
         im_path = obj.image
         if im_path and frame and column:
             filename = os.path.join("static/db/", dbname, "files", im_path)
             img = Image.open(filename)
             (width, height) = img.size
             swidth = math.floor(width / column)
             sheight = math.floor(height / row)
             vals["rotate_width"] = swidth
             vals["rotate_height"] = sheight
             vals["master_image"] = master_path
             all_vals[obj.id] = vals
         else:
             print("Not enough arguments given")
     return all_vals
开发者ID:Sorawit123,项目名称:netforce,代码行数:26,代码来源:product_image.py

示例7: _get_cache

 def _get_cache(self):
     global _cache
     dbname = get_active_db()
     cache = _cache.get(dbname)
     if cache is None:
         cache = self._load_cache()
     return cache
开发者ID:Sorawit123,项目名称:netforce,代码行数:7,代码来源:translation.py

示例8: get

 def get(self):
     self.get_argument("token") # TODO: check token
     dbname=database.get_active_db()
     db=database.get_connection()
     try:
         db.begin()
         set_active_user(None)
         user_id=1
         user=get_model("base.user").browse(user_id)
         t=time.strftime("%Y-%m-%d %H:%M:%S")
         user.write({"lastlog":t})
         comp=get_model("company").browse(1)
         set_active_user(user_id)
         audit_log("Login token")
         url="http://nf1.netforce.com/update_lastlogin?dbname=%s"%dbname
         req=urllib.request.Request(url)
         try:
             urllib.request.urlopen(req).read()
         except:
             print("ERROR: failed to update last login time")
         token=new_token(dbname,user_id)
         self.set_cookie("dbname",dbname)
         self.set_cookie("user_id",str(user_id))
         self.set_cookie("token",token)
         self.set_cookie("user_name",quote(user.name)) # XXX: space
         self.set_cookie("company_name",quote(comp.name))
         self.set_cookie("package",comp.package)
         self.redirect("http://%s.my.netforce.com/action#name=account_board"%dbname.replace("_","-"))
         db.commit()
     except:
         db.rollback()
开发者ID:Sorawit123,项目名称:netforce,代码行数:31,代码来源:login_token.py

示例9: get

 def get(self):
     raise Exception("Polling is disabled") # XXX
     #print("ListenPoll.get",os.getpid())
     global sending_notifs
     t=time.strftime("%Y-%m-%d %H:%M:%S")
     dbname=get_active_db()
     if not dbname:
         raise Exception("Missing dbname in long poll request")
     db=None
     try:
         db=get_connection()
         user_id=self.get_cookie("user_id",None)
         if user_id:
             user_id=int(user_id)
         res=db.get("INSERT INTO ws_listener (user_id,last_check_time) VALUES (%s,%s) RETURNING id",user_id,t)
         self.listener_id=res.id
         self.dbname=dbname
         listen_handlers[self.listener_id]=self
         if not sending_notifs:
             io_loop=tornado.ioloop.IOLoop.instance()
             io_loop.add_timeout(time.time()+POLL_WAIT,send_notifs) # XXX: should start this directly when process is started?
             sending_notifs=True
         db.commit()
     except:
         print("#########################################################")
         print("ERROR: ListenPoll.get failed")
         if db:
             db.rollback()
         import traceback
         traceback.print_exc()
开发者ID:Sorawit123,项目名称:netforce,代码行数:30,代码来源:listen_poll.py

示例10: get_rate

 def get_rate(self, ids, date=None, rate_type="buy", context={}):
     obj_id = ids[0]
     dbname = database.get_active_db()
     company_id = access.get_active_company()
     key = (dbname, company_id, obj_id, date, rate_type)
     if key in _cache and not context.get("no_cache"):
         return _cache[key]
     obj = self.browse(obj_id)
     res = None
     for rate in obj.rates:
         if rate.company_id.id != company_id:
             continue
         if date and rate.date > date:
             continue
         if rate_type == "buy":
             res = rate.buy_rate
             break
         else:
             res = rate.sell_rate
             break
     if res is None:
         for rate in obj.rates:
             if date and rate.date > date:
                 continue
             if rate_type == "buy":
                 res = rate.buy_rate
                 break
             else:
                 res = rate.sell_rate
                 break
     _cache[key] = res
     return res
开发者ID:analycer,项目名称:netforce,代码行数:32,代码来源:currency.py

示例11: get_file_path

def get_file_path(fname):
    if not fname:
        return None
    dbname = database.get_active_db()
    if not dbname:
        return None
    path = os.path.join(os.getcwd(), "static", "db", dbname, "files", fname)
    return path
开发者ID:nfco,项目名称:netforce,代码行数:8,代码来源:utils.py

示例12: _file_path

def _file_path(data, val, options={}):
    if val is None:
        return ""
    try:
        dbname = database.get_active_db()
        return "/static/db/" + dbname + "/files/" + val
    except:
        return val
开发者ID:nfco,项目名称:netforce,代码行数:8,代码来源:template.py

示例13: _replace

 def _replace(m):
     cid = m.group(1)
     cid = "<" + cid + ">"
     if cid not in content_ids:
         return m.group(0)
     fname = content_ids[cid][0]
     dbname = get_active_db()
     return "/static/db/" + dbname + "/files/" + fname
开发者ID:jzoldyck,项目名称:netforce,代码行数:8,代码来源:email_message.py

示例14: get_ratio

 def get_ratio(self, uom_id, context={}):
     dbname = database.get_active_db()
     if not context.get("no_cache"):
         if (dbname, uom_id) in _cache:
             return _cache[(dbname, uom_id)]
     obj = self.browse(uom_id)
     if not context.get("no_cache"):
         _cache[(dbname, uom_id)] = obj.ratio
     return obj.ratio
开发者ID:Sorawit123,项目名称:netforce,代码行数:9,代码来源:uom.py

示例15: emit

 def emit(self, record):
     msg = self.format(record)
     dbname = database.get_active_db()
     if dbname:
         dir_path = os.path.join("static", "db", dbname, "log")
         if not os.path.exists(dir_path):
             os.makedirs(dir_path)
         day = time.strftime("%Y-%m-%d")
         log_path = os.path.join(dir_path, "netforce-rpc-%s.log" % day)
         open(log_path, "a").write(msg + "\n")
开发者ID:Sorawit123,项目名称:netforce,代码行数:10,代码来源:log.py


注:本文中的netforce.database.get_active_db函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。