コード例 #1
0
ファイル: borrow.py プロジェクト: dmontalvo/openlibrary
def can_borrow(edition):
    global lending_library_subject, in_library_subject
    
    # Check if in overdrive
    # $$$ Should we also require to be in lending library?
    if overdrive_id(edition):
        return True
    
    # Check that work is in the general lending library, or available for
    # in-library loan and the user is in a library
    lendable = False
    for work in edition.get('works', []):
        subjects = work.get_subjects()
        
        if subjects:
            if lending_library_subject in subjects:
                # General lending library
                lendable = True
                break
            if in_library_subject in subjects:
                # Books is eligible for in-library loan
                if 'inlibrary' in web.ctx.features and inlibrary.get_library() is not None:
                    # Person is in a library
                    lendable = True
                    break
                        
    if not lendable:
        return False
    
    # Check if hosted at archive.org - sanity check
    if edition.get('ocaid', False):
        return True
    
    return False
コード例 #2
0
def can_borrow(edition):
    global lending_library_subject, in_library_subject

    # Check if in overdrive
    # $$$ Should we also require to be in lending library?
    if overdrive_id(edition):
        return True

    # Check that work is in the general lending library, or available for
    # in-library loan and the user is in a library
    lendable = False
    for work in edition.get('works', []):
        subjects = work.get_subjects()

        if subjects:
            if lending_library_subject in subjects:
                # General lending library
                lendable = True
                break
            if in_library_subject in subjects:
                # Books is eligible for in-library loan
                if 'inlibrary' in web.ctx.features and inlibrary.get_library(
                ) is not None:
                    # Person is in a library
                    lendable = True
                    break

    if not lendable:
        return False

    # Check if hosted at archive.org - sanity check
    if edition.get('ocaid', False):
        return True

    return False
コード例 #3
0
ファイル: borrow_home.py プロジェクト: lukasklein/openlibrary
    def GET(self):
        i = web.input(offset=0, limit=12, rand=-1, details="false", has_fulltext="false")

        filters = {}
        if i.get("has_fulltext") == "true":
            filters["has_fulltext"] = "true"

        if i.get("published_in"):
            if "-" in i.published_in:
                begin, end = i.published_in.split("-", 1)

                if h.safeint(begin, None) is not None and h.safeint(end, None) is not None:
                    filters["publish_year"] = [begin, end]
            else:
                y = h.safeint(i.published_in, None)
                if y is not None:
                    filters["publish_year"] = i.published_in

        i.limit = h.safeint(i.limit, 12)
        i.offset = h.safeint(i.offset, 0)

        i.rand = h.safeint(i.rand, -1)

        if i.rand > 0:
            sort = 'random_%d desc' % i.rand
            filters['sort'] = sort

        subject = get_lending_library(web.ctx.site,
            offset=i.offset,
            limit=i.limit,
            details=i.details.lower() == "true",
            inlibrary=inlibrary.get_library() is not None,
            **filters)
        return simplejson.dumps(subject)
コード例 #4
0
 def GET(self):
     subject = get_lending_library(web.ctx.site,
                                   details=True,
                                   inlibrary=inlibrary.get_library()
                                   is not None,
                                   limit=24)
     return render_template("borrow/index", subject, stats=LoanStats())
コード例 #5
0
ファイル: borrow_home.py プロジェクト: yzou/openlibrary
    def GET(self):
        i = web.input(offset=0, limit=24, rand=-1, details="false", has_fulltext="false")

        filters = {}
        if i.get("has_fulltext") == "true":
            filters["has_fulltext"] = "true"

        if i.get("published_in"):
            if "-" in i.published_in:
                begin, end = i.published_in.split("-", 1)

                if h.safeint(begin, None) is not None and h.safeint(end, None) is not None:
                    filters["publish_year"] = [begin, end]
            else:
                y = h.safeint(i.published_in, None)
                if y is not None:
                    filters["publish_year"] = i.published_in

        i.limit = h.safeint(i.limit, 12)
        i.offset = h.safeint(i.offset, 0)

        i.rand = h.safeint(i.rand, -1)

        if i.rand > 0:
            sort = 'random_%d desc' % i.rand
            filters['sort'] = sort

        subject = get_lending_library(web.ctx.site, 
            offset=i.offset, 
            limit=i.limit, 
            details=i.details.lower() == "true", 
            inlibrary=inlibrary.get_library() is not None,
            **filters)
        return simplejson.dumps(subject)
コード例 #6
0
ファイル: home.py プロジェクト: harshadsavant/openlibrary
def render_returncart(limit=60, randomize=True):
    data = get_returncart(limit*5)

    # Remove all inlibrary books if we not in a participating library
    if not inlibrary.get_library():
        data = [d for d in data if 'inlibrary_borrow_url' not in d]
    
    if randomize:
        random.shuffle(data)
    data = data[:limit]
    return render_template("books/carousel", storify(data), id="returncart_carousel")
コード例 #7
0
ファイル: borrow_home.py プロジェクト: nibrahim/openlibrary
 def GET(self):
     rand = random.randint(0, 9999)
     sort = "random_%d desc" % rand
     subject = get_lending_library(web.ctx.site,
                                   details=True,
                                   inlibrary=inlibrary.get_library()
                                   is not None,
                                   limit=24,
                                   sort=sort)
     return render_template("borrow/index",
                            subject,
                            stats=LoanStats(),
                            rand=rand)
コード例 #8
0
ファイル: home.py プロジェクト: yzou/openlibrary
def render_returncart(limit=60, randomize=True):
    data = get_returncart(limit * 5)

    # Remove all inlibrary books if we not in a participating library
    if not inlibrary.get_library():
        data = [d for d in data if 'inlibrary_borrow_url' not in d]

    if randomize:
        random.shuffle(data)
    data = data[:limit]
    return render_template("books/carousel",
                           storify(data),
                           id="returncart_carousel")
コード例 #9
0
ファイル: libraries.py プロジェクト: iefbr14/openlibrary
def on_loan_created(loan):
    """Adds the loan info to the admin stats database.
    """
    logger.debug("on_loan_created")
    db = get_admin_couchdb()

    # The loan key is now changed from uuid to fixed key.
    # Using _key as key for loan stats will result in overwriting previous loans.
    # Using the unique uuid to create the loan key and falling back to _key
    # when uuid is not available.
    key = "loans/" + loan.get("uuid") or loan["_key"]

    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])

    d = {
        "_id": key,
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }

    library = inlibrary.get_library()
    d['library'] = library and library.key
    d['geoip_country'] = geo_ip.get_country(web.ctx.ip)

    if key in db:
        logger.warn(
            "loan document is already present in the stats database: %r", key)
    else:
        db[d['_id']] = d

    yyyy_mm = t_start.strftime("%Y-%m")

    logger.debug("incrementing loan count of %s", d['book'])

    # Increment book loan count
    # Loan count is maintained per month so that it is possible to find popular books per month, year and overall.
    book = db.get(d['book']) or {"_id": d['book']}
    book["loans"][yyyy_mm] = book.setdefault("loans", {}).setdefault(
        yyyy_mm, 0) + 1
    db[d['book']] = book

    # Increment user loan count
    user_key = loan['user']
    user = db.get(user_key) or {"_id": user_key}
    user["loans"][yyyy_mm] = user.setdefault("loans", {}).setdefault(
        yyyy_mm, 0) + 1
    db[user_key] = user
コード例 #10
0
ファイル: libraries.py プロジェクト: iefbr14/openlibrary
def on_loan_created_statsdb(loan):
    """Adds the loan info to the stats database.
    """
    key = _get_loan_key(loan)
    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])
    d = {
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }
    library = inlibrary.get_library()
    d['library'] = library and library.key
    d['geoip_country'] = geo_ip.get_country(web.ctx.ip)
    statsdb.add_entry(key, d)
コード例 #11
0
ファイル: libraries.py プロジェクト: ashumeow/openlibrary
def on_loan_created_statsdb(loan):
    """Adds the loan info to the stats database.
    """
    key = _get_loan_key(loan)
    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])
    d = {
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }
    library = inlibrary.get_library()
    d['library'] = library and library.key
    d['geoip_country'] = geo_ip.get_country(web.ctx.ip)
    statsdb.add_entry(key, d)
コード例 #12
0
def format_one_request(record, data, details):
    edition = web.ctx.site.get(record['key'])

    if not 'works' in record:
        return {}

    work = web.ctx.site.get(record['works'][0]['key'])  # xxx

    user_inlibrary = inlibrary.get_library()

    # XXX fix
    thised_item = get_readable_edition_item(edition, work, user_inlibrary,
                                            edition)
    eds = get_work_editions(work)
    eds = [ed for ed in eds if ed != edition['key']]

    eds = web.ctx.site.get_many(eds)

    othered_items = [
        get_readable_edition_item(ed, work, user_inlibrary, edition)
        for ed in eds
    ]
    othered_items = [item for item in othered_items if item]
    if thised_item:
        othered_items.insert(0, thised_item)
    items = othered_items

    isbns = edition.get('isbn_10', [])
    isbns.extend(edition.get('isbn_13', []))  # xxx ? how to handle.

    result = {
        'records': {
            edition['key']: {
                'isbns': isbns,
                'issns': [],
                'lccns': edition.get('lccn', []),
                'oclcs': edition.get('oclc_numbers', []),
                'publishDates': [edition['publish_date']],
                # XXX below openlibrary.org from conf
                'recordURL': 'http://openlibrary.org%s' % edition['key'],
                # 'marc-xml': ''
                'data': data,
                'details': details,
            }
        },
        'items': items
    }
    return result
コード例 #13
0
ファイル: libraries.py プロジェクト: ashumeow/openlibrary
def on_loan_created(loan):
    """Adds the loan info to the admin stats database.
    """
    logger.debug("on_loan_created")
    db = get_admin_couchdb()

    # The loan key is now changed from uuid to fixed key.
    # Using _key as key for loan stats will result in overwriting previous loans.
    # Using the unique uuid to create the loan key and falling back to _key
    # when uuid is not available.
    key = "loans/" + loan.get("uuid") or loan["_key"]

    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])

    d = {
        "_id": key,
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }

    library = inlibrary.get_library()
    d['library'] = library and library.key
    d['geoip_country'] = geo_ip.get_country(web.ctx.ip)

    if key in db:
        logger.warn("loan document is already present in the stats database: %r", key)
    else:
        db[d['_id']] = d

    yyyy_mm = t_start.strftime("%Y-%m")

    logger.debug("incrementing loan count of %s", d['book'])

    # Increment book loan count
    # Loan count is maintained per month so that it is possible to find popular books per month, year and overall.
    book = db.get(d['book']) or {"_id": d['book']}
    book["loans"][yyyy_mm] = book.setdefault("loans", {}).setdefault(yyyy_mm, 0) + 1
    db[d['book']] = book

    # Increment user loan count
    user_key = loan['user']
    user = db.get(user_key) or {"_id": user_key}
    user["loans"][yyyy_mm] = user.setdefault("loans", {}).setdefault(yyyy_mm, 0) + 1
    db[user_key] = user
コード例 #14
0
ファイル: readlinks.py プロジェクト: amoghravish/openlibrary
def format_one_request(record, data, details):
    edition = web.ctx.site.get(record['key'])

    if not 'works' in record:
        return {}

    work = web.ctx.site.get(record['works'][0]['key']) # xxx

    user_inlibrary = inlibrary.get_library()

    # XXX fix
    thised_item = get_readable_edition_item(edition, work,
                                            user_inlibrary, edition)
    eds = get_work_editions(work)
    eds = [ed for ed in eds if ed != edition['key']]

    eds = web.ctx.site.get_many(eds)

    othered_items = [get_readable_edition_item(ed, work,
                                               user_inlibrary, edition)
                     for ed in eds]
    othered_items = [item for item in othered_items if item]
    if thised_item:
        othered_items.insert(0, thised_item)
    items = othered_items

    isbns = edition.get('isbn_10', [])
    isbns.extend(edition.get('isbn_13', [])) # xxx ? how to handle.

    result = {'records':
                  { edition['key']:
                        { 'isbns': isbns,
                          'issns': [],
                          'lccns': edition.get('lccn', []),
                          'oclcs': edition.get('oclc_numbers', []),
                          'publishDates': [edition['publish_date']],
                          # XXX below openlibrary.org from conf
                          'recordURL': 'http://openlibrary.org%s' % edition['key'],
                          # 'marc-xml': ''
                          'data': data,
                          'details': details,
                          } },
              'items': items }
    return result
コード例 #15
0
def on_loan_created(loan):
    """Adds the loan info to the admin stats database.
    """
    logger.debug("on_loan_created")
    db = get_admin_couchdb()
    key = "loans/" + loan['_key']

    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])

    d = {
        "_id": key,
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }

    library = inlibrary.get_library()
    d['library'] = library and library.key

    if key in db:
        logger.warn(
            "loan document is already present in the stats database: %r", key)
    else:
        db[d['_id']] = d

    yyyy_mm = t_start.strftime("%Y-%m")

    logger.debug("incrementing loan count of %s", d['book'])

    # Increment book loan count
    # Loan count is maintained per month so that it is possible to find popular books per month, year and overall.
    book = db.get(d['book']) or {"_id": d['book']}
    book["loans"][yyyy_mm] = book.setdefault("loans", {}).setdefault(
        yyyy_mm, 0) + 1
    db[d['book']] = book

    # Increment user loan count
    user_key = loan['user']
    user = db.get(user_key) or {"_id": user_key}
    user["loans"][yyyy_mm] = user.setdefault("loans", {}).setdefault(
        yyyy_mm, 0) + 1
    db[user_key] = user
コード例 #16
0
ファイル: libraries.py プロジェクト: dmontalvo/openlibrary
def on_loan_created(loan):
    """Adds the loan info to the admin stats database.
    """
    logger.debug("on_loan_created")
    db = get_admin_couchdb()
    key = "loans/" + loan['_key']

    t_start = datetime.datetime.utcfromtimestamp(loan['loaned_at'])

    d = {
        "_id": key,
        "book": loan['book'],
        "resource_type": loan['resource_type'],
        "t_start": t_start.isoformat(),
        "status": "active"
    }
    
    library = inlibrary.get_library()
    d['library'] = library and library.key

    if key in db:
        logger.warn("loan document is already present in the stats database: %r", key)
    else:
        db[d['_id']] = d

    yyyy_mm = t_start.strftime("%Y-%m")

    logger.debug("incrementing loan count of %s", d['book'])

    # Increment book loan count
    # Loan count is maintained per month so that it is possible to find popular books per month, year and overall.
    book = db.get(d['book']) or {"_id": d['book']}
    book["loans"][yyyy_mm] = book.setdefault("loans", {}).setdefault(yyyy_mm, 0) + 1
    db[d['book']] = book

    # Increment user loan count
    user_key = loan['user']
    user = db.get(user_key) or {"_id": user_key}
    user["loans"][yyyy_mm] = user.setdefault("loans", {}).setdefault(yyyy_mm, 0) + 1
    db[user_key] = user
コード例 #17
0
ファイル: borrow_home.py プロジェクト: lukasklein/openlibrary
 def GET(self):
     rand = random.randint(0, 9999)
     sort = "random_%d desc" % rand
     is_inlibrary = inlibrary.get_library() is not None
     subject = get_lending_library(web.ctx.site, details=True, inlibrary=is_inlibrary, limit=12, sort=sort)
     return render_template("borrow/index", subject, stats=LoanStats(), rand=rand, inlibrary=is_inlibrary)
コード例 #18
0
ファイル: readlinks.py プロジェクト: traceypooh/openlibrary
 def get_inlibrary(self):
     if not self.set_inlibrary:
         self.set_inlibrary = True
         self.inlibrary = inlibrary.get_library()
     return self.inlibrary
コード例 #19
0
ファイル: borrow_home.py プロジェクト: strogo/openlibrary
 def GET(self):
     subject = get_lending_library(web.ctx.site, details=True, inlibrary=inlibrary.get_library() is not None)
     return render_template("borrow/index", subject)
コード例 #20
0
 def GET(self):
     subject = get_lending_library(web.ctx.site, details=True, inlibrary=inlibrary.get_library() is not None, limit=24)
     return render_template("borrow/index", subject, stats=LoanStats())