Top level feed done

This commit is contained in:
Kovid Goyal 2010-10-10 23:00:46 -06:00
parent 1737226363
commit 2457241f11
5 changed files with 64 additions and 5 deletions

View File

@ -183,3 +183,28 @@ h2.library_name {
/* }}} */
/* Top level {{{ */
.toplevel ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.toplevel li {
margin: 0.75em;
padding: 0.75em;
text-align: center;
cursor: pointer;
}
.toplevel li:hover {
background-color: #d6d3c9;
font-weight: bold;
}
.toplevel li span { display: none }
/* }}} */

View File

@ -81,7 +81,7 @@
<div>&nbsp;</div>
<div id="main">
xxx
{main}
</div>
<div id="footer">
[{library_path}] Created by Kovid Goyal

View File

@ -119,5 +119,12 @@ function init() {
// Top-level feed {{{
function toplevel() {
$(".sort_select").hide();
$(".toplevel li").corner("15px");
$(".toplevel li").click(function() {
var href = $(this).children("span").html();
window.location = href;
});
}
// }}}

View File

@ -63,13 +63,37 @@ class BrowseServer(object):
# Catalogs {{{
def browse_catalog(self, category=None):
if category == None:
#categories = self.categories_cache()
categories = self.categories_cache()
category_meta = self.db.field_metadata
cats = [
(_('Newest'), 'newest'),
]
def getter(x):
return category_meta[x]['name'].lower()
for category in sorted(categories,
cmp=lambda x,y: cmp(getter(x), getter(y))):
if len(categories[category]) == 0:
continue
if category == 'formats':
continue
meta = category_meta.get(category, None)
if meta is None:
continue
cats.append((meta['name'], category))
cats = ['<li title="{2} {0}">{0}<span>/browse/category/{1}</span></li>'.format(xml(x, True),
xml(y), xml(_('Browse books by'))) for x, y in cats]
main = '<div class="toplevel"><h3>{0}</h3><ul>{1}</ul></div>'\
.format(_('Choose a category to browse by:'), '\n\n'.join(cats))
ans = self.browse_template().format(title='',
script='toplevel();')
script='toplevel();', main=main)
else:
raise cherrypy.HTTPError(404, 'Not found')
cherrypy.response.headers['Content-Type'] = 'text/html'
cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time)
updated = self.db.last_modified()
cherrypy.response.headers['Last-Modified'] = \
self.last_modified(max(updated, self.build_time))
return ans
# }}}

View File

@ -30,7 +30,10 @@ class Cache(object):
def categories_cache(self, restrict_to=frozenset([])):
base_restriction = self.search_cache('')
restrict_to = frozenset(restrict_to).intersection(base_restriction)
if restrict_to:
restrict_to = frozenset(restrict_to).intersection(base_restriction)
else:
restrict_to = base_restriction
old = self._category_cache.pop(frozenset(restrict_to), None)
if old is None or old[0] <= self.db.last_modified():
categories = self.db.get_categories(ids=restrict_to)