From: Radek Czajka Date: Mon, 18 Mar 2019 09:46:23 +0000 (+0100) Subject: Minor fixes. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/0b83514c0335addda3b76710aec04df93f85479d?ds=inline Minor fixes. --- diff --git a/src/basicauth.py b/src/basicauth.py index 3635727c4..dc7aceb16 100644 --- a/src/basicauth.py +++ b/src/basicauth.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################# # from http://djangosnippets.org/snippets/243/ @@ -29,7 +28,7 @@ def view_or_basicauth(view, request, test_func, realm="", *args, **kwargs): # 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: diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 5beb6dc01..2c9f5dd11 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -1,4 +1,3 @@ -# -*- 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. # @@ -512,7 +511,7 @@ def collections(request): objects = Collection.objects.all() if len(objects) > 3: - best = random.sample(objects, 3) + best = random.sample(list(objects), 3) else: best = objects diff --git a/src/oai/handlers.py b/src/oai/handlers.py index 779406d70..b2f255990 100644 --- a/src/oai/handlers.py +++ b/src/oai/handlers.py @@ -98,12 +98,12 @@ class Catalogue(common.ResumptionOAIPMH): 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 diff --git a/src/reporting/utils.py b/src/reporting/utils.py index 955f7d92d..ef4b1d0b2 100755 --- a/src/reporting/utils.py +++ b/src/reporting/utils.py @@ -1,4 +1,3 @@ -# -*- 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. # @@ -72,7 +71,7 @@ def render_to_csv(output_path, template, context=None, add_files=None): 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')) @@ -111,7 +110,7 @@ def generated_file_view(file_name, mime_type, send_name=None, signals=None): 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 diff --git a/src/search/index.py b/src/search/index.py index 712089396..9f87b9974 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -634,7 +634,10 @@ class SearchResult(object): 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) @@ -746,13 +749,17 @@ class SearchResult(object): 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)