From 4e361d55331351f56077e5f9999ecb4ee7e93819 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 5 Aug 2019 16:07:15 +0200 Subject: [PATCH] Django 2.0 --- requirements/requirements.txt | 2 +- src/ajaxable/utils.py | 5 ++--- src/basicauth.py | 2 +- src/catalogue/api/fields.py | 2 +- src/dictionary/models.py | 3 +-- src/dictionary/tests.py | 2 +- src/lesmianator/views.py | 6 +++--- src/paypal/views.py | 3 +-- src/social/forms.py | 3 +-- src/social/templatetags/social_tags.py | 2 +- src/social/utils.py | 3 +-- src/social/views.py | 4 ++-- src/sortify.py | 5 ++--- src/sponsors/widgets.py | 3 +-- src/suggest/forms.py | 8 ++++---- src/wolnelektury/settings/celery.py | 2 +- src/wolnelektury/urls.py | 2 +- src/wolnelektury/utils.py | 2 +- src/wolnelektury/views.py | 4 ++-- 19 files changed, 28 insertions(+), 35 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index b8e46befa..2911a9a8f 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,7 +1,7 @@ -i https://py.mdrn.pl/simple/ # django -Django==1.11.22 +Django==2.0.13 fnpdjango==0.4 django-pipeline==1.6.13 jsmin diff --git a/src/ajaxable/utils.py b/src/ajaxable/utils.py index 8e34a9a57..164feac34 100755 --- a/src/ajaxable/utils.py +++ b/src/ajaxable/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. # @@ -92,7 +91,7 @@ class AjaxableFormView(object): return response # do I need to be logged in? - if self.POST_login and not request.user.is_authenticated(): + if self.POST_login and not request.user.is_authenticated: return require_login(request) form_kwargs['data'] = request.POST @@ -123,7 +122,7 @@ class AjaxableFormView(object): if request.is_ajax(): return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data)) else: - if self.POST_login and not request.user.is_authenticated() and not request.is_ajax(): + if self.POST_login and not request.user.is_authenticated and not request.is_ajax(): return require_login(request) form = self.form_class(*form_args, **form_kwargs) diff --git a/src/basicauth.py b/src/basicauth.py index dc7aceb16..1275390ed 100644 --- a/src/basicauth.py +++ b/src/basicauth.py @@ -79,7 +79,7 @@ def logged_in_or_basicauth(realm=""): def view_decorator(func): def wrapper(request, *args, **kwargs): return view_or_basicauth(func, request, - lambda u: u.is_authenticated(), + lambda u: u.is_authenticated, realm, *args, **kwargs) return wrapper return view_decorator diff --git a/src/catalogue/api/fields.py b/src/catalogue/api/fields.py index 371da38ad..80de4ab34 100644 --- a/src/catalogue/api/fields.py +++ b/src/catalogue/api/fields.py @@ -14,7 +14,7 @@ class BookLiked(serializers.ReadOnlyField): def to_representation(self, value): request = self.context['request'] if not hasattr(request, 'liked_books'): - if request.user.is_authenticated(): + if request.user.is_authenticated: request.liked_books = set(Book.tagged.with_any(request.user.tag_set.all()).values_list('id', flat=True)) else: request.liked_books = None diff --git a/src/dictionary/models.py b/src/dictionary/models.py index c2891e1c9..5c3d2b998 100644 --- a/src/dictionary/models.py +++ b/src/dictionary/models.py @@ -68,7 +68,6 @@ def build_notes(book): fn_type=fn_type, language=language ) - qualifier_objects = [] for qualifier in qualifiers: obj, created = Qualifier.objects.get_or_create( @@ -76,7 +75,7 @@ def build_notes(book): 'name': FN_QUALIFIERS.get(qualifier, '') }) qualifier_objects.append(obj) - note.qualifiers = qualifier_objects + note.qualifiers.set(qualifier_objects) note.notesource_set.create(book=book, anchor=anchor) Note.objects.filter(notesource=None).delete() diff --git a/src/dictionary/tests.py b/src/dictionary/tests.py index 57af9d759..6c48cee67 100755 --- a/src/dictionary/tests.py +++ b/src/dictionary/tests.py @@ -20,7 +20,7 @@ class DictionaryTests(WLTestCase): ) def test_book_with_footnote(self): - book_text = """ + book_text = b""" rose --- kind of a flower. rose --- kind of a flower. diff --git a/src/lesmianator/views.py b/src/lesmianator/views.py index 3e8cfa5ff..e179c1483 100644 --- a/src/lesmianator/views.py +++ b/src/lesmianator/views.py @@ -21,7 +21,7 @@ def main_page(request): @cache.never_cache def new_poem(request): - user = request.user if request.user.is_authenticated() else None + user = request.user if request.user.is_authenticated else None text = Poem.write() p = Poem(slug=get_random_hash(text), text=text, created_by=user) p.save() @@ -35,7 +35,7 @@ def new_poem(request): @cache.never_cache def poem_from_book(request, slug): book = get_object_or_404(Book, slug=slug) - user = request.user if request.user.is_authenticated() else None + user = request.user if request.user.is_authenticated else None text = Poem.write(Continuations.get(book)) p = Poem(slug=get_random_hash(text), text=text, created_by=user) p.created_from = json.dumps([book.id]) @@ -49,7 +49,7 @@ def poem_from_book(request, slug): @cache.never_cache def poem_from_set(request, shelf): - user = request.user if request.user.is_authenticated() else None + user = request.user if request.user.is_authenticated else None tag = get_object_or_404(Tag, category='set', slug=shelf) text = Poem.write(Continuations.get(tag)) p = Poem(slug=get_random_hash(text), text=text, created_by=user) diff --git a/src/paypal/views.py b/src/paypal/views.py index c541ba80b..01d3a5aab 100644 --- a/src/paypal/views.py +++ b/src/paypal/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. # @@ -17,7 +16,7 @@ from paypal.models import BillingAgreement, BillingPlan def paypal_form(request, app=False): if request.POST: - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden() form = PaypalSubscriptionForm(data=request.POST) if form.is_valid(): diff --git a/src/social/forms.py b/src/social/forms.py index b3be6ebda..5c0973c19 100644 --- a/src/social/forms.py +++ b/src/social/forms.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. # @@ -26,7 +25,7 @@ class ObjectSetsForm(forms.Form): self._obj = obj self._user = user data = kwargs.setdefault('data', {}) - if 'tags' not in data and user.is_authenticated(): + if 'tags' not in data and user.is_authenticated: data['tags'] = ', '.join( obj.tags.filter(category='set', user=user).exclude(name__in=(None, '')).values_list('name', flat=True)) super(ObjectSetsForm, self).__init__(*args, **kwargs) diff --git a/src/social/templatetags/social_tags.py b/src/social/templatetags/social_tags.py index 298782c52..596c36d30 100644 --- a/src/social/templatetags/social_tags.py +++ b/src/social/templatetags/social_tags.py @@ -27,7 +27,7 @@ def choose_cite(context, book_id=None, tag_ids=None): @register.simple_tag(takes_context=True) def book_shelf_tags(context, book_id): request = context['request'] - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return '' book = Book.objects.get(pk=book_id) lks = likes(request.user, book, request) diff --git a/src/social/utils.py b/src/social/utils.py index e713fcdbc..67bc867fa 100644 --- a/src/social/utils.py +++ b/src/social/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. # @@ -15,7 +14,7 @@ from social.models import Cite def likes(user, work, request=None): - if not user.is_authenticated(): + if not user.is_authenticated: return False if request is None: diff --git a/src/social/views.py b/src/social/views.py index 2d95cfece..b7c823373 100644 --- a/src/social/views.py +++ b/src/social/views.py @@ -19,7 +19,7 @@ from social import forms @require_POST def like_book(request, slug): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden('Login required.') book = get_object_or_404(Book, slug=slug) @@ -33,7 +33,7 @@ def like_book(request, slug): @require_POST def unlike_book(request, slug): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden('Login required.') book = get_object_or_404(Book, slug=slug) diff --git a/src/sortify.py b/src/sortify.py index 941f50f1f..58807bb01 100644 --- a/src/sortify.py +++ b/src/sortify.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import re from fnpdjango.utils.text import char_map @@ -6,7 +5,7 @@ from fnpdjango.utils.text import char_map # Specifies diacritics order. # Default order is zero, max is 9 char_order = { - u'ż': 1, u'Ż': 1, + 'ż': 1, 'Ż': 1, } @@ -41,4 +40,4 @@ def sortify(value): value = value.lower() value = re.sub(r'[^a-z0-9~]+', ' ', value) - return value.encode('ascii', 'ignore') + return value.encode('ascii', 'ignore').decode('ascii') diff --git a/src/sponsors/widgets.py b/src/sponsors/widgets.py index 06bc3041a..7d537996e 100644 --- a/src/sponsors/widgets.py +++ b/src/sponsors/widgets.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. # @@ -25,7 +24,7 @@ class SponsorPageWidget(forms.Textarea): output = [super(SponsorPageWidget, self).render(name, value, attrs)] sponsors = [(str(obj), obj.pk, obj.logo.url) for obj in models.Sponsor.objects.all().iterator()] sponsors_js = ', '.join('{name: "%s", id: %d, image: "%s"}' % sponsor for sponsor in sponsors) - output.append(u'\n' % (name, sponsors_js)) diff --git a/src/suggest/forms.py b/src/suggest/forms.py index 72fd31124..90d3b9896 100644 --- a/src/suggest/forms.py +++ b/src/suggest/forms.py @@ -30,7 +30,7 @@ adres e-mail zostanie wykorzystany także w celu przesyłania newslettera Wolnyc description = self.cleaned_data['description'] suggestion = Suggestion(contact=contact, description=description, ip=request.META['REMOTE_ADDR']) - if request.user.is_authenticated(): + if request.user.is_authenticated: suggestion.user = request.user suggestion.save() @@ -44,7 +44,7 @@ Kontakt: %(contact)s %(description)s''' % { 'site': Site.objects.get_current().domain, 'url': reverse('admin:suggest_suggestion_change', args=[suggestion.id]), - 'user': str(request.user) if request.user.is_authenticated() else '', + 'user': str(request.user) if request.user.is_authenticated else '', 'contact': contact, 'description': description, }, fail_silently=True) @@ -89,7 +89,7 @@ class PublishingSuggestForm(NewsletterForm): suggestion = PublishingSuggestion( contact=contact, books=books, audiobooks=audiobooks, ip=request.META['REMOTE_ADDR']) - if request.user.is_authenticated(): + if request.user.is_authenticated: suggestion.user = request.user suggestion.save() @@ -107,7 +107,7 @@ class PublishingSuggestForm(NewsletterForm): Audiobooki: %(audiobooks)s''' % { 'url': request.build_absolute_uri(reverse('admin:suggest_suggestion_change', args=[suggestion.id])), - 'user': str(request.user) if request.user.is_authenticated() else '', + 'user': str(request.user) if request.user.is_authenticated else '', 'contact': contact, 'books': books, 'audiobooks': audiobooks, diff --git a/src/wolnelektury/settings/celery.py b/src/wolnelektury/settings/celery.py index 1552bc0e0..0d9b7785a 100644 --- a/src/wolnelektury/settings/celery.py +++ b/src/wolnelektury/settings/celery.py @@ -3,7 +3,7 @@ # CELERY_BROKER_URL = 'redis://' -CELERY_EAGER_PROPAGATES_EXCEPTIONS = True +CELERY_TASK_EAGER_PROPAGATES = True CELERY_SEND_TASK_ERROR_EMAILS = True CELERY_ACCEPT_CONTENT = ['pickle'] CELERY_TASK_SERIALIZER = 'pickle' diff --git a/src/wolnelektury/urls.py b/src/wolnelektury/urls.py index 6af8093c7..d765e7dab 100644 --- a/src/wolnelektury/urls.py +++ b/src/wolnelektury/urls.py @@ -60,7 +60,7 @@ urlpatterns += [ url(r'^admin/catalogue/book/import$', catalogue.views.import_book, name='import_book'), url(r'^admin/catalogue/picture/import$', picture.views.import_picture, name='import_picture'), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', admin.site.urls), # API url(r'^api/', include('api.urls')), diff --git a/src/wolnelektury/utils.py b/src/wolnelektury/utils.py index 44973bb26..c9b1a18f7 100644 --- a/src/wolnelektury/utils.py +++ b/src/wolnelektury/utils.py @@ -94,7 +94,7 @@ def ajax(login_required=False, method=None, template=None, permission_required=N if fun_kwargs or key in fun_params) kwargs.update(stringify_keys(request_params)) res = None - if login_required and not request.user.is_authenticated(): + if login_required and not request.user.is_authenticated: res = {'result': 'logout'} if (permission_required and not request.user.has_perm(permission_required)): diff --git a/src/wolnelektury/views.py b/src/wolnelektury/views.py index e77045527..2736acc5c 100644 --- a/src/wolnelektury/views.py +++ b/src/wolnelektury/views.py @@ -66,7 +66,7 @@ class LoginFormView(AjaxableFormView): ajax_redirect = True def __call__(self, request): - if request.user.is_authenticated(): + if request.user.is_authenticated: return self.redirect_or_refresh( request, '/', message=_('Already logged in as user %(user)s', ) % {'user': request.user.username}) @@ -87,7 +87,7 @@ class RegisterFormView(AjaxableFormView): honeypot = True def __call__(self, request): - if request.user.is_authenticated(): + if request.user.is_authenticated: return self.redirect_or_refresh( request, '/', message=_('Already logged in as user %(user)s', ) % {'user': request.user.username}) -- 2.20.1