Implement sub-sorting. So if you want to sort by author and then sub sort by series, you can now click first on series and then on author to acheive this. Implement #1810 (Advanced Sorting?)

This commit is contained in:
Kovid Goyal 2009-03-04 09:46:47 -08:00
parent 7e849659cd
commit f967c00b9f
2 changed files with 9 additions and 9 deletions

View File

@ -275,8 +275,9 @@ class ResultCache(SearchQueryParser):
cmp(self._data[x][loc], self._data[y][loc]) cmp(self._data[x][loc], self._data[y][loc])
except AttributeError: # Some entries may be None except AttributeError: # Some entries may be None
ans = cmp(self._data[x][loc], self._data[y][loc]) ans = cmp(self._data[x][loc], self._data[y][loc])
if ans != 0: return ans #if ans != 0: return ans
return cmp(self._data[x][11].lower(), self._data[y][11].lower()) #return cmp(self._data[x][11].lower(), self._data[y][11].lower())
return ans
def sort(self, field, ascending): def sort(self, field, ascending):
field = field.lower().strip() field = field.lower().strip()

View File

@ -68,10 +68,9 @@ class Newsweek(BasicNewsRecipe):
def parse_index(self): def parse_index(self):
ci = self.get_current_issue() soup = self.get_current_issue()
if not ci: if not soup:
raise RuntimeError('Unable to connect to newsweek.com. Try again later.') raise RuntimeError('Unable to connect to newsweek.com. Try again later.')
soup = self.index_to_soup(ci)
img = soup.find(alt='Cover') img = soup.find(alt='Cover')
if img is not None and img.has_key('src'): if img is not None and img.has_key('src'):
small = img['src'] small = img['src']
@ -119,10 +118,10 @@ class Newsweek(BasicNewsRecipe):
return soup return soup
def get_current_issue(self): def get_current_issue(self):
from urllib2 import urlopen # For some reason mechanize fails #from urllib2 import urlopen # For some reason mechanize fails
home = urlopen('http://www.newsweek.com').read() #home = urlopen('http://www.newsweek.com').read()
soup = BeautifulSoup(home) soup = self.index_to_soup('http://www.newsweek.com')#BeautifulSoup(home)
img = soup.find('img', alt='Current Magazine') img = soup.find('img', alt='Current Magazine')
if img and img.parent.has_key('href'): if img and img.parent.has_key('href'):
return urlopen(img.parent['href']).read() return self.index_to_soup(img.parent['href'])