Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: internetarchive/openlibrary
base: f07d061754
...
head fork: internetarchive/openlibrary
compare: 95cd990dd3
Checking mergeability… Don't worry, you can still create the pull request.
  • 12 commits
  • 6 files changed
  • 0 commit comments
  • 3 contributors
Commits on Sep 15, 2011
@EdwardBetts EdwardBetts speed up search inside d41c11c
@EdwardBetts EdwardBetts Merge branch 'master' of github.com:internetarchive/openlibrary 62c31a5
@EdwardBetts EdwardBetts less results per page 6f531ac
@EdwardBetts EdwardBetts fix indents ade69f6
@EdwardBetts EdwardBetts fix get_many typo 177201b
@EdwardBetts EdwardBetts missed some references to editions 4b6cff7
Commits on Sep 20, 2011
@anandology anandology sync infogami.
Changes:
* Added optional `raw` argument to `get_many` to return raw data instead of objects.
23f4d96
@anandology anandology Added /works/OL123W/editions.json API 377e097
Commits on Sep 22, 2011
@anandology anandology typo d176654
Commits on Sep 23, 2011
@anandology anandology Added type.key hidden field to /type/page edit template.
Required when undoing a delete.
c70474d
@anandology anandology Sync infogami.
Changes:
* When doing diff ignore white-space changes and treat empty dictionaries as nothing
* Added __hash__ to Thing class
6576493
Open Library Merge remote branch 'origin/master' into dev 95cd990
View
20 openlibrary/plugins/inside/code.py
@@ -105,12 +105,30 @@ def get_results(q, offset=0, limit=100, snippets=3, fragsize=200, hl_phrase=Fals
stats.begin("solr", url=solr_select)
json_data = urllib.urlopen(solr_select).read()
stats.end()
+
try:
- return simplejson.loads(json_data)
+ results = simplejson.loads(json_data)
except:
m = re_query_parser_error.search(json_data)
return { 'error': web.htmlunquote(m.group(1)) }
+ ekey_doc = {}
+ for doc in results['response']['docs']:
+ ia = doc['ia']
+ q = {'type': '/type/edition', 'ocaid': ia}
+ ekeys = web.ctx.site.things(q)
+ if not ekeys:
+ del q['ocaid']
+ q['source_records'] = 'ia:' + ia
+ ekeys = web.ctx.site.things(q)
+ if ekeys:
+ ekey_doc[ekeys[0]] = doc
+
+ editions = web.ctx.site.get_many(ekey_doc.keys())
+ for e in editions:
+ ekey_doc[e['key']]['edition'] = e
+ return results
+
return render_template('search/inside.tmpl', get_results, quote_snippet, editions_from_ia, read_from_archive)
def ia_lookup(path):
View
51 openlibrary/plugins/openlibrary/api.py
@@ -0,0 +1,51 @@
+"""API stuff."""
+import web
+import simplejson
+
+from infogami.utils import delegate
+from openlibrary.core import helpers as h
+
+def setup():
+ # placeholder
+ pass
+
+class work_editions(delegate.page):
+ path = "(/works/OL\d+W)/editions"
+ encoding = "json"
+
+ def GET(self, key):
+ doc = web.ctx.site.get(key)
+ if not doc or doc.type.key != "/type/work":
+ raise web.notfound('')
+ else:
+ i = web.input(limit=50, offset=0)
+ limit = h.safeint(i.limit) or 50
+ offset = h.safeint(i.offset) or 0
+
+ data = self.get_editions_data(doc, limit=limit, offset=offset)
+ return delegate.RawText(simplejson.dumps(data), content_type="applicaiton/json")
+
+ def get_editions_data(self, work, limit, offset):
+ if limit > 1000:
+ limit = 1000
+
+ keys = web.ctx.site.things({"type": "/type/edition", "works": work.key, "limit": limit, "offset": offset})
+ editions = web.ctx.site.get_many(keys, raw=True)
+
+ size = work.edition_count
+ links = {
+ "self": web.ctx.fullpath,
+ "work": work.key,
+ }
+
+ if offset > 0:
+ links['prev'] = web.changequery(offset=min(0, offset-limit))
+
+ if offset + len(editions) < size:
+ links['next'] = web.changequery(offset=offset+limit)
+
+ return {
+ "links": links,
+ "size": size,
+ "entries": editions
+ }
View
3  openlibrary/plugins/openlibrary/code.py
@@ -779,6 +779,9 @@ def setup():
events.setup()
status.setup()
+ import api
+ api.setup()
+
from stats import stats_hook
delegate.app.add_processor(web.unloadhook(stats_hook))
View
2  openlibrary/plugins/openlibrary/templates/type/page/edit.html
@@ -11,6 +11,8 @@
<form name="edit" method="post" action="" class="olform">
<div class="formElement title">
+ <input type="hidden" name="type.key" value="$page.type.key" />
+
<div class="label"><label for="title">$_("Title"):</label></div>
<div class="input">
<input type="text" name="title" value="$page.title" />
View
13 openlibrary/plugins/worksearch/templates/search/inside.html
@@ -53,11 +53,10 @@
<li>
$ authors = []
$ cover = '/images/icons/avatar_book-sm.png'
- $ editions = editions_from_ia(ia)
+ $ e = doc.get('edition')
$ item = read_from_archive(ia)
$ collection = set(item.get('collection', []))
- $if editions:
- $ e = get_document(editions[0])
+ $if e:
$ key = e.key
$ url = key
$ title = e.title
@@ -80,16 +79,16 @@
<span class="resultTitle">
<h3 class="booktitle sansserif"><a href="$url" class="results">$title</a></h3>
<span class="bookauthor">by
- $if editions and authors:
+ $if e and authors:
$for a in authors:
<a href="$a.key" class="results">$a.name</a>$('' if loop.last else ', ')
- $elif not editions and authors:
+ $elif not e and authors:
$', '.join(authors)
$else:
<em>unknown author</em>
</span>
<span class="resultPublisher">
- $if editions:
+ $if e:
Published
$if e.publish_date:
in $e.publish_date
@@ -119,4 +118,4 @@ <h3 class="booktitle sansserif"><a href="$url" class="results">$title</a></h3>
</ul>
$:macros.Pager(page, num_found, results_per_page)
</div>
-</div>
+</div>
2  vendor/infogami
@@ -1 +1 @@
-Subproject commit a04f1508bef53ce06074aeef480e5d90b6c5bc36
+Subproject commit 7f3a8fdb3a9ee50f596d2430503c9a40c422f53d

No commit comments for this range

Something went wrong with that request. Please try again.