fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
5c14b2f
)
Django 4.
author
Radek Czajka
<rczajka@rczajka.pl>
Fri, 14 Oct 2022 13:37:22 +0000
(15:37 +0200)
committer
Radek Czajka
<rczajka@rczajka.pl>
Fri, 14 Oct 2022 13:37:22 +0000
(15:37 +0200)
13 files changed:
requirements/requirements.txt
patch
|
blob
|
history
src/ajaxable/templatetags/ajaxable_tags.py
patch
|
blob
|
history
src/ajaxable/utils.py
patch
|
blob
|
history
src/catalogue/views.py
patch
|
blob
|
history
src/club/models.py
patch
|
blob
|
history
src/club/payment_methods.py
patch
|
blob
|
history
src/paypal/rest.py
patch
|
blob
|
history
src/pdcounter/templatetags/time_tags.py
patch
|
blob
|
history
src/search/fields.py
patch
|
blob
|
history
src/social/views.py
patch
|
blob
|
history
src/waiter/views.py
patch
|
blob
|
history
src/wolnelektury/utils.py
patch
|
blob
|
history
src/wolnelektury/views.py
patch
|
blob
|
history
diff --git
a/requirements/requirements.txt
b/requirements/requirements.txt
index
b99f18e
..
2dec1cc
100644
(file)
--- a/
requirements/requirements.txt
+++ b/
requirements/requirements.txt
@@
-1,7
+1,7
@@
-i https://py.mdrn.pl/simple/
# django
-i https://py.mdrn.pl/simple/
# django
-Django==
3.2.16
+Django==
4.0.8
fnpdjango==0.6
docutils==0.16
fnpdjango==0.6
docutils==0.16
@@
-15,7
+15,7
@@
django-allauth==0.51
django-extensions==3.2.1
djangorestframework==3.13.1
djangorestframework-xml==2.0.0
django-extensions==3.2.1
djangorestframework==3.13.1
djangorestframework-xml==2.0.0
-django-admin-ordering==0.1
4.0
+django-admin-ordering==0.1
6
django-countries==7.3.2
# A version compatible with Django 2.2+, with long help text and editable max_length.
django-countries==7.3.2
# A version compatible with Django 2.2+, with long help text and editable max_length.
@@
-29,9
+29,7
@@
pyyaml==5.4.1
polib==1.1.1
polib==1.1.1
-pytz==2022.2.1
-
-django-honeypot==1.0.2
+django-honeypot==1.0.3
python-fb==0.2
python-fb==0.2
diff --git
a/src/ajaxable/templatetags/ajaxable_tags.py
b/src/ajaxable/templatetags/ajaxable_tags.py
index
2d980f2
..
a9a308d
100644
(file)
--- a/
src/ajaxable/templatetags/ajaxable_tags.py
+++ b/
src/ajaxable/templatetags/ajaxable_tags.py
@@
-2,7
+2,7
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import template
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import template
-from django.utils.encoding import force_
text
+from django.utils.encoding import force_
str
from django.utils.safestring import mark_safe
from ajaxable.utils import placeholdized
from django.utils.safestring import mark_safe
from ajaxable.utils import placeholdized
@@
-32,8
+32,8
@@
def pretty_field(field, template=None):
return mark_safe(template % {
'errors': field.errors,
'input': field,
return mark_safe(template % {
'errors': field.errors,
'input': field,
- 'label': ('*' if field.field.required else '') + force_
text
(field.label),
- 'helptext': force_
text
(field.help_text),
+ 'label': ('*' if field.field.required else '') + force_
str
(field.label),
+ 'helptext': force_
str
(field.help_text),
})
})
diff --git
a/src/ajaxable/utils.py
b/src/ajaxable/utils.py
index
23a350f
..
3a1c455
100644
(file)
--- a/
src/ajaxable/utils.py
+++ b/
src/ajaxable/utils.py
@@
-3,21
+3,22
@@
#
from functools import wraps
import json
#
from functools import wraps
import json
+from urllib.parse import quote_plus
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render
-from django.utils.encoding import force_
text
+from django.utils.encoding import force_
str
from django.utils.functional import Promise
from django.utils.functional import Promise
-from django.utils.http import urlquote_plus
from django.utils.translation import gettext_lazy as _
from django.views.decorators.vary import vary_on_headers
from honeypot.decorators import verify_honeypot_value
from django.utils.translation import gettext_lazy as _
from django.views.decorators.vary import vary_on_headers
from honeypot.decorators import verify_honeypot_value
+from wolnelektury.utils import is_ajax
class LazyEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Promise):
class LazyEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Promise):
- return force_
text
(o)
+ return force_
str
(o)
return o
return o
@@
-38,7
+39,7
@@
def method_decorator(function_decorator):
def require_login(request):
"""Return 403 if request is AJAX. Redirect to login page if not."""
def require_login(request):
"""Return 403 if request is AJAX. Redirect to login page if not."""
- if
request.is_ajax(
):
+ if
is_ajax(request
):
return HttpResponseForbidden('Not logged in')
return HttpResponseRedirect('/uzytkownicy/zaloguj') # next?=request.build_full_path())
return HttpResponseForbidden('Not logged in')
return HttpResponseRedirect('/uzytkownicy/zaloguj') # next?=request.build_full_path())
@@
-104,10
+105,10
@@
class AjaxableFormView:
}
if add_args:
response_data.update(add_args)
}
if add_args:
response_data.update(add_args)
- if not
request.is_ajax(
) and response_data['redirect']:
- return HttpResponseRedirect(
url
quote_plus(
+ if not
is_ajax(request
) and response_data['redirect']:
+ return HttpResponseRedirect(quote_plus(
response_data['redirect'], safe='/?=&'))
response_data['redirect'], safe='/?=&'))
- elif
request.is_ajax(
):
+ elif
is_ajax(request
):
# Form was sent with errors. Send them back.
if self.form_prefix:
errors = {}
# Form was sent with errors. Send them back.
if self.form_prefix:
errors = {}
@@
-118,17
+119,17
@@
class AjaxableFormView:
response_data = {'success': False, 'errors': errors}
else:
response_data = None
response_data = {'success': False, 'errors': errors}
else:
response_data = None
- if
request.is_ajax(
):
+ if
is_ajax(request
):
return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
else:
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
is_ajax(request
):
return require_login(request)
form = self.form_class(*form_args, **form_kwargs)
response_data = None
title = self.title
return require_login(request)
form = self.form_class(*form_args, **form_kwargs)
response_data = None
title = self.title
- if
request.is_ajax(
):
+ if
is_ajax(request
):
template = self.template
else:
template = self.full_template
template = self.template
else:
template = self.full_template
@@
-157,7
+158,7
@@
class AjaxableFormView:
def redirect_or_refresh(self, request, path, message=None):
"""If the form is AJAX, refresh the page. If not, go to `path`."""
def redirect_or_refresh(self, request, path, message=None):
"""If the form is AJAX, refresh the page. If not, go to `path`."""
- if
request.is_ajax(
):
+ if
is_ajax(request
):
output = "<script>window.location.reload()</script>"
if message:
output = "<div class='normal-text'>" + message + "</div>" + output
output = "<script>window.location.reload()</script>"
if message:
output = "<div class='normal-text'>" + message + "</div>" + output
diff --git
a/src/catalogue/views.py
b/src/catalogue/views.py
index
5a32932
..
12f47a2
100644
(file)
--- a/
src/catalogue/views.py
+++ b/
src/catalogue/views.py
@@
-4,6
+4,7
@@
from collections import OrderedDict
import random
import re
from collections import OrderedDict
import random
import re
+from urllib.parse import quote_plus
from django.conf import settings
from django.template.loader import render_to_string
from django.conf import settings
from django.template.loader import render_to_string
@@
-12,7
+13,6
@@
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpRespons
from django.urls import reverse
from django.db.models import Q, QuerySet
from django.contrib.auth.decorators import login_required, user_passes_test
from django.urls import reverse
from django.db.models import Q, QuerySet
from django.contrib.auth.decorators import login_required, user_passes_test
-from django.utils.http import urlquote_plus
from django.utils import translation
from django.utils.translation import gettext as _, gettext_lazy
from django.views.decorators.cache import never_cache
from django.utils import translation
from django.utils.translation import gettext as _, gettext_lazy
from django.views.decorators.cache import never_cache
@@
-416,7
+416,7
@@
def download_zip(request, file_format=None, media_format=None, slug=None):
url = book.zip_audiobooks(media_format)
else:
raise Http404('No format specified for zip package')
url = book.zip_audiobooks(media_format)
else:
raise Http404('No format specified for zip package')
- return HttpResponseRedirect(
url
quote_plus(settings.MEDIA_URL + url, safe='/?='))
+ return HttpResponseRedirect(quote_plus(settings.MEDIA_URL + url, safe='/?='))
class CustomPDFFormView(AjaxableFormView):
class CustomPDFFormView(AjaxableFormView):
diff --git
a/src/club/models.py
b/src/club/models.py
index
1a78d76
..
468622f
100644
(file)
--- a/
src/club/models.py
+++ b/
src/club/models.py
@@
-11,10
+11,9
@@
from django.core.mail import send_mail, EmailMessage
from django.urls import reverse
from django.db import models
from django import template
from django.urls import reverse
from django.db import models
from django import template
-from django.utils.timezone import now
+from django.utils.timezone import now
, utc
from django.utils.translation import gettext_lazy as _, ngettext, gettext, get_language
from django_countries.fields import CountryField
from django.utils.translation import gettext_lazy as _, ngettext, gettext, get_language
from django_countries.fields import CountryField
-from pytz import utc
from catalogue.utils import get_random_hash
from messaging.states import Level
from reporting.utils import render_to_pdf
from catalogue.utils import get_random_hash
from messaging.states import Level
from reporting.utils import render_to_pdf
diff --git
a/src/club/payment_methods.py
b/src/club/payment_methods.py
index
9fddff3
..
6bb6f8e
100644
(file)
--- a/
src/club/payment_methods.py
+++ b/
src/club/payment_methods.py
@@
-159,9
+159,8
@@
class PayPal(PaymentMethod):
return agreement_approval_url(schedule.amount, schedule.key, app=app)
def pay(self, request, schedule):
return agreement_approval_url(schedule.amount, schedule.key, app=app)
def pay(self, request, schedule):
- from datetime import date, timedelta, datetime
- from pytz import utc
- tomorrow = datetime(*(date.today() + timedelta(2)).timetuple()[:3], tzinfo=utc)
+ from datetime import date, timedelta, datetime, timezone
+ tomorrow = datetime(*(date.today() + timedelta(2)).timetuple()[:3], tzinfo=timezone.utc)
any_active = False
for ba in schedule.billingagreement_set.all():
active = ba.check_agreement()
any_active = False
for ba in schedule.billingagreement_set.all():
active = ba.check_agreement()
diff --git
a/src/paypal/rest.py
b/src/paypal/rest.py
index
11693cb
..
e70c67b
100644
(file)
--- a/
src/paypal/rest.py
+++ b/
src/paypal/rest.py
@@
-4,7
+4,6
@@
from datetime import date, datetime, timedelta
from decimal import Decimal
import paypalrestsdk
from datetime import date, datetime, timedelta
from decimal import Decimal
import paypalrestsdk
-import pytz
from django.contrib.sites.models import Site
from django.urls import reverse
from django.utils import timezone
from django.contrib.sites.models import Site
from django.urls import reverse
from django.utils import timezone
@@
-70,7
+69,7
@@
def create_agreement(amount, key, app=False):
plan_id = create_plan(amount)
else:
plan_id = plan.plan_id
plan_id = create_plan(amount)
else:
plan_id = plan.plan_id
- start = (timezone.now() + timedelta(0, 3600*24)).astimezone(
pytz
.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
+ start = (timezone.now() + timedelta(0, 3600*24)).astimezone(
timezone
.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
billing_agreement = paypalrestsdk.BillingAgreement({
"name": "Subskrypcja klubu WL",
"description": "Stałe wsparcie Wolnych Lektur kwotą %s złotych" % amount,
billing_agreement = paypalrestsdk.BillingAgreement({
"name": "Subskrypcja klubu WL",
"description": "Stałe wsparcie Wolnych Lektur kwotą %s złotych" % amount,
diff --git
a/src/pdcounter/templatetags/time_tags.py
b/src/pdcounter/templatetags/time_tags.py
index
98d516c
..
4597f04
100644
(file)
--- a/
src/pdcounter/templatetags/time_tags.py
+++ b/
src/pdcounter/templatetags/time_tags.py
@@
-2,7
+2,6
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
import datetime
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
import datetime
-import pytz
from django.conf import settings
from django import template
from django.utils import timezone
from django.conf import settings
from django import template
from django.utils import timezone
@@
-20,10
+19,9
@@
def date_to_utc(date, day_end=False):
"""
if day_end:
date += datetime.timedelta(1)
"""
if day_end:
date += datetime.timedelta(1)
- localtime = datetime.datetime.combine(date, datetime.time(0, 0))
- return timezone.utc.normalize(
- pytz.timezone(settings.TIME_ZONE).localize(localtime)
- )
+
+ localtime = datetime.datetime.combine(date, datetime.time(0, 0), timezone.get_current_timezone())
+ return timezone.localtime(localtime, timezone.utc)
@register.filter
@register.filter
diff --git
a/src/search/fields.py
b/src/search/fields.py
index
10afd59
..
07e50d7
100644
(file)
--- a/
src/search/fields.py
+++ b/
src/search/fields.py
@@
-3,7
+3,7
@@
#
from django import forms
from django.forms.utils import flatatt
#
from django import forms
from django.forms.utils import flatatt
-from django.utils.encoding import smart_
text
+from django.utils.encoding import smart_
str
from django.utils.safestring import mark_safe
from json import dumps
from django.utils.safestring import mark_safe
from json import dumps
@@
-20,7
+20,7
@@
class JQueryAutoCompleteWidget(forms.TextInput):
final_attrs = self.build_attrs(self.attrs, attrs)
final_attrs["name"] = name
if value:
final_attrs = self.build_attrs(self.attrs, attrs)
final_attrs["name"] = name
if value:
- final_attrs['value'] = smart_
text
(value)
+ final_attrs['value'] = smart_
str
(value)
if 'id' not in self.attrs:
final_attrs['id'] = 'id_%s' % name
if 'id' not in self.attrs:
final_attrs['id'] = 'id_%s' % name
diff --git
a/src/social/views.py
b/src/social/views.py
index
b7c8233
..
8966159
100644
(file)
--- a/
src/social/views.py
+++ b/
src/social/views.py
@@
-10,6
+10,7
@@
from ajaxable.utils import AjaxableFormView
from catalogue.models import Book
from social import forms
from catalogue.models import Book
from social import forms
+from wolnelektury.utils import is_ajax
# ====================
# ====================
@@
-25,7
+26,7
@@
def like_book(request, slug):
book.like(request.user)
book.like(request.user)
- if
request.is_ajax(
):
+ if
is_ajax(request
):
return JsonResponse({"success": True, "msg": "ok", "like": True})
else:
return redirect(book)
return JsonResponse({"success": True, "msg": "ok", "like": True})
else:
return redirect(book)
@@
-39,7
+40,7
@@
def unlike_book(request, slug):
book.unlike(request.user)
book.unlike(request.user)
- if
request.is_ajax(
):
+ if
is_ajax(request
):
return JsonResponse({"success": True, "msg": "ok", "like": False})
else:
return redirect(book)
return JsonResponse({"success": True, "msg": "ok", "like": False})
else:
return redirect(book)
diff --git
a/src/waiter/views.py
b/src/waiter/views.py
index
b001fef
..
120e32e
100644
(file)
--- a/
src/waiter/views.py
+++ b/
src/waiter/views.py
@@
-7,6
+7,7
@@
from waiter.settings import WAITER_URL
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.views.decorators.cache import never_cache
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.views.decorators.cache import never_cache
+from wolnelektury.utils import is_ajax
@never_cache
@never_cache
@@
-18,7
+19,7
@@
def wait(request, path):
file_url = None
waiting = get_object_or_404(WaitedFile, path=path)
file_url = None
waiting = get_object_or_404(WaitedFile, path=path)
- if
request.is_ajax(
):
+ if
is_ajax(request
):
return HttpResponse(file_url)
else:
return render(request, "waiter/wait.html", {
return HttpResponse(file_url)
else:
return render(request, "waiter/wait.html", {
diff --git
a/src/wolnelektury/utils.py
b/src/wolnelektury/utils.py
index
c994149
..
33bf42c
100644
(file)
--- a/
src/wolnelektury/utils.py
+++ b/
src/wolnelektury/utils.py
@@
-8,7
+8,6
@@
from inspect import getargspec
from io import BytesIO
import json
import os
from io import BytesIO
import json
import os
-import pytz
import re
from django.conf import settings
import re
from django.conf import settings
@@
-17,22
+16,12
@@
from django.core.cache import cache
from django.core.mail import send_mail
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.core.mail import send_mail
from django.http import HttpResponse
from django.template.loader import render_to_string
-from django.utils import timezone
from django.utils.translation import get_language
from django.conf import settings
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
from django.utils.translation import get_language
from django.conf import settings
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
-tz = pytz.timezone(settings.TIME_ZONE)
-
-
-def localtime_to_utc(localtime):
- return timezone.utc.normalize(
- tz.localize(localtime)
- )
-
-
def utc_for_js(dt):
return dt.strftime('%Y/%m/%d %H:%M:%S UTC')
def utc_for_js(dt):
return dt.strftime('%Y/%m/%d %H:%M:%S UTC')
@@
-211,3
+200,7
@@
class YesNoFilter(admin.SimpleListFilter):
return queryset.filter(self.q)
elif self.value() == 'no':
return queryset.exclude(self.q)
return queryset.filter(self.q)
elif self.value() == 'no':
return queryset.exclude(self.q)
+
+
+def is_ajax(request):
+ return request.headers.get('x-requested-with') == 'XMLHttpRequest'
diff --git
a/src/wolnelektury/views.py
b/src/wolnelektury/views.py
index
61c55c4
..
1855222
100644
(file)
--- a/
src/wolnelektury/views.py
+++ b/
src/wolnelektury/views.py
@@
-2,6
+2,7
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from datetime import date, datetime
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from datetime import date, datetime
+from urllib.parse import quote_plus
import feedparser
from allauth.socialaccount.views import SignupView
import feedparser
from allauth.socialaccount.views import SignupView
@@
-12,7
+13,6
@@
from django.contrib.auth.forms import AuthenticationForm
from django.core.cache import cache
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.core.cache import cache
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
-from django.utils.http import urlquote_plus
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
@@
-131,7
+131,7
@@
class LoginRegisterFormView(LoginFormView):
@never_cache
def logout_then_redirect(request):
auth.logout(request)
@never_cache
def logout_then_redirect(request):
auth.logout(request)
- return HttpResponseRedirect(
url
quote_plus(request.GET.get('next', '/'), safe='/?='))
+ return HttpResponseRedirect(quote_plus(request.GET.get('next', '/'), safe='/?='))
@never_cache
@never_cache