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


Python web.storage函数代码示例

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


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

示例1: work_wrapper

def work_wrapper(w):
    d = web.storage(
        key="/works/" + w["key"],
        title=w["title"],
        edition_count=w["edition_count"]
    )

    if "cover_id" in w:
        d.cover_id = w["cover_id"]
    elif "cover_edition_key" in w:
        book = web.ctx.site.get("/books/" + w["cover_edition_key"])
        cover = book and book.get_cover()
        d.cover_id = cover and cover.id or None
        d.cover_edition_key = w['cover_edition_key']
    else:
        d.cover_id = None

    # special care to handle missing author_key/author_name in the solr record
    w.setdefault('author_key', [])
    w.setdefault('author_name', [])
    
    d.authors = [web.storage(key='/authors/' + k, name=n)
                 for k, n in zip(w['author_key'], w['author_name'])]

    d.first_publish_year = (w['first_publish_year'][0] if 'first_publish_year' in w else None)
    d.ia = w.get('ia', [])
    d.has_fulltext = w.get('has_fulltext', "false")
    return d
开发者ID:ziwar,项目名称:openlibrary,代码行数:28,代码来源:search.py

示例2: create_account_manager

    def create_account_manager(self):
        # Hack to use the accounts stuff from Infogami
        infobase_config.user_root = "/people"

        store = web.storage(store=self.store)
        site = web.storage(store=store, save_many=self.save_many)
        return account.AccountManager(site, config.infobase['secret_key'])
开发者ID:randomecho,项目名称:openlibrary,代码行数:7,代码来源:mock_infobase.py

示例3: get_voter_details_old

def get_voter_details_old(voterid):
    # ignore voterids like "yes" etc.
    if len(voterid) <= 4:
        return

    logger.info("get_voter_details %s", voterid)    
    try:
        b = web.Browser()
        b.open(URL)
        b.select_form(index=0)
        b['ctl00$ContentPlaceHolder1$ddlDistrict'] = ['21']
        b['ctl00$ContentPlaceHolder1$txtEpic'] = voterid
        b.submit()
    except Exception:
        logger.error("failed to request voterid details for %s", voterid, exc_info=True)
        return web.storage()

    soup = b.get_soup()
    table = soup.find("table", {"id": "ctl00_ContentPlaceHolder1_GridView1"})
    if not table:
        return None
    last_row = table.findAll("tr")[-1]
    data = [td.getText() for td in last_row.findAll(("td", "tr"))]
    # skip the first one, which is a button
    data = data[1:]
    cols = "ac_num ac_name part_no sl_no first_name last_name rel_firstname rel_lastname sex age".split()
    d = dict(zip(cols, data))
    d['voterid'] = voterid
    logger.info("voter info %s %s", voterid, d)   
    return web.storage(d)
开发者ID:anandology,项目名称:voternet,代码行数:30,代码来源:voterlib.py

示例4: work_object

def work_object(w): # called by works_by_author
    ia = w.get('ia', [])

    if config.get("single_core_solr"):
        key = w['key']
    else:
        key = '/works/' + w['key']

    obj = dict(
        authors = [web.storage(key='/authors/' + k, name=n) for k, n in zip(w['author_key'], w['author_name'])],
        edition_count = w['edition_count'],
        key = key,
        title = w['title'],
        public_scan = w.get('public_scan_b', bool(ia)),
        lending_edition = w.get('lending_edition_s', ''),
        lending_identifier = w.get('lending_identifier_s', ''),
        overdrive = (w['overdrive_s'].split(';') if 'overdrive_s' in w else []),
        collections = set(w['ia_collection_s'].split(';') if 'ia_collection_s' in w else []),
        url = key + '/' + urlsafe(w['title']),
        cover_edition_key = w.get('cover_edition_key'),
        first_publish_year = (w['first_publish_year'] if 'first_publish_year' in w else None),
        ia = w.get('ia', []),
        cover_i = w.get('cover_i')
    )

    if obj['lending_identifier']:
        doc = web.ctx.site.store.get("ebooks/" + obj['lending_identifier']) or {}
        obj['checked_out'] = doc.get("borrowed") == "true"
    else:
        obj['checked_out'] = False
    
    for f in 'has_fulltext', 'subtitle':
        if w.get(f):
            obj[f] = w[f]
    return web.storage(obj)
开发者ID:bfalling,项目名称:openlibrary,代码行数:35,代码来源:code.py

示例5: do_search

def do_search(param, sort, page=1, rows=100):
    (reply, solr_select, q_list) = run_solr_query(param, rows, page, sort)
    is_bad = False
    if reply.startswith('<html'):
        is_bad = True
    if not is_bad:
        try:
            root = XML(reply)
        except XMLSyntaxError:
            is_bad = True
    if is_bad:
        m = re_pre.search(reply)
        return web.storage(
            facet_counts = None,
            docs = [],
            is_advanced = bool(param.get('q', 'None')),
            num_found = None,
            solr_select = solr_select,
            q_list = q_list,
            error = (web.htmlunquote(m.group(1)) if m else reply),
        )

    docs = root.find('result')
    return web.storage(
        facet_counts = read_facets(root),
        docs = docs,
        is_advanced = bool(param.get('q', 'None')),
        num_found = (int(docs.attrib['numFound']) if docs is not None else None),
        solr_select = solr_select,
        q_list = q_list,
        error = None,
    )
开发者ID:sribanta,项目名称:openlibrary,代码行数:32,代码来源:code.py

示例6: f

        def f():
            web.ctx.disable_permission_check = True

            d = web.storage({"key": key, "type": {"key": "/type/user"}})
            d.update(data)
            self.site.save(key, d, timestamp=timestamp, author=d, comment="Created new account")

            q = make_query(d)
            account_bot = config.get('account_bot')
            account_bot = account_bot and web.storage({"key": account_bot, "type": {"key": "/type/user"}})
            self.site.save_many(q, ip=ip, timestamp=timestamp, author=account_bot, action='register', comment="Setup new account")
            self.site.store.register(key, email, enc_password)
            self.update_user_details(username, verified=True, active=True)

            # Add account doc to store
            olddoc = self.site.store.store.get("account/" + username) or {}
            
            doc = {
                "_key": "account/" + username,
                "_rev": olddoc.get("_rev"),
                "type": "account",
                "registered_on": olddoc['registered_on'],
                "activated_on": timestamp.isoformat(),
                "last_login": timestamp.isoformat(),
            }
            self.site.store.store.put("account/" + username, doc)
开发者ID:internetarchive,项目名称:infogami,代码行数:26,代码来源:account.py

示例7: _old_get_meta_xml

def _old_get_meta_xml(itemid):
    """Returns the contents of meta_xml as JSON.
    """
    itemid = web.safestr(itemid.strip())
    url = 'http://www.archive.org/download/%s/%s_meta.xml' % (itemid, itemid)
    try:
        stats.begin('archive.org', url=url)
        metaxml = urllib2.urlopen(url).read()
        stats.end()
    except IOError:
        logger.error("Failed to download _meta.xml for %s", itemid, exc_info=True)
        stats.end()
        return web.storage()

    # archive.org returns html on internal errors.
    # Checking for valid xml before trying to parse it.
    if not metaxml.strip().startswith("<?xml"):
        return web.storage()

    try:
        defaults = {"collection": [], "external-identifier": []}
        return web.storage(xml2dict(metaxml, **defaults))
    except Exception as e:
        logger.error("Failed to parse metaxml for %s", itemid, exc_info=True)
        return web.storage()
开发者ID:internetarchive,项目名称:openlibrary,代码行数:25,代码来源:ia.py

示例8: work_wrapper

def work_wrapper(w):
    d = web.storage(key="/works/" + w["key"], title=w["title"], edition_count=w["edition_count"])

    if "cover_id" in w:
        d.cover_id = w["cover_id"]
    elif "cover_edition_key" in w:
        book = web.ctx.site.get("/books/" + w["cover_edition_key"])
        cover = book and book.get_cover()
        d.cover_id = cover and cover.id or None
        d.cover_edition_key = w["cover_edition_key"]
    else:
        d.cover_id = None
    d.subject = w.get("subject", [])
    ia_collection = w["ia_collection_s"].split(";") if "ia_collection_s" in w else []
    d.ia_collection = ia_collection
    d.lendinglibrary = "lendinglibrary" in ia_collection
    d.printdisabled = "printdisabled" in ia_collection
    d.lending_edition = w.get("lending_edition_s", "")
    d.overdrive = w["overdrive_s"].split(";")[0] if "overdrive_s" in w else ""

    # special care to handle missing author_key/author_name in the solr record
    w.setdefault("author_key", [])
    w.setdefault("author_name", [])

    d.authors = [web.storage(key="/authors/" + k, name=n) for k, n in zip(w["author_key"], w["author_name"])]

    d.first_publish_year = w["first_publish_year"][0] if "first_publish_year" in w else None
    d.ia = w.get("ia", [])
    d.public_scan = w.get("public_scan_b", bool(d.ia))
    d.has_fulltext = w.get("has_fulltext", "false")
    return d
开发者ID:bowlofeggs,项目名称:openlibrary,代码行数:31,代码来源:search.py

示例9: GET

    def GET(self, page_path):
        try:
            page = get_page_by_path(page_path)
            if not page.is_published and not auth.get_user():
                raise flash.redirect(_(page_access_forbidden_text), "/login")
            load_page_data(page)

            if auth.has_role("admin"):
                json_data = web.storage(
                    page=page_to_json(page),
                    pages=pages_to_json(get_pages_in_tree_order()),
                )
            else:
                json_data = web.storage()

            if "edit" in web.input() and auth.has_role("admin"):
                json_data.update(
                    page_block=block_to_json(
                        get_page_block_by_page_id(page.id)),
                    template_blocks=template_blocks_to_json()
                )
            else:
                load_page_blocks(page.id)

            return render.pages.page(json_data)
        except IndexError:
            raise web.notfound()
开发者ID:w0rm,项目名称:pre-stonegarden-dev,代码行数:27,代码来源:pages.py

示例10: POST

 def POST(self, path):
     i = web.input(_method='post')
     i = web.storage(helpers.unflatten(i))
     i.key = path
     
     _ = web.storage((k, i.pop(k)) for k in i.keys() if k.startswith('_'))
     action = self.get_action(_)
     comment = _.get('_comment', None)
     
     for k, v in i.items():
         i[k] = self.trim(v)
         
     p = web.ctx.site.get(path) or web.ctx.site.new(path, {})
     p.update(i)
     
     if action == 'preview':
         p['comment_'] = comment
         return render.editpage(p, preview=True)
     elif action == 'save':
         try:
             p._save(comment)
             path = web.input(_method='GET', redirect=None).redirect or web.changequery(query={})
             raise web.seeother(path)
         except (ClientException, db.ValidationException), e:            
             add_flash_message('error', str(e))
             p['comment_'] = comment                
             return render.editpage(p)
开发者ID:EdwardBetts,项目名称:infogami,代码行数:27,代码来源:code.py

示例11: get_meta_xml

def get_meta_xml(itemid):
    """Returns the contents of meta_xml as JSON.
    """
    itemid = itemid.strip()
    
    url = 'http://www.archive.org/download/%s/%s_meta.xml' % (itemid, itemid)
    try:
        stats.begin("archive.org", url=url)
        metaxml = urllib2.urlopen(url).read()
        stats.end()
    except IOError:
        stats.end()
        return web.storage()
        
    # archive.org returns html on internal errors. 
    # Checking for valid xml before trying to parse it.
    if not metaxml.strip().startswith("<?xml"):
        return web.storage()
    
    try:
        defaults = {"collection": [], "external-identifier": []}
        return web.storage(xml2dict(metaxml, **defaults))
    except Exception, e:
        print >> web.debug, "Failed to parse metaxml for %s: %s" % (itemid, str(e)) 
        return web.storage()
开发者ID:amoghravish,项目名称:openlibrary,代码行数:25,代码来源:ia.py

示例12: __init__

 def __init__(self):
     init_dbcontext()
     web.cache=web.Storage()
     web.cache.sku_properid_datas=web.storage()
     web.cache.sku_properval_datas=web.storage()
     web.cache.cate_attr_datas=web.storage()
     self.access_token=''
     self.get_token_from_db()
开发者ID:aveenzhou,项目名称:smt_app,代码行数:8,代码来源:get_smt_products.py

示例13: load_extensions

def load_extensions():
    from common import db
    db.init(get_conn())
    web.extensions = web.storage()
    web.extensions.db = db
    web.extensions.ensure_login = ensure_login

    web.app_extensions = web.storage()
开发者ID:onlytiancai,项目名称:webappbox,代码行数:8,代码来源:extension.py

示例14: get_doc

def get_doc(doc): # called from work_search template
    e_ia = doc.find("arr[@name='ia']")
    first_pub = None
    e_first_pub = doc.find("int[@name='first_publish_year']")
    if e_first_pub is not None:
        first_pub = e_first_pub.text
    e_first_edition = doc.find("str[@name='first_edition']")
    first_edition = None
    if e_first_edition is not None:
        first_edition = e_first_edition.text

    work_subtitle = None
    e_subtitle = doc.find("str[@name='subtitle']")
    if e_subtitle is not None:
        work_subtitle = e_subtitle.text

    if doc.find("arr[@name='author_key']") is None:
        assert doc.find("arr[@name='author_name']") is None
        authors = []
    else:
        ak = [e.text for e in doc.find("arr[@name='author_key']")]
        an = [e.text for e in doc.find("arr[@name='author_name']")]
        authors = [web.storage(key=key, name=name, url="/authors/%s/%s" % (key, (urlsafe(name) if name is not None else 'noname'))) for key, name in zip(ak, an)]

    cover = doc.find("str[@name='cover_edition_key']")
    e_public_scan = doc.find("bool[@name='public_scan_b']")
    e_overdrive = doc.find("str[@name='overdrive_s']")
    e_lending_edition = doc.find("str[@name='lending_edition_s']")
    e_collection = doc.find("str[@name='ia_collection_s']")
    collections = set()
    if e_collection is not None:
        collections = set(e_collection.text.split(';'))

    doc = web.storage(
        key = doc.find("str[@name='key']").text,
        title = doc.find("str[@name='title']").text,
        edition_count = int(doc.find("int[@name='edition_count']").text),
        ia = [e.text for e in (e_ia if e_ia is not None else [])],
        has_fulltext = (doc.find("bool[@name='has_fulltext']").text == 'true'),
        public_scan = ((e_public_scan.text == 'true') if e_public_scan is not None else (e_ia is not None)),
        overdrive = (e_overdrive.text.split(';') if e_overdrive is not None else []),
        lending_edition = (e_lending_edition.text if e_lending_edition is not None else None),
        collections = collections,
        authors = authors,
        first_publish_year = first_pub,
        first_edition = first_edition,
        subtitle = work_subtitle,
        cover_edition_key = (cover.text if cover is not None else None),
    )

    doc.url = '/works/' + doc.key + '/' + urlsafe(doc.title)
    
    if not doc.public_scan and doc.lending_edition:
        store_doc = web.ctx.site.store.get("ebooks/books/" + doc.lending_edition) or {}
        doc.checked_out = store_doc.get("borrowed") == "true"
    else:
        doc.checked_out = "false"
    return doc
开发者ID:ashumeow,项目名称:openlibrary,代码行数:58,代码来源:code.py

示例15: get_property

 def get_property(self, type, name):
     if name == 'type':
         return web.storage(name='type', expected_type=web.storage(key='/type/type', kind="regular"), unique=True)
     elif name in ['permission', 'child_permission']:
         return web.storage(name=name, expected_type=web.storage(key='/type/permission', kind="regular"), unique=True)
     else:
         for p in type.get('properties', []):
             if p.get('name') == name:
                 return p
开发者ID:termim,项目名称:infogami,代码行数:9,代码来源:writequery.py


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