Пример #1
0
def set_license_bind(lid, did, dname, sid, sname, surl, pexp, osname):
    if not dbsl: return {'errmsg': 'No database'}
    t = dbsl.transaction()
    try:
        count = web.listget(
            dbsl.select("DM_CLIENTS", what="COUNT(*) CNT",
                        where="ISPRIMARY=1").list(), 0, {}).get("CNT", 0)
        pubpem, pripem = gen_rsakey()
        if web.listget(
                dbsl.select("DM_CLIENTS",
                            vars=locals(),
                            where="LICENSEID=$lid").list(), 0, None):
            dbsl.update("DM_CLIENTS",
                        vars=locals(),
                        where="LICENSEID=$lid",
                        DEVICEID=did,
                        DEVICENAME=dname,
                        SERVERID=sid,
                        SERVERNAME=sname,
                        SERVERURL=surl,
                        PUBKEY=pubpem,
                        OSNAME=osname,
                        push_expire=(pexp or 0))
        else:
            ispri = 1 if count == 0 else 0
            dbsl.insert("DM_CLIENTS",
                        LICENSEID=lid,
                        DEVICEID=did,
                        DEVICENAME=dname,
                        ISPRIMARY=ispri,
                        SERVERID=sid,
                        SERVERNAME=sname,
                        SERVERURL=surl,
                        PUBKEY=pubpem,
                        OSNAME=osname,
                        push_expire=(pexp or 0))
        dbsl.update("DM_CONFIG",
                    vars=locals(),
                    where="CKEY='ENABLE_BIND'",
                    CVAL=0)
    except Exception as e:
        t.rollback()
        traceback.print_exc()
        return {"errmsg": e}
    else:
        t.commit()
        load_pubkeys()
        return {
            "body": {
                "pem": pripem,
                "sid": sid,
                "sname": sname,
                "surl": surl,
                "lid": lid,
                "osname": osname
            }
        }
Пример #2
0
def getRecentOnePostsInNode(nodeId):
    return web.listget(
        db.select('_post',
                  limit=1,
                  order='id DESC',
                  vars=dict(nodeId=nodeId),
                  where='nodeId = $nodeId'), 0, {})
Пример #3
0
def get_just_added_comment(uid, pid):
    return web.listget(
        db.select('_post_comments',
                  vars=dict(pid=pid, uid=uid),
                  where='pid = $pid and uid = $uid',
                  order='id DESC',
                  limit=1), 0, {})
Пример #4
0
def make_question(url, category):
    """Create the random question from wikipedia."""
    try:
        article = lib.dnl(url, referer='http://en.wikipedia.org/')
        xml = lib.parse_xml(article)
    except:
        return False
        raise 'Either can\'t download the wikipedia article or can\'t parse it.'
    
    answer = xml.findtext('.//h1').encode('utf-8')
    snippet = ''
    for p in xml.xpath('//div[@id="bodyContent"]/p'):
        snippet += etree.tostring(p, method='text', encoding='utf-8').strip() + ' '
#        snippet += lib.strip_tags(etree.tostring(p)) + '\n'
    snippet = snippet[0:snippet_size].replace('\n', '<br />').decode('utf-8')
    snippet = re.sub('\[\d+\]', '', snippet)
    
    snippet_secret = snippet
    for a in answer.split():
        if a[-1] == 's': a = a[:-1]
        p = re.compile(r'\b%ss?\b' % re.escape(a), re.I)
        snippet_secret = p.sub('<strong class="depleted">' + '?' * len(a) + '</strong>', snippet_secret)
    
    image_url = web.listget(
        xml.xpath('//img[@class="thumbimage"]//@src'), 0, '')
    
    return web.storage(
        dict(answer=answer, snippet_secret=snippet_secret, category=category,
        snippet=snippet, wiki_url=url, image_url=image_url))
Пример #5
0
def add_compose(fpath):
    if not dbsl: return {'errmsg': 'No database'}
    realpath = utils.prefixStorageDir(
        fpath) if not os.path.isabs(fpath) else fpath
    if not os.path.isfile(realpath):
        return {'errmsg': 'File %s not exists' % fpath}
    folder = os.path.split(os.path.abspath(realpath))[0]
    if not web.listget(
            dbsl.select("DM_COMPOSE",
                        vars=locals(),
                        where="FILEPATH=$fpath and FOLDER=$folder").list(), 0):
        if fpath.lower().endswith(('yaml', 'yml')):
            alias = os.path.basename(os.path.split(fpath)[0])
        else:
            alias = os.path.basename(fpath)
        t = dbsl.transaction()
        try:
            dbsl.insert("DM_COMPOSE",
                        ALIAS=alias,
                        FILEPATH=fpath,
                        FOLDER=folder)
        except Exception as e:
            t.rollback()
            traceback.print_exc()
            return {"errmsg": e}
        else:
            t.commit()
            return {}
    else:
        return {"errmsg": "%s already exists" % fpath}
Пример #6
0
    def match(path):
        for pat, type, property, default_title in patterns:
            m = web.re_compile('^' + pat).match(path)
            if m:
                prefix = m.group()
                extra = web.lstrips(path, prefix)
                tokens = extra.split("/", 2)

                # `extra` starts with "/". So first token is always empty.
                middle = web.listget(tokens, 1, "")
                suffix = web.listget(tokens, 2, "")
                if suffix:
                    suffix = "/" + suffix

                return type, property, default_title, prefix, middle, suffix
        return None, None, None, None, None, None
Пример #7
0
def batchInsertPreNf(market=None,brand=None):
    ##dbconn.query("insert into prenaifen (name,duration,weight,spec,brand,series,sellto,age,duan,pack,place,price,img) select name,duration,weight,spec,brand,series,sellto,age,duan,pack,place,price,img from naifenitem where brand = $brand and market = $market",vars=dict(brand=brand,market=market))
    res = dbconn.query(u"select * from prenaifen where brand = $brand",vars=dict(brand=brand))
    for r in res:
        res1  = dbconn.query(u"select * from naifenitem where name = $name and market=$market",vars=dict(name=r.name,market=market))
        item = web.listget(res1,0,None)
        dbconn.insert("prmatch",prid=r.ID,itemid=item.itemid,market=market)
Пример #8
0
def already_voted(module_id, user_ip):
    return web.listget(
        db.select('votes',
            vars = dict(ip=user_ip, id=module_id),
            what = 'count(vote)', 
            where = 'ip = $ip and module_id = $id',
            group = 'module_id having count(module_id) > 0'), 0, False)
Пример #9
0
    def match(path):
        for pat, type, property, default_title in patterns:
            m = web.re_compile('^' + pat).match(path)
            if m:
                prefix = m.group()
                extra = web.lstrips(path, prefix)
                tokens = extra.split("/", 2)

                # `extra` starts with "/". So first token is always empty.
                middle = web.listget(tokens, 1, "")
                suffix = web.listget(tokens, 2, "")
                if suffix:
                    suffix = "/" + suffix

                return type, property, default_title, prefix, middle, suffix
        return None, None, None, None, None, None
Пример #10
0
def get_question(question):
    """Get a specific question from the cache."""
    return web.listget(
        db.select('wikitrivia_cache',
                  vars=dict(url=question.wiki_url),
                  where='wiki_url = $url',
                  limit=1), 0, False)
Пример #11
0
def push_message(lid, pkey, data):
    if not dbsl: return {'errmsg': 'No database'}
    lobj = web.config.vars.pubkeys.get(lid)
    if not lobj:
        load_pubkeys()
        lobj = web.config.vars.pubkeys.get(lid)
    if not lobj: return {'errmsg': 'License not exists'}
    if not lobj.get('EXNOTIISON'):
        load_pubkeys()
        lobj = web.config.vars.pubkeys.get(lid)
    if not lobj.get('EXNOTIISON'):
        return {'errmsg': 'External notification is off'}
    if not pkey or (pkey and lobj.get('EXNOTIPASS') != pkey):
        return {'errmsg': 'Require password to send external notification'}
    if not data.get('body'): return {'errmsg': 'body required'}
    if '%s' % data.get('level', '') not in ('1', '2', '3'): data['level'] = 1
    from . import apush
    try:
        aobj = web.listget(
            dbsl.select(
                "DM_ALERTS",
                vars=locals(),
                where=
                "LICENSEID=$lid and CNAME='--sys--' and ALTYPE=0 and ALENABLED=0"
            ).list(), 0, None)
        if not aobj:
            alid = dbsl.insert("DM_ALERTS",
                               ALSTR='',
                               ALVAL='',
                               ALPUSH=1,
                               LICENSEID=lid,
                               CNAME='--sys--',
                               ALTYPE=0,
                               ALENABLED=0,
                               ALLEVEL=data.get('level', 1))
        else:
            alid = aobj.ALID
        msgid = dbsl.insert("DM_MESSAGE",
                            ALID=alid,
                            MSGSTAMP=time.time(),
                            ISREAD=0,
                            ISPUSHED=1,
                            MSGKEYWORD=data.get('title', ''),
                            MSGBODY=data.get('body', ''),
                            MSGURL=data.get('url', ''))
        if lobj.get('push_expire', 0) <= time.time():
            load_pubkeys()
            lobj = web.config.vars.pubkeys.get(lid)
        if lobj.get('push_expire', 0) <= time.time():
            return {'errmsg': 'License/Push service expired'}
        else:
            retval = apush.pushNotification(
                lobj.get('LICENSEID', ''), lobj.get('SERVERID', ''),
                lobj.get('DEVICEID', ''), data.get('title', ''),
                data.get('body', ''),
                'domapp://message/%s?lid=%s' % (msgid, lid))
            retval = formator.json_object(retval)
            return retval
    except Exception as e:
        return {'errmsg': str(e)}
Пример #12
0
def getUserByID(userid):
    res = dbconn.query("""
                            select * from user_info ui
                                 where ui.userid = $userid
                       """,
                       vars=dict(userid=userid))
    u = web.listget(res, 0, None)
    return u
Пример #13
0
def get_random_question(category):
    """Get a random quiz question from the cache."""
    return web.listget(
        db.select('wikitrivia_cache',
                  vars=dict(category=category),
                  where='category = $category',
                  limit=1,
                  order='rand()'), 0, False)
Пример #14
0
def get_module(id):
    """Get a specific module by its id."""
    return web.listget(
        db.select('modules', 
            vars = dict(id=id), 
            what = 'id, title, description, author, author_affiliation, title_url, \
                    author_email, render_inline, screenshot, calculated_vote, url',
            where='id = $id'), 0, False)
Пример #15
0
def getLastTimeStamp(userid):
    r = web.listget(
        dbconn.query(
            "select max(timeStamp) as timeStamp from user_data where userid=$userid",
            vars=dict(userid=userid)), 0, None)
    if r:
        return date_to_timestamp(r.timeStamp)
    return None
Пример #16
0
def get_random_wiki_url(category):
    """Use yahoo to get a random wikipedia url."""
    wiki_url = ''
    if categories.yahoo_queries.has_key(category):
        query = categories.get_yahoo_query(category)
        wiki_url = web.listget(
            lib.yahoo_search(query, random.randint(0, question_range), 1), 0, {}).get('url', '')
    return wiki_url
Пример #17
0
def set_syskey(key, val):
    if not dbsl: return
    if web.listget(
            dbsl.select("DM_CONFIG", vars=locals(), where="CKEY=$key").list(),
            0, None):
        dbsl.update("DM_CONFIG", vars=locals(), where="CKEY=$key", CVAL=val)
    else:
        dbsl.insert("DM_CONFIG", CKEY=key, CVAL=val)
Пример #18
0
def get_special_question(ID_special_question):
    special_question_row = web.listget(list(db.select('special_questions',dict(ID_special_question=ID_special_question),where='ID_special_question=$ID_special_question')), 0, default=None)
    if special_question_row is None:
        return None
    else:
        ID_special_question=special_question_row['ID_special_question']
        description_special_question=special_question_row['Description']
        question_list = [Question(row['Description'],row['Answer']) for row in list(db.select('questions',dict(ID_special_question=ID_special_question),where='ID_special_question=$ID_special_question'))]
        return SpecialQuestion(description_special_question,question_list)
Пример #19
0
def get_by_id(id):
    return web.listget(
        db.select(
            'applicants as a, users as u',
            vars=dict(id=id),
            what='a.*, nickname',
            where=
            'a.id=$id and (u.id = a.decided_by_user_id or a.decided_by_user_id is NULL)'
        ), 0, {})
Пример #20
0
def get_random_wiki_url(category):
    """Use yahoo to get a random wikipedia url."""
    wiki_url = ''
    if categories.yahoo_queries.has_key(category):
        query = categories.get_yahoo_query(category)
        wiki_url = web.listget(
            lib.yahoo_search(query, random.randint(0, question_range), 1), 0,
            {}).get('url', '')
    return wiki_url
Пример #21
0
def get_module(id):
    """Get a specific module by its id."""
    return web.listget(
        db.select(
            'modules',
            vars=dict(id=id),
            what=
            'id, title, description, author, author_affiliation, title_url, \
                    author_email, render_inline, screenshot, calculated_vote, url',
            where='id = $id'), 0, False)
Пример #22
0
def get_message(msgid):
    if not dbsl: return {'errmsg': 'No database'}
    retval = web.listget(
        dbsl.select(
            "DM_ALERTS A, DM_MESSAGE M",
            what=
            "A.ALID,A.CNAME,ALTYPE,ALLEVEL,MSGID,MSGSTAMP,ISREAD,ISPUSHED,MSGKEYWORD,MSGBODY",
            vars=locals(),
            where="A.ALID=M.ALID AND M.MSGID=$msgid").list(), 0, {})
    return retval
Пример #23
0
 def GET(self):
     data = web.input()
     naifenid = data.naifenid
     r = web.listget(dbconn.query("""
         select n.itemid,n.market from prmatch m
         join naifenitem n
         on m.itemid = n.itemid and m.market = n.market
         where m.naifenid = $naifenid
     """,vars=dict(naifenid=naifenid)),0,None)
     if r:
         return web.seeother(getItemUrl(r.itemid,r.market))
Пример #24
0
 def GET(self,name):
     naifenid = int(name)
     nf = web.listget(dbconn.query("select * from formalnaifen where id = $naifenid",vars=dict(naifenid=naifenid)),0,None)
     
     nfs = dbconn.query("""
             select n.price,n.market,n.itemid from prmatch m
             join formalnaifen f
             on f.id = m.naifenid
             join naifenitem n
             on m.itemid = n.itemid and m.market = n.market
             where f.id= $naifenid
     """,vars=dict(naifenid=naifenid))
     return render.naifen(nf=nf,nfs=nfs)
Пример #25
0
def get_related(module_id): 
    """Get a similar module."""
    module_tags = [t.tag for t in tags.get_tags(module_id)]
    
    m = web.listget(
        db.select('tags', 
            vars  = dict(id=module_id, tags=module_tags),
            what  = 'module_id',
            where = 'module_id != $id and %s' % web.sqlors("tag = ", module_tags),
            group = 'module_id having count(module_id) > 1',
            order = 'rand()'), 0, False)
    
    return m and get_module(m.module_id)
Пример #26
0
def count_message2(lid, cname, skey=''):
    if not dbsl: return []
    swhere = "A.ALID=M.ALID and A.LICENSEID=$lid"
    if cname:
        swhere += " AND A.CNAME=$cname"
    if skey:
        skey = '%' + skey + '%'
        swhere += " AND MSGBODY like $skey"
    return web.listget(
        dbsl.select("DM_ALERTS A, DM_MESSAGE M",
                    what="COUNT(MSGID) CNT",
                    vars=locals(),
                    where=swhere).list(), 0, {}).get('CNT', 0)
Пример #27
0
def update_calculated_vote(module_id):
    min_votes = 5
    r = web.listget(
        db.select('votes',
            vars = dict(id=module_id),
            what = 'sum(vote) / count(module_id) as calculated_vote', 
            where = 'module_id = $id',
            group = 'module_id having count(module_id) > %s' % min_votes), 0, False)
    
    if r:
        db.update('modules', 
            vars = dict(id=module_id),
            where='id = $id',    
            calculated_vote=r.calculated_vote)
Пример #28
0
def get_related(module_id):
    """Get a similar module."""
    module_tags = [t.tag for t in tags.get_tags(module_id)]

    m = web.listget(
        db.select('tags',
                  vars=dict(id=module_id, tags=module_tags),
                  what='module_id',
                  where='module_id != $id and %s' %
                  web.sqlors("tag = ", module_tags),
                  group='module_id having count(module_id) > 1',
                  order='rand()'), 0, False)

    return m and get_module(m.module_id)
Пример #29
0
    def GET(self, img_id):
        img = image.get_img_by_imgid(img_id)
        author = web.listget(users.get_users_by_id(img.userID) , 0, {})

        fav_user = image.GetFavImageByImageId(img_id).list()
        fav_user_ids = []
        for i in xrange(len(fav_user)):
            fav_user_ids += str(fav_user[i].user_id).split()

        usernnames = []
        for i in xrange(len(fav_user_ids)):
            usernnames += users.get_users_by_id(fav_user_ids[i])

        return view.base03(view.photo_fans(img_id, img, usernnames, author), user, siteName, 2)
Пример #30
0
    def GET(self, img_id):
        img = image.get_img_by_imgid(img_id)
        author = web.listget(users.get_users_by_id(img.userID), 0, {})

        fav_user = image.GetFavImageByImageId(img_id).list()
        fav_user_ids = []
        for i in xrange(len(fav_user)):
            fav_user_ids += str(fav_user[i].user_id).split()

        usernnames = []
        for i in xrange(len(fav_user_ids)):
            usernnames += users.get_users_by_id(fav_user_ids[i])

        return view.base(view.photo_fans(img_id, img, usernnames, author),
                         user, siteName)
Пример #31
0
def fix_dirs(data):
    data = list(data)
    
    keys = set()
    for id, author, t, comment, docs in data:
        keys.update(doc['key'] for doc in docs if web.listget(doc['key'].split("/"), 1) not in skip_dirs)

    dirnames = set(os.path.dirname(k) for k in keys)

    def f(doc):
        if doc['key'] in dirnames:
            doc['key'] = doc['key'].rstrip("/") + "/index"
        return doc
        
    return _map_docs(f, data)
Пример #32
0
def main():
    data = read()
    data = fix_lang(data)
    data = fix_dirs(data)
    data = sorted(data, key=lambda d: d[2])
    
    spammers = [email.strip() for email in open("data/spammers.txt")]
    spamedits = [id.strip() for id in open("data/spamedits.txt")]

    skip_dirs = "user permission macros templates type user group usergroup".split()
    
    system("rm -rf build && mkdir build && cd build && git init")
    
    for id, author, t, comment, docs in data:
        if "http://" in comment and "webpy.org" not in comment:
            print "ignoring changeset: %s" % str((id, author, t, comment))
            continue

        author = re.sub(" +", " ", author)
        if author.strip() in spammers or id in spamedits:
            print "ignoring spam: %s" % str((id, author, t, comment))
            continue
            
        bad_keys = ['\xe0\xb1\x86recentchanges.md', ').md']
        
        print "** processing changeset", id, t
        added = False
        for doc in docs:
            key = doc['key'][1:].encode('utf-8') + ".md"
            if doc['type']['key'] == '/type/page' and web.listget(doc['key'].split("/"), 1) not in skip_dirs and key not in bad_keys:
                title = doc.get('title', '')
                body = doc.get("body", {})
                if isinstance(body, dict):
                    body = body.get("value", "").replace("\r\n", "\n")
                    
                write("build/" + key, title, body)
                system("cd build && git add '%s'" % key)
                added = True
                
        if author == "annonymous":
            author = "anonymous <*****@*****.**>"

        if added:
            system("cd build && git commit -m %s --date='%s' --author='%s'" % (simplejson.dumps(comment), git_date(t), author))
            
    system("cp -r _layouts static build")
    system("cd build && git add _layouts static && git commit -m 'Added layouts and static file'")
Пример #33
0
def del_license_bind(lid):
    if not dbsl: return {'errmsg': 'No database'}
    t = dbsl.transaction()
    try:
        dbsl.delete("DM_CLIENTS", vars=locals(), where="LICENSEID=$lid")
        if web.listget(
                dbsl.select("DM_CLIENTS", what="count(*) CNT").list(), 0,
            {}).get('CNT', 0) == 0:
            set_syskey('ENABLE_BIND', 1)
    except Exception as e:
        t.rollback()
        traceback.print_exc()
        return {"errmsg": e}
    else:
        t.commit()
        web.config.vars.pubkeys.pop(lid, None)
        return {}
Пример #34
0
 def get(self, query):
     """
     Get values from the cache given a query. 
     
     The variable query is a string or an object with a unique representation.
     An object with a unique representation must implement instance variable "uniq".
     """
     query = get_unique_repr(query)
     key = self._make_key(query)
     r = self.db.select('cache', vars=dict(key=key), where='_key = $key', limit=1)
     r = web.listget(r, 0)
     
     value = None
     if r:
         if not r.sticky:
             self.db.query('update cache set datetime=now() where _key = $key', vars=dict(key=key))
         value = pickle.loads(base64.b64decode(r.value))
     return value
Пример #35
0
def set_alert(params):
    if not dbsl: return {'errmsg': 'No database'}
    retval = chk_alert(params)
    if retval.get('errmsg'): return retval
    t = dbsl.transaction()
    try:
        if params.alid and web.listget(
                dbsl.select("DM_ALERTS",
                            vars=locals(),
                            where="ALID=$params.alid").list(), 0, None):
            dbsl.update("DM_ALERTS",
                        vars=locals(),
                        where="ALID=$params.alid",
                        LICENSEID=params.lid,
                        CNAME=params.cname,
                        ALTYPE=params.altype,
                        ALSTR=params.alstr,
                        ALVAL=params.alval,
                        ALENABLED=params.enabled,
                        ALPUSH=params.push,
                        ALLEVEL=params.level)
        else:
            dbsl.insert("DM_ALERTS",
                        LICENSEID=params.lid,
                        CNAME=params.cname,
                        ALTYPE=params.altype,
                        ALSTR=params.alstr,
                        ALVAL=params.alval,
                        ALENABLED=params.enabled,
                        ALPUSH=params.push,
                        ALLEVEL=params.level)
    except Exception as e:
        t.rollback()
        traceback.print_exc()
        return {"errmsg": e}
    else:
        t.commit()
        load_alerts()
        return {}
Пример #36
0
def make_question(url, category):
    """Create the random question from wikipedia."""
    try:
        article = lib.dnl(url, referer='http://en.wikipedia.org/')
        xml = lib.parse_xml(article)
    except:
        return False
        raise 'Either can\'t download the wikipedia article or can\'t parse it.'

    answer = xml.findtext('.//h1').encode('utf-8')
    snippet = ''
    for p in xml.xpath('//div[@id="bodyContent"]/p'):
        snippet += etree.tostring(p, method='text',
                                  encoding='utf-8').strip() + ' '


#        snippet += lib.strip_tags(etree.tostring(p)) + '\n'
    snippet = snippet[0:snippet_size].replace('\n', '<br />').decode('utf-8')
    snippet = re.sub('\[\d+\]', '', snippet)

    snippet_secret = snippet
    for a in answer.split():
        if a[-1] == 's': a = a[:-1]
        p = re.compile(r'\b%ss?\b' % re.escape(a), re.I)
        snippet_secret = p.sub(
            '<strong class="depleted">' + '?' * len(a) + '</strong>',
            snippet_secret)

    image_url = web.listget(xml.xpath('//img[@class="thumbimage"]//@src'), 0,
                            '')

    return web.storage(
        dict(answer=answer,
             snippet_secret=snippet_secret,
             category=category,
             snippet=snippet,
             wiki_url=url,
             image_url=image_url))
Пример #37
0
def read_wexin(weixincode):
    '''从数据库读取微信公众号账户信息'''
    global wxaccount
    m = web.listget(
        dbFrame.select("WX_ACCOUNT",
                       vars=locals(),
                       where='WEIXIN_CODE=$weixincode').list(), 0)
    if m:
        m.MENUS = json.dumps(MENUS, ensure_ascii=False)
        print '-' * 20, 'Read WX Account [%s].' % weixincode
        wxaccount.ORIGINAL_ID = m.ORIGINAL_ID.encode('utf8')
        wxaccount.APPID = m.APPID.encode('utf8')
        wxaccount.APPSECRET = m.APPSECRET.encode('utf8')
        wxaccount.TOKEN = m.TOKEN.encode('utf8') if m.TOKEN else ''
        wxaccount.ACCESSTOKEN = m.ACCESSTOKEN.encode(
            'utf8') if m.ACCESSTOKEN else ''
        wxaccount.EXPIRES = m.EXPIRES
        wxaccount.JSAPI_TICKET = m.JSAPI_TICKET
        wxaccount.JSAPI_EXPIRES = m.JSAPI_EXPIRES
        wxaccount.WEBTOKEN = m.WEBTOKEN.encode('utf8') if m.WEBTOKEN else ''
        wxaccount.WEBEXPIRES = m.WEBEXPIRES
        wxaccount.MCH_ID = m.MCH_ID.encode('utf8') if m.MCH_ID else ''
        wxaccount.WXPAY_KEY = m.WXPAY_KEY.encode('utf8') if m.WXPAY_KEY else ''
Пример #38
0
    def _split(self, path):
        """Splits the path as required by the get_readable_path.
        
            >>> _split = ReadableUrlProcessor()._split

            >>> _split('/b/OL1M')
            ('/b/OL1M', '', '')
            >>> _split('/b/OL1M/foo')
            ('/b/OL1M', 'foo', '')
            >>> _split('/b/OL1M/foo/cover')
            ('/b/OL1M', 'foo', '/cover')
            >>> _split('/b/OL1M/foo/cover/bar')
            ('/b/OL1M', 'foo', '/cover/bar')
        """
        tokens = path.split('/', 4)

        prefix = '/'.join(tokens[:3])
        middle = web.listget(tokens, 3, '')
        suffix = '/'.join(tokens[4:])

        if suffix:
            suffix = '/' + suffix

        return prefix, middle, suffix
Пример #39
0
 def get_color_obj(color):
     if isinstance(color, str):
         color = web.listget(
             [c for c in COLOR_PALETTE if c['name'] is color], 0)
     return color
Пример #40
0
def get_just_added_comment(uid, pid):
    return web.listget(
        db.select('_post_comments', vars = dict(pid=pid, uid = uid), where='pid = $pid and uid = $uid', order='id DESC', limit = 1), 0, {})
Пример #41
0
def hasNfitem(nf):
    return web.listget(dbconn.query("select * from naifenitem where itemid=$itemid and market=$market",vars=dict(itemid=nf.itemid,market=nf.market)),0,None)
Пример #42
0
def get_serverinfo(lid):
    m = web.listget(
        dbsl.select("DM_CLIENTS", vars=locals(),
                    where="LICENSEID=$lid").list(), 0, {})
    return (m.get("SERVERNAME"), m.get('code_server') or '', m.get('SERVERURL')
            or '')
Пример #43
0
def get_syskey(key, defval=None):
    if not dbsl: return
    m = web.listget(
        dbsl.select("DM_CONFIG", vars=locals(), where="CKEY=$key").list(), 0,
        None)
    return m.CVAL if m else defval
Пример #44
0
def insertPreNf(itemid,market):
    dbconn.query("insert into prenaifen name, duration, weight, spec, brand, series, sellto, age, duan, pack, place, price, img select from naifenitem name, duration, weight, spec, brand, series, sellto, age, duan, pack, place, price, img where itemid=$itemid and market=$market",vars=dict(itemid=itemid,market=market))
    r = web.listget(dbconn.query("select last_insert_id() as lastid"),0,None)
    return r.lastid
Пример #45
0
def get_user_by_email(email):
    result = db.select('users', vars=dict(email=email), where=web.db.sqlwhere({'email': email, 'is_active': '1'})).list()
    return web.listget(result, 0, {})
Пример #46
0
 def _delete_lru(self):
     r = self.db.query('select count(*) as size from cache')
     r = web.listget(r, 0)
     n = r.size - MAX_SIZE 
     if n > 0:
         self.db.query('delete from cache where sticky !=1 order by datetime limit %s' % n)
Пример #47
0
def fix_pagination(s):
    if s is None:
        s = ''
    return web.listget(re.findall('^\w?[\d-]+', s), 0)
Пример #48
0
 def get_color_obj(color):
     if isinstance(color, str):
         color = web.listget(
             [c for c in COLOR_PALETTE if c['name'] is color], 0)
     return color
Пример #49
0
def getThisPostByUserId(postAuthor):
    return web.listget(
        db.select('_post', vars=dict(postAuthor=postAuthor), order='id DESC',
            where='postAuthor = $postAuthor'), 0, {})
Пример #50
0
def get_compose(cmpsid):
    if not dbsl: return
    retval = web.listget(
        dbsl.select("DM_COMPOSE", vars=locals(),
                    where="CMPSID=$cmpsid").list(), 0)
    return retval
Пример #51
0
def get_session(session_id):
    res = dbconn.query("select * from sessions where session_id = $session_id",
                       vars=dict(session_id=session_id))
    return web.listget(res, 0, None)
Пример #52
0
def getPostByPostId(PostId):
    return web.listget(
        db.select('_post', vars=dict(id=PostId), where='id = $id'), 0, {})
Пример #53
0
def getsp(spid):
    return web.listget(dbconn.query("select * from formalitem where id=$spid",vars=dict(spid=spid)),0,None)
Пример #54
0
def getdp(dpid):
    return web.listget(dbconn.query("select * from danping where id = $dpid",vars=dict(dpid=dpid)),0,None)
Пример #55
0
def getRecentOnePostsInNode(nodeId):
    return web.listget(
    db.select('_post', limit=1,  order='id DESC', vars=dict(nodeId=nodeId), where='nodeId = $nodeId'), 0, {})
Пример #56
0
def getLastTimeStamp(userid):
    r = web.listget( dbconn.query("select max(timeStamp) as timeStamp from user_data where userid=$userid",vars=dict(userid=userid)), 0, None)
    if r:
        return date_to_timestamp(r.timeStamp)
    return None
Пример #57
0
 def GET(self):
     data = web.input()
     naifenid = int(data["id"])
     nf = web.listget(dbconn.query("select * from formalnaifen where id = $naifenid",vars=dict(naifenid=naifenid)),0,None)
     return render.editnaifen(nf=nf)