return self.refresh_theme_counter()
return dict((int(k), v) for k, v in self.get__theme_counter_value().iteritems())
+ def pretty_title(self, html_links=False):
+ book = self
+ names = list(book.tags.filter(category='author'))
+
+ books = []
+ while book:
+ books.append(book)
+ book = book.parent
+ names.extend(reversed(books))
+
+ if html_links:
+ names = ['<a href="%s">%s</a>' % (tag.get_absolute_url(), tag.name) for tag in names]
+ else:
+ names = [tag.name for tag in names]
+
+ return ', '.join(names)
+
+
class Fragment(models.Model):
text = models.TextField()
short_text = models.TextField(editable=False)
return capfirst(', '.join(title))
-def book_stub_title(book):
- return ', '.join((book.author, book.title))
-
-
@register.simple_tag
def book_title(book, html_links=False):
- try:
- names = list(book.tags.filter(category='author'))
- except AttributeError:
- return book_stub_title(book)
-
- books = []
- while book:
- books.append(book)
- book = book.parent
- names.extend(reversed(books))
-
- if html_links:
- names = ['<a href="%s">%s</a>' % (tag.get_absolute_url(), tag.name) for tag in names]
- else:
- names = [tag.name for tag in names]
-
- return ', '.join(names)
+ return book.pretty_title(html_links)
@register.simple_tag
raise ValueError("query must have at least two characters")
result = tuple(_tags_starting_with(query, user))
+ # remove pdcounter stuff
+ book_titles = set(match.pretty_title().lower() for match in result
+ if isinstance(match, models.Book))
+ authors = set(match.name.lower() for match in result
+ if isinstance(match, models.Tag) and match.category=='author')
+ result = (res for res in result if not (
+ (isinstance(res, pdcounter_models.BookStub) and res.pretty_title().lower() in book_titles)
+ or (isinstance(res, pdcounter_models.Author) and res.name.lower() in authors)
+ ))
+
exact_matches = tuple(res for res in result if res.name.lower() == query)
if exact_matches:
return exact_matches
else:
- return result[:1]
+ return tuple(result)[:1]
def search(request):
def name(self):
return self.title
+ def pretty_title(self, html_links=False):
+ return ', '.join((self.author, self.title))