-# -*- coding: utf-8 -*-
#############################################################################
# from http://djangosnippets.org/snippets/243/
# NOTE: We are only support basic authentication for now.
#
if auth[0].lower() == "basic":
- uname, passwd = base64.b64decode(auth[1]).split(':')
+ uname, passwd = base64.b64decode(auth[1].encode('utf-8')).decode('utf-8').split(':')
user = authenticate(username=uname, password=passwd)
if user is not None:
if user.is_active:
-# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
objects = Collection.objects.all()
if len(objects) > 3:
- best = random.sample(objects, 3)
+ best = random.sample(list(objects), 3)
else:
best = objects
identifier = self.slug_to_identifier(book.slug)
if isinstance(book, Book):
# setSpec = map(self.tag_to_setspec, book.tags.filter(category__in=self.TAG_CATEGORIES))
- header = common.Header(identifier, make_time_naive(book.changed_at), [], False)
+ header = common.Header(None, identifier, make_time_naive(book.changed_at), [], False)
if not headers_only:
meta = common.Metadata(self.metadata(book))
about = None
elif isinstance(book, Deleted):
- header = common.Header(identifier, make_time_naive(book.deleted_at), [], True)
+ header = common.Header(None, identifier, make_time_naive(book.deleted_at), [], True)
if not headers_only:
meta = common.Metadata({})
about = None
-# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
makedirs(os.path.dirname(output_path))
rendered = render_to_string(template, context)
- with open(output_path, 'w') as csv_file:
+ with open(output_path, 'wb') as csv_file:
csv_file.write(rendered.encode('utf-8'))
response = HttpResponse(content_type=mime_type)
response['Content-Disposition'] = 'attachment; filename=%s' % name
- with open(file_path) as f:
+ with open(file_path, 'rb') as f:
for chunk in read_chunks(f):
response.write(chunk)
return response
def get_book(self):
if self._book is not None:
return self._book
- self._book = catalogue.models.Book.objects.get(id=self.book_id)
+ try:
+ self._book = catalogue.models.Book.objects.get(id=self.book_id)
+ except catalogue.models.Book.DoesNotExist:
+ self._book = None
return self._book
book = property(get_book)
books[r.book_id] = r
return books.values()
+ def get_sort_key(self):
+ return (-self.score,
+ self.published_date,
+ self.book.sort_key_author if self.book else '',
+ self.book.sort_key if self.book else '')
+
def __lt__(self, other):
- return (-self.score, self.published_date, self.book.sort_key_author, self.book.sort_key) > \
- (-other.score, other.published_date, other.book.sort_key_author, other.book.sort_key)
+ return self.get_sort_key() > other.get_sort_key()
def __eq__(self, other):
- return (self.score, self.published_date, self.book.sort_key_author, self.book.sort_key) == \
- (other.score, other.published_date, other.book.sort_key_author, other.book.sort_key)
+ return self.get_sort_key() == other.get_sort_key()
def __len__(self):
return len(self.hits)