diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index cb78130c..9ef4fa53 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -1,3 +1,4 @@ +from django.urls import path from django.conf.urls import include, url from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns @@ -15,8 +16,8 @@ urlpatterns = [ url('^assets/', include('assets.urls')), url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail), name="registration_register"), - url('^user/', include('django.contrib.auth.urls')), - url('^user/', include('registration.backends.default.urls')), + path('user/', include('django.contrib.auth.urls')), + path('user/', include('registration.backends.default.urls')), url(r'^admin/', admin.site.urls), ] diff --git a/RIGS/urls.py b/RIGS/urls.py index 9de5a494..34d97b14 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -1,3 +1,4 @@ +from django.urls import path from django.conf.urls import url from django.contrib.auth.views import PasswordResetView @@ -16,8 +17,7 @@ urlpatterns = [ url('^$', login_required(views.Index.as_view()), name='index'), url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'), - url('^user/login/$', views.login, name='login'), - url('^user/login/embed/$', xframe_options_exempt(views.login_embed), name='login_embed'), + path('user/login/embed/', xframe_options_exempt(views.LoginEmbed.as_view()), name='login_embed'), url(r'^user/password_reset/$', PasswordResetView.as_view()), diff --git a/RIGS/versioning.py b/RIGS/versioning.py index 9dff4a3e..f9056abf 100644 --- a/RIGS/versioning.py +++ b/RIGS/versioning.py @@ -184,8 +184,7 @@ class RIGSVersion(Version): versions = RIGSVersion.objects.get_for_object_reference(self.content_type.model_class(), thisId).select_related("revision", "revision__user").all() try: - previousVersion = versions.filter(revision_id__lt=self.revision_id).latest( - field_name='revision__date_created') + previousVersion = versions.filter(revision_id__lt=self.revision_id).latest('revision__date_created') except ObjectDoesNotExist: return False diff --git a/RIGS/views.py b/RIGS/views.py index f8494e25..a7655ccc 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -3,6 +3,7 @@ from django.http.response import HttpResponseRedirect from django.http import HttpResponse from django.urls import reverse_lazy, reverse, NoReverseMatch from django.views import generic +from django.contrib.auth.views import LoginView from django.db.models import Q from django.shortcuts import get_object_or_404 from django.core import serializers @@ -34,28 +35,15 @@ class Index(generic.TemplateView): return context -def login(request, **kwargs): - if request.user.is_authenticated: - next = request.GET.get('next', '/') - return HttpResponseRedirect(next) - else: - from django.contrib.auth.views import login - - return login(request) - - # This view should be exempt from requiring CSRF token. # Then we can check for it and show a nice error # Don't worry, django.contrib.auth.views.login will # check for it before logging the user in -@csrf_exempt -def login_embed(request, **kwargs): - if request.user.is_authenticated: - next = request.GET.get('next', '/') - return HttpResponseRedirect(next) - else: - from django.contrib.auth.views import login +class LoginEmbed(LoginView): + template_name = 'registration/login_embed.html' + @csrf_exempt + def dispatch(self, request, *args, **kwargs): if request.method == "POST": csrf_cookie = request.COOKIES.get('csrftoken', None) @@ -63,7 +51,7 @@ def login_embed(request, **kwargs): messages.warning(request, 'Cookies do not seem to be enabled. Try logging in using a new tab.') request.method = 'GET' # Render the page without trying to login - return login(request, template_name="registration/login_embed.html", authentication_form=forms.EmbeddedAuthenticationForm) + return super().dispatch(request, *args, **kwargs) """ diff --git a/requirements.txt b/requirements.txt index 9974ee1f..b3109681 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ icalendar==4.0.4 lxml==4.5.0 Markdown==3.2.1 Pillow==7.0.0 -psycopg2==2.8.4 +psycopg2-binary==2.8.4 Pygments==2.5.2 PyPDF2==1.26.0 python-dateutil==2.8.1 @@ -38,4 +38,4 @@ z3c.rml==3.9.1 zope.event==4.4 zope.interface==4.7.1 zope.schema==4.9.3 -pypom==2.2.0 \ No newline at end of file +pypom==2.2.0 diff --git a/templates/400.html b/templates/400.html index dda8d561..85b6b95a 100644 --- a/templates/400.html +++ b/templates/400.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Bad Request{% endblock %} {% block content %} diff --git a/templates/401.html b/templates/401.html index 7fc7dfe0..9b1d45bc 100644 --- a/templates/401.html +++ b/templates/401.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Unauthorized{% endblock %} {% block content %} diff --git a/templates/403.html b/templates/403.html index 7fdb8f24..734e3116 100644 --- a/templates/403.html +++ b/templates/403.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Forbidden{% endblock %} {% block content %} diff --git a/templates/404.html b/templates/404.html index 5a4ef0bf..d1f933d8 100644 --- a/templates/404.html +++ b/templates/404.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Page Not Found{% endblock %} {% block content %} diff --git a/templates/500.html b/templates/500.html index 26fd115d..39802962 100644 --- a/templates/500.html +++ b/templates/500.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Server error{% endblock %} {% block content %} diff --git a/templates/base_embed.html b/templates/base_embed.html index 6a7a8741..c4fb417b 100644 --- a/templates/base_embed.html +++ b/templates/base_embed.html @@ -1,4 +1,4 @@ -{% load static from staticfiles %} +{% load static %} {% load raven %} diff --git a/templates/login_redirect.html b/templates/login_redirect.html index 6b69cdfd..29bb8ef7 100644 --- a/templates/login_redirect.html +++ b/templates/login_redirect.html @@ -1,5 +1,5 @@ {% extends 'base_rigs.html' %} -{% load staticfiles %} +{% load static %} {% block title %}Login Required{% endblock %} {% block js %} diff --git a/templates/registration/loginform.html b/templates/registration/loginform.html index 328ad18b..20fde945 100644 --- a/templates/registration/loginform.html +++ b/templates/registration/loginform.html @@ -1,8 +1,6 @@ - {% load widget_tweaks %} {% include 'form_errors.html' %}