Update django3

This commit is contained in:
hhummel 2021-02-09 12:48:51 -05:00
parent 6bd5bdc9f1
commit 7d97b690f2
3 changed files with 31 additions and 22 deletions

View file

@ -15,6 +15,7 @@ env:
- DJANGO="Django>=1.11,<2.0"
- DJANGO="Django>=2.0,<2.1"
- DJANGO="Django==2.2.12"
- DJANGO="Django==3.1.6"
- DJANGO="https://github.com/django/django/archive/master.tar.gz"
matrix:
@ -30,6 +31,8 @@ matrix:
env: DJANGO="https://github.com/django/django/archive/master.tar.gz"
- python: "3.6"
env: DJANGO="Django>=1.8,<1.11"
- python: "2.7"
env: DJANGO="Django==3.1.6"
allow_failures:
- env: DJANGO="https://github.com/django/django/archive/master.tar.gz"

View file

@ -65,6 +65,17 @@ def get_middleware_settings_key():
return 'MIDDLEWARE_CLASSES'
def get_render(request, template_name, context):
if django.VERSION >= (1, 10, 0):
from django.shortcuts import render
return render(request, template_name, context)
else:
from django.shortcuts import render_to_response
from django.template import RequestContext
return render_to_response(template_name, context, RequestContext(request))
if django.VERSION < (1, 5):
from django.templatetags.future import url
else:

View file

@ -8,14 +8,12 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect
from django.shortcuts import render, render_to_response
from django.template import RequestContext
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.generic import TemplateView
from django.utils.translation import ugettext_lazy as _
from tos.compat import get_cache, get_runtime_user_model, get_request_site
from tos.compat import get_cache, get_runtime_user_model, get_request_site, get_render
from tos.models import has_user_agreed_latest_tos, TermsOfService, UserAgreement
@ -77,19 +75,12 @@ def check_tos(request, template_name='tos/tos_check.html',
request,
_(u"You cannot login without agreeing to the terms of this site.")
)
if DJANGO_VERSION >= (1, 10, 0):
return render(request, template_name, {
'tos': tos,
'redirect_field_name': redirect_field_name,
'next': redirect_to,
})
else:
return render_to_response(template_name, {
'tos': tos,
'redirect_field_name': redirect_field_name,
'next': redirect_to,
}, RequestContext(request))
context = {
'tos': tos,
'redirect_field_name': redirect_field_name,
'next': redirect_to,
}
return get_render(request, template_name, context)
@csrf_protect
@ -131,11 +122,12 @@ def login(request, template_name='registration/login.html',
# see: https://docs.djangoproject.com/en/1.6/topics/auth/default/#how-to-log-a-user-in
request.session['tos_backend'] = user.backend
return render_to_response('tos/tos_check.html', {
redirect_field_name: redirect_to,
context = {
'redirect_field_name': redirect_to,
'tos': TermsOfService.objects.get_current_tos()
}, RequestContext(request))
}
return get_render(request, 'tos/tos_check.html', context)
else:
form = authentication_form(request)
@ -146,9 +138,12 @@ def login(request, template_name='registration/login.html',
else:
current_site = get_request_site()(request)
return render_to_response(template_name, {
context = {
'form': form,
redirect_field_name: redirect_to,
'redirect_field_name': redirect_to,
'site': current_site,
'site_name': current_site.name,
}, RequestContext(request))
}
return get_render(request, template_name, context)