Django 2.0
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 5 Aug 2019 14:07:15 +0000 (16:07 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 5 Aug 2019 14:07:15 +0000 (16:07 +0200)
19 files changed:
requirements/requirements.txt
src/ajaxable/utils.py
src/basicauth.py
src/catalogue/api/fields.py
src/dictionary/models.py
src/dictionary/tests.py
src/lesmianator/views.py
src/paypal/views.py
src/social/forms.py
src/social/templatetags/social_tags.py
src/social/utils.py
src/social/views.py
src/sortify.py
src/sponsors/widgets.py
src/suggest/forms.py
src/wolnelektury/settings/celery.py
src/wolnelektury/urls.py
src/wolnelektury/utils.py
src/wolnelektury/views.py

index b8e46be..2911a9a 100644 (file)
@@ -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
index 8e34a9a..164feac 100755 (executable)
@@ -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)
index dc7aceb..1275390 100644 (file)
@@ -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
index 371da38..80de4ab 100644 (file)
@@ -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
index c2891e1..5c3d2b9 100644 (file)
@@ -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()
index 57af9d7..6c48cee 100755 (executable)
@@ -20,7 +20,7 @@ class DictionaryTests(WLTestCase):
         )
 
     def test_book_with_footnote(self):
-        book_text = """<utwor>
+        book_text = b"""<utwor>
         <opowiadanie>
             <akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
             <akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
index 3e8cfa5..e179c14 100644 (file)
@@ -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)
index c541ba8..01d3a5a 100644 (file)
@@ -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():
index b3be6eb..5c0973c 100644 (file)
@@ -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)
index 298782c..596c36d 100644 (file)
@@ -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)
index e713fcd..67bc867 100644 (file)
@@ -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:
index 2d95cfe..b7c8233 100644 (file)
@@ -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)
 
index 941f50f..58807bb 100644 (file)
@@ -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')
index 06bc304..7d53799 100644 (file)
@@ -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'<script type="text/javascript">addEvent(window, "load", function(e) {')
+        output.append('<script type="text/javascript">$(function(e) {')
         # TODO: "id_" is hard-coded here. This should instead use the correct
         # API to determine the ID dynamically.
         output.append(u'$("#id_%s").sponsorsFooter({sponsors: [%s]}); });</script>\n' % (name, sponsors_js))
index 72fd311..90d3b98 100644 (file)
@@ -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,
index 1552bc0..0d9b778 100644 (file)
@@ -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'
index 6af8093..d765e7d 100644 (file)
@@ -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')),
index 44973bb..c9b1a18 100644 (file)
@@ -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)):
index e770455..2736acc 100644 (file)
@@ -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})