Skip to content

Commit

Permalink
Updates for Django 4 deprecations.
Browse files Browse the repository at this point in the history
Updated ugettext_lazy, url(), NullBooleanField, ifequal/ifnotequal, and
CachedStaticFilesStorage. Added DEFAULT_AUTO_FIELD, removed login view
and nose. Pinned tox to 3.9 and added keepdb. Upgrade reversion.
  • Loading branch information
dracos committed Nov 19, 2023
1 parent 11c14fe commit d5d3e87
Show file tree
Hide file tree
Showing 36 changed files with 276 additions and 313 deletions.
8 changes: 4 additions & 4 deletions autocomplete/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from django.http import HttpResponse, HttpResponseRedirect

from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
from django.utils.translation import ugettext as _
from django.utils.encoding import force_text
from django.utils.translation import gettext as _
from django.utils.encoding import force_str
from django.utils.html import escape
from django.utils.datastructures import MultiValueDict

Expand Down Expand Up @@ -259,7 +259,7 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
opts = obj._meta
pk_value = obj._get_pk_val()

msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}
msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_str(opts.verbose_name), 'obj': force_str(obj)}
# Here, we distinguish between different save types by checking for
# the presence of keys in request.POST.
if '_continue' in request.POST:
Expand All @@ -274,7 +274,7 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
return HttpResponse('<script type="text/javascript">opener.dismissAutocompletePopup(window, "%s", "%s");</script>' % (escape(pk_value), escape(obj)))

elif '_addanother' in request.POST:
self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_text(opts.verbose_name)))
self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_str(opts.verbose_name)))
return HttpResponseRedirect(request.path)
else:
self.message_user(request, msg)
Expand Down
2 changes: 1 addition & 1 deletion countries/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class Country(models.Model):
Expand Down
10 changes: 5 additions & 5 deletions lp/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.conf.urls import url
from django.urls import path
from lp import views


urlpatterns = [
url(r'^edition/$', views.edition),
url(r'^sample/$', views.sample),
url(r'^meta.json$', views.meta_json),
url(r'^icon.png$', views.icon),
path('edition/', views.edition),
path('sample/', views.sample),
path('meta.json', views.meta_json),
path('icon.png', views.icon),
]
20 changes: 10 additions & 10 deletions merged/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@

class MergeTest(TestCase):
def test_doing_a_merge(self):
make_production(
hamlet1 = make_production(
'Hamlet',
'A tragedy',
['Shakespeare Productions'],
[{'name': 'Theatre', 'start': '2013-01-01', 'end': '2013-01-14'}]
)
make_production(
hamlet2 = make_production(
'Hamlet',
'A tragedy',
['Shakespeare Productions'],
[{'name': 'Stirchley Theatre', 'start': '2013-01-01', 'end': '2013-01-14'}]
)
resp = self.client.get('/play/1/hamlet/production/1')
resp = self.client.get(hamlet1.get_absolute_url())
self.assertContains(resp, 'Hamlet')
resp = self.client.get('/play/1/hamlet/production/2')
resp = self.client.get(hamlet2.get_absolute_url())
self.assertContains(resp, 'Hamlet')
resp = self.client.get('/play/1/hamlet/production/2/merge')
resp = self.client.get(hamlet2.get_absolute_url() + '/merge')
self.assertContains(resp, 'Thanks for helping improve the accuracy of the site.')
resp = self.client.get('/play/1/hamlet/production/2')
resp = self.client.get(hamlet2.get_absolute_url())
self.assertNotContains(resp, 'This is a duplicate')
resp = self.client.get('/play/1/hamlet/production/1')
resp = self.client.get(hamlet1.get_absolute_url())
self.assertContains(resp, 'This is a duplicate of Shakespeare Productions production of Hamlet')
resp = self.client.post('/play/1/hamlet/production/1/merge', {'dupe': True})
resp = self.client.post(hamlet1.get_absolute_url() + '/merge', {'dupe': True})
self.assertContains(resp, 'Thanks again for helping')
self.assertEqual(len(mail.outbox), 1)

resp = self.client.post('/play/1/hamlet/production/1/merge', {'stop': True}, follow=True)
self.assertRedirects(resp, '/play/1/hamlet/production/1')
resp = self.client.post(hamlet1.get_absolute_url() + '/merge', {'stop': True}, follow=True)
self.assertRedirects(resp, hamlet1.get_absolute_url())
2 changes: 1 addition & 1 deletion productions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class Part(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
role = models.CharField(
u'R\u00f4le', max_length=200, blank=True, help_text=u'e.g. \u201cRomeo\u201d or \u201cDirector\u201d')
cast = models.NullBooleanField(
cast = models.BooleanField(
null=True, blank=True, verbose_name='Cast/Crew',
help_text=u'Crew includes all non-cast, from director to musicians to producers')
credited_as = models.CharField(
Expand Down
2 changes: 1 addition & 1 deletion profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class User(AbstractUser):
Expand Down
54 changes: 5 additions & 49 deletions profiles/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from django.http import HttpResponseRedirect, Http404
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
from django.contrib.auth import REDIRECT_FIELD_NAME, login as auth_login
from django.conf import settings
from django.shortcuts import render, resolve_url
from django.template.response import TemplateResponse
from django.utils.http import is_safe_url
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from django.contrib.auth import login as auth_login
from django.contrib.auth.views import LoginView as DjangoLoginView
from django.shortcuts import render

from django.db.models import Q, Min
from django.db.models.expressions import RawSQL
Expand Down Expand Up @@ -79,46 +73,8 @@ def register(request):
return render(request, 'registration/register.html', {'form': form})


@sensitive_post_parameters()
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME,
authentication_form=AuthenticationForm,
extra_context=None):
"""
Displays the login form and handles the login action.
"""
redirect_to = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name, ''))

if request.method == "POST":
form = authentication_form(request, data=request.POST)
if form.is_valid():

# Ensure the user-originating redirection url is safe.
if not is_safe_url(url=redirect_to, allowed_hosts=request.get_host()):
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)

# Okay, security check complete. Log the user in.
auth_login(request, form.get_user())

return HttpResponseRedirect(redirect_to)
else:
form = authentication_form(request)

current_site = get_current_site(request)

context = {
'form': form,
redirect_field_name: redirect_to,
'site': current_site,
'site_name': current_site.name,
}
if extra_context is not None:
context.update(extra_context)

return TemplateResponse(request, template_name, context)
class LoginView(DjangoLoginView):
form_class = AuthenticationForm


# def registration_complete(request):
Expand Down
6 changes: 4 additions & 2 deletions requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mysqlclient==2.0.2
Pillow==10.1.0
# Upgrade to 8.0.0 when DJ3
django-cleanup==6.0.0
django-contrib-comments==2.2.0
django-nose==1.4.7
django-reversion==3.0.7
# Upgrade to 5.0.8 when DJ3
django-reversion==4.0.2
# Upgrade to 12.10.0 when running on DJ3
sorl-thumbnail==12.8.0
python-dateutil==2.8.2
12 changes: 6 additions & 6 deletions templates/admin/edit_part_inline.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
<thead><tr>
{% for field in inline_admin_formset.fields %}
{% if not field.is_hidden %}
{% ifnotequal field.label 'LookupPerson' %}
{% if field.label != 'LookupPerson' %}
<th {% if forloop.first %}colspan="2"{% endif %}>{{ field.label|capfirst }}</th>
{% endifnotequal %}
{% endif %}
{% endif %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
Expand Down Expand Up @@ -63,17 +63,17 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
{% ifnotequal field.field.name 'lookup_person' %}
{% if field.field.name != 'lookup_person' %}
<td class="{{ field.field.name }}">
{{ field.field.errors.as_ul }}
{% ifequal field.field.name 'person' %}
{% if field.field.name == 'person' %}
<input type="hidden" name="{{ field.field.html_name }}" id="id_{{ field.field.html_name }}" value="{{ field.field.form.initial.person }}"/>
<input type="text" class="lookup_person" id="lookup_{{ field.field.html_name }}" value="{{ field.field.form.initial.lookup_person }}" size="40"/>
{% else %}
{{ field.field }}
{% endifequal %}
{% endif %}
</td>
{% endifnotequal %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<a href="{% url "profile" user %}">Your profile</a>
| <a href="{% url "logout" %}">Sign out</a>
{% else %}
<a href="{% url "login" %}{% ifnotequal request.path '/tickets/returns' %}?next={{ request.path }}{% endifnotequal %}">Sign in</a>
<a href="{% url "login" %}{% if request.path != '/tickets/returns' %}?next={{ request.path }}{% endif %}">Sign in</a>
{% endif %}
</p>
{% endblock %}
Expand All @@ -160,9 +160,9 @@
</p>
{% endif %}

{% ifequal request.META.HTTP_HOST "staging.theatricalia.com" %}
{% if request.META.HTTP_HOST == "staging.theatricalia.com" %}
<div id="banner_big">Staging site (behind the scenes)</div>
{% else %}
{% endifequal %}
{% endif %}
</body>
</html>
26 changes: 11 additions & 15 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ <h2>For example&hellip;</h2>
by {{ production.get_companies_display }}{% endif %},
{% endthumbnail %}

{% ifequal production.places.count 1 %}
{% if production.places.count == 1 %}
{{ production.date_summary|prettify }},
at <a href="{{ production.places.all.0.get_absolute_url }}">{{ production.places.all.0.get_name_display|prettify }}</a>.</p>
{% else %}
{% ifequal production.places.count 0 %}
{% if production.places.count == 0 %}
at an unknown location.
{% else %}
at
{% for place in production.place_set.all %}
{% if forloop.last and not forloop.first %} and {% endif %}
<a href="{{ place.place.get_absolute_url }}">{{ place.place.get_name_display|prettify }}</a>
<small>({{ place.date_summary|prettify }})</small>{% ifequal forloop.revcounter0 0 %}{% else %}{% ifequal forloop.revcounter0 1 %}{% ifnotequal forloop.counter0 0 %},{% endifnotequal %}{% else %},{% endifequal %}{% endifequal %}{% endfor %}.
{% endifequal %}
{% endifequal %}
<small>({{ place.date_summary|prettify }})</small>{% if forloop.revcounter0 == 0 %}{% elif forloop.revcounter0 == 1 %}{% if forloop.counter0 != 0 %},{% endif %}{% else %},{% endif %}{% endfor %}.
{% endif %}
{% endif %}

<p align="right"><a href="{{ production.get_absolute_url }}">More &rarr;</a></p>

Expand Down Expand Up @@ -106,31 +106,27 @@ <h2 class="no-descenders">Most recent&hellip;</h2>
<li><strong>&hellip;addition:</strong>
{% if latest_production %}
<a href="{{ latest_production.get_absolute_url }}">{{ latest_production.play.get_title_display|prettify }}</a>,
{% ifequal latest_production.places.count 1 %}
{% if latest_production.places.count == 1 %}
at <a href="{{ latest_production.places.all.0.get_absolute_url }}">{{ latest_production.places.all.0|prettify }}</a>,
{{ latest_production.date_summary|prettify }}.
{% if latest_production.place_set.all.0.press_date and latest_production.place_set.all.0.start_date %}
Press night was {{ latest_production.place_set.all.0.press_date|date:"jS F Y"|prettify }}.
{% endif %}
{% else %}
{% ifequal latest_production.places.count 0 %}
{% elif latest_production.places.count == 0 %}
at an unknown location.
{% else %}
{% firstof latest_production.place_set_ordered|length as places %}
at
{% for place in latest_production.place_set_ordered|slice:":5" %}
{% if forloop.last and not forloop.first and places|add:0 <= 5 %} and {% endif %}
<a href="{{ place.place.get_absolute_url }}">{{ place.place|prettify }}</a>
<small>({{ place.date_summary|prettify }})</small>{% ifequal forloop.revcounter0 0 %}{% else %}{% ifequal forloop.revcounter0 1 %}{% ifnotequal forloop.counter0 0 %},{% endifnotequal %}{% else %},{% endifequal %}{% endifequal %}{% endfor %}{% if places|add:0 > 5 %} and other locations{% endif %}.
{% endifequal %}
{% endifequal %}
{% ifnotequal latest_production.last_modifier latest_production.creator %}
<small>({{ place.date_summary|prettify }})</small>{% if forloop.revcounter0 == 0 %}{% elif forloop.revcounter0 == 1 %}{% if forloop.counter0 != 0 %},{% endif %}{% else %},{% endif %}{% endfor %}{% if places|add:0 > 5 %} and other locations{% endif %}.
{% endif %}
{% if latest_production.last_modifier != latest_production.creator %}
Added by <a href="{{ latest_production.creator.profile.get_absolute_url }}">{{ latest_production.creator.name }}</a>, last modified by <a href="{{ latest_production.last_modifier.profile.get_absolute_url }}">{{ latest_production.last_modifier.name }}</a>.
{% else %}
{% if latest_production.creator.name %}
{% elif latest_production.creator.name %}
Added by <a href="{{ latest_production.creator.profile.get_absolute_url }}">{{ latest_production.creator.name }}</a>.
{% endif %}
{% endifnotequal %}
{% else %}
Nothing in the system yet!
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions templates/merged/buttons.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% ifnotequal object.id duplicate.id %}
{% if object.id != duplicate.id %}
<div class="secondary">
<form action="{{ object.get_absolute_url }}/merge" method="post">{% csrf_token %}
<p align="center"><input type="submit" name="dupe" value="This is a duplicate of {{ duplicate.name }}" id="edit-form-submit">
<br><input type="submit" name="stop" value="Stop looking for duplicates"></p>
</form>
</div>
{% endifnotequal %}
{% endif %}
12 changes: 6 additions & 6 deletions templates/pagination.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% load humanize %}
{% if page_obj.has_other_pages %}
<p class="pagination">
{% if page_obj.has_previous %}
{% ifequal page_obj.previous_page_number 1 %}
{% if page_obj.has_previous %}
{% if page_obj.previous_page_number == 1 %}
<a href="{{ request.path }}">&larr; Previous</a>
{% else %}
<a href="?page={{ page_obj.previous_page_number }}">&larr; Previous</a>
{% endifequal %}
{% else %}
<span class="greyed">&larr; Previous</span>
{% endif %}
{% endif %}
{% else %}
<span class="greyed">&larr; Previous</span>
{% endif %}
&middot;
<span class="current">
{{ page_obj.start_index }} to {{ page_obj.end_index }} of {{ paginator.count|intcomma }}
Expand Down
8 changes: 4 additions & 4 deletions templates/people/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ <h2>Current &amp; Upcoming productions</h2>
{{ production.part__role__concatenate }}, {% endif %}
<a itemprop="url" href="{{ production.get_absolute_url }}">{{ production.play.get_title_display|prettify }}</a>{% if production.get_companies_display %}, {{ production.get_companies_display }}{% endif %}
<span class="meta">{{ production.date_summary|prettify }},
{% ifequal production.places.count 1 %}
{% if production.places.count == 1 %}
<a href="{{ production.place_summary.get_absolute_url }}">{{ production.place_summary|prettify }}</a>.
{% else %}
{{ production.place_summary|prettify }}.
{% endifequal %}
{% endif %}
</span>
{% endfor %}
</ul>
Expand All @@ -70,11 +70,11 @@ <h2>Past productions</h2>
{{ production.part__role__concatenate }}, {% endif %}
<a itemprop="url" href="{{ production.get_absolute_url }}">{{ production.play.get_title_display|prettify }}</a>{% if production.get_companies_display %}, {{ production.get_companies_display }}{% endif %}
<span class="meta">{{ production.date_summary|prettify }},
{% ifequal production.places.count 1 %}
{% if production.places.count == 1 %}
<a href="{{ production.place_summary.get_absolute_url }}">{{ production.place_summary|prettify }}</a>.
{% else %}
{{ production.place_summary|prettify }}.
{% endifequal %}
{% endif %}
</span>
{% endfor %}
</ul>
Expand Down
Loading

0 comments on commit d5d3e87

Please sign in to comment.