Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade to Django 3.0 #5601

Merged
merged 22 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e1b783e
chore: Update requirements.txt for Django 3.0
jennifer-richards May 8, 2023
9fda268
fix: Replace `available_attrs` helper (dropped by Django 3.0)
jennifer-richards May 8, 2023
6d4d095
fix: Replace obsolete `curry()` with `functools.partialmethod()`
jennifer-richards May 9, 2023
9fde845
chore: Revert psycopg2 dependency
jennifer-richards May 9, 2023
2cf2a3d
chore: Remove django-cookie-delete-with-all-settings.patch
jennifer-richards May 9, 2023
dcb211f
Merge remote-tracking branch 'origin/main' into django4
jennifer-richards May 9, 2023
07e26dd
refactor: Replace deprecated force_text with force_str
jennifer-richards May 9, 2023
da16839
refactor: Replace deprecated smart_text with smart_str
jennifer-richards May 9, 2023
31fd431
chore: Tweak add-django-http-cookie-value-none.patch for Django 3.0
jennifer-richards May 9, 2023
ed571ae
chore: Rename DB engine to drop the deprecated "_psycopg2" suffix
jennifer-richards May 10, 2023
69eb634
test: Do not misuse django.conf.settings for HTML validation params
jennifer-richards May 10, 2023
57026bb
Revert "chore: Remove django-cookie-delete-with-all-settings.patch"
jennifer-richards May 10, 2023
21ac8c0
chore: Fix cookie-delete patch to work with Django 3.0
jennifer-richards May 10, 2023
a75dbd4
chore: Remove accidentally reverted removal of form_utils app
jennifer-richards May 10, 2023
85d0934
refactor: Refactor LiaisonForm without BetterModelForm
jennifer-richards May 10, 2023
163479b
refactor: Replace obsolete `staticfiles` template lib with `static`
jennifer-richards May 10, 2023
4f443cc
refactor: Explicitly allow name=None for a couple of views
jennifer-richards May 10, 2023
1015cf8
fix: Finish refactoring LiaisonModelForm subclasses without BetterMod…
jennifer-richards May 10, 2023
e6259a5
chore: Remove filter on staticfiles DeprecationWarning
jennifer-richards May 10, 2023
406ba7b
style: Apply Black style to active_group_types() view
jennifer-richards May 10, 2023
eee145e
fix: Explicitly order GroupTypeNames in active_group_types
jennifer-richards May 10, 2023
0d07059
style: Double backslashes in strings
jennifer-richards May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/deploy-to-container/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'HOST': '__DBHOST__',
'PORT': 5432,
'NAME': 'datatracker',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'django',
'PASSWORD': 'RkTkDPFnKpko',
},
Expand Down
2 changes: 1 addition & 1 deletion dev/diff/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'HOST': '__DBHOST__',
'PORT': 5432,
'NAME': 'datatracker',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'django',
'PASSWORD': 'RkTkDPFnKpko',
},
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'HOST': 'db',
'PORT': 5432,
'NAME': 'datatracker',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'django',
'PASSWORD': 'RkTkDPFnKpko',
},
Expand Down
2 changes: 1 addition & 1 deletion docker/configs/settings_postgresqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'HOST': 'db',
'PORT': 5432,
'NAME': 'datatracker',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'django',
'PASSWORD': 'RkTkDPFnKpko',
},
Expand Down
14 changes: 7 additions & 7 deletions ietf/api/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.exceptions import ObjectDoesNotExist, FieldError
from django.core.serializers.json import Serializer
from django.http import HttpResponse
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.db.models import Field
from django.db.models.query import QuerySet
from django.db.models.signals import post_save, post_delete, m2m_changed
Expand Down Expand Up @@ -121,7 +121,7 @@ def end_object(self, obj):
for name in expansions:
try:
field = getattr(obj, name)
#self._current["_"+name] = smart_text(field)
#self._current["_"+name] = smart_str(field)
if not isinstance(field, Field):
options = self.options.copy()
options["expand"] = [ v[len(name)+2:] for v in options["expand"] if v.startswith(name+"__") ]
Expand Down Expand Up @@ -188,10 +188,10 @@ def handle_fk_field(self, obj, field):
related = related.natural_key()
elif field.remote_field.field_name == related._meta.pk.name:
# Related to remote object via primary key
related = smart_text(related._get_pk_val(), strings_only=True)
related = smart_str(related._get_pk_val(), strings_only=True)
else:
# Related to remote object via other field
related = smart_text(getattr(related, field.remote_field.field_name), strings_only=True)
related = smart_str(getattr(related, field.remote_field.field_name), strings_only=True)
self._current[field.name] = related

def handle_m2m_field(self, obj, field):
Expand All @@ -201,7 +201,7 @@ def handle_m2m_field(self, obj, field):
elif self.use_natural_keys and hasattr(field.remote_field.to, 'natural_key'):
m2m_value = lambda value: value.natural_key()
else:
m2m_value = lambda value: smart_text(value._get_pk_val(), strings_only=True)
m2m_value = lambda value: smart_str(value._get_pk_val(), strings_only=True)
self._current[field.name] = [m2m_value(related)
for related in getattr(obj, field.name).iterator()]

Expand All @@ -221,7 +221,7 @@ class JsonExportMixin(object):
# obj = None
#
# if obj is None:
# raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.model._meta.verbose_name), 'key': escape(object_id)})
# raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_str(self.model._meta.verbose_name), 'key': escape(object_id)})
#
# content_type = 'application/json'
# return HttpResponse(serialize([ obj ], sort_keys=True, indent=3)[2:-2], content_type=content_type)
Expand Down Expand Up @@ -264,6 +264,6 @@ def json_view(self, request, filter=None, expand=None):
qd = dict( ( k, json.loads(v)[0] ) for k,v in items )
except (FieldError, ValueError) as e:
return HttpResponse(json.dumps({"error": str(e)}, sort_keys=True, indent=3), content_type=content_type)
text = json.dumps({smart_text(self.model._meta): qd}, sort_keys=True, indent=3)
text = json.dumps({smart_str(self.model._meta): qd}, sort_keys=True, indent=3)
return HttpResponse(text, content_type=content_type)

10 changes: 5 additions & 5 deletions ietf/doc/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.conf import settings
from django.urls import reverse as urlreverse
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.encoding import force_str

import debug # pyflakes:ignore
from ietf.doc.templatetags.mail_filters import std_level_prompt
Expand Down Expand Up @@ -175,7 +175,7 @@ def generate_ballot_writeup(request, doc):
e.doc = doc
e.rev = doc.rev
e.desc = "Ballot writeup was generated"
e.text = force_text(render_to_string("doc/mail/ballot_writeup.txt", {'iana': iana, 'doc': doc }))
e.text = force_str(render_to_string("doc/mail/ballot_writeup.txt", {'iana': iana, 'doc': doc }))

# caller is responsible for saving, if necessary
return e
Expand All @@ -187,7 +187,7 @@ def generate_ballot_rfceditornote(request, doc):
e.doc = doc
e.rev = doc.rev
e.desc = "RFC Editor Note for ballot was generated"
e.text = force_text(render_to_string("doc/mail/ballot_rfceditornote.txt"))
e.text = force_str(render_to_string("doc/mail/ballot_rfceditornote.txt"))
e.save()

return e
Expand Down Expand Up @@ -232,7 +232,7 @@ def generate_last_call_announcement(request, doc):
e.doc = doc
e.rev = doc.rev
e.desc = "Last call announcement was generated"
e.text = force_text(mail)
e.text = force_str(mail)

# caller is responsible for saving, if necessary
return e
Expand All @@ -252,7 +252,7 @@ def generate_approval_mail(request, doc):
e.doc = doc
e.rev = doc.rev
e.desc = "Ballot approval text was generated"
e.text = force_text(mail)
e.text = force_str(mail)

# caller is responsible for saving, if necessary
return e
Expand Down
6 changes: 3 additions & 3 deletions ietf/doc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.html import mark_safe # type:ignore
from django.contrib.staticfiles import finders

Expand Down Expand Up @@ -1131,7 +1131,7 @@ class DocHistory(DocumentInfo):
name = models.CharField(max_length=255)

def __str__(self):
return force_text(self.doc.name)
return force_str(self.doc.name)

def get_related_session(self):
return self.doc.get_related_session()
Expand Down Expand Up @@ -1193,7 +1193,7 @@ def document(self):
return self.docs.first()

def __str__(self):
return u"%s-->%s" % (self.name, ','.join([force_text(d.name) for d in self.docs.all() if isinstance(d, Document) ]))
return u"%s-->%s" % (self.name, ','.join([force_str(d.name) for d in self.docs.all() if isinstance(d, Document) ]))
document_link = admin_link("document")
class Meta:
verbose_name = "document alias"
Expand Down
5 changes: 2 additions & 3 deletions ietf/doc/templatetags/ietf_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from django.template.defaultfilters import truncatewords_html, linebreaksbr, stringfilter, striptags
from django.utils.safestring import mark_safe, SafeData
from django.utils.html import strip_tags
from django.utils.encoding import force_text
from django.utils.encoding import force_str # pyflakes:ignore force_str is used in the doctests
from django.utils.encoding import force_str
from django.urls import reverse as urlreverse
from django.core.cache import cache
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -132,7 +131,7 @@ def bracketpos(pos,posslug):
@register.filter
def prettystdname(string, space=" "):
from ietf.doc.utils import prettify_std_name
return prettify_std_name(force_text(string or ""), space)
return prettify_std_name(force_str(string or ""), space)

@register.filter
def rfceditor_info_url(rfcnum : str):
Expand Down
6 changes: 3 additions & 3 deletions ietf/doc/utils_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.urls import reverse as urlreverse
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.encoding import smart_text, force_text
from django.utils.encoding import smart_str, force_str

import debug # pyflakes:ignore

Expand Down Expand Up @@ -153,7 +153,7 @@ def generate_ballot_writeup(request, doc):
e.doc = doc
e.rev = doc.rev,
e.desc = "Ballot writeup was generated"
e.text = force_text(render_to_string("doc/charter/ballot_writeup.txt"))
e.text = force_str(render_to_string("doc/charter/ballot_writeup.txt"))

# caller is responsible for saving, if necessary
return e
Expand Down Expand Up @@ -197,7 +197,7 @@ def derive_new_work_text(review_text,group):
'Reply_to':'<[email protected]>'})
if not addrs.cc:
del m['Cc']
return smart_text(m.as_string())
return smart_str(m.as_string())

def default_review_text(group, charter, by):
now = timezone.now()
Expand Down
4 changes: 2 additions & 2 deletions ietf/doc/views_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.html import escape

import debug # pyflakes:ignore
Expand Down Expand Up @@ -821,7 +821,7 @@ def charter_with_milestones_txt(request, name, rev):

try:
with io.open(os.path.join(settings.CHARTER_PATH, filename), 'r') as f:
charter_text = force_text(f.read(), errors='ignore')
charter_text = force_str(f.read(), errors='ignore')
except IOError:
charter_text = "Error reading charter text %s" % filename

Expand Down
6 changes: 3 additions & 3 deletions ietf/doc/views_status_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.urls import reverse
from django.template.loader import render_to_string
from django.conf import settings
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.html import escape

import debug # pyflakes:ignore
Expand Down Expand Up @@ -531,7 +531,7 @@ def rfc_status_changes(request):
)

@role_required("Area Director","Secretariat")
def start_rfc_status_change(request,name):
def start_rfc_status_change(request, name=None):
"""Start the RFC status change review process, setting the initial shepherding AD, and possibly putting the review on a telechat."""

if name:
Expand Down Expand Up @@ -665,7 +665,7 @@ def generate_last_call_text(request, doc):
e.doc = doc
e.rev = doc.rev
e.desc = 'Last call announcement was generated'
e.text = force_text(new_text)
e.text = force_str(new_text)
e.save()

return e
Expand Down
4 changes: 2 additions & 2 deletions ietf/group/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.core.management import load_command_class
from django.http import Http404
from django.shortcuts import render
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.html import escape
from django.utils.translation import ugettext as _

Expand Down Expand Up @@ -152,7 +152,7 @@ def send_one_reminder(self, request, object_id):
permission_denied(request, "You don't have edit permissions for this change.")

if obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(opts.verbose_name), 'key': escape(object_id)})
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_str(opts.verbose_name), 'key': escape(object_id)})

return self.send_reminder(request, sdo=obj)

Expand Down
23 changes: 21 additions & 2 deletions ietf/group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,27 @@ def active_groups(request, group_type=None):
raise Http404

def active_group_types(request):
grouptypes = GroupTypeName.objects.filter(slug__in=['wg','rg','ag','rag','team','dir','review','area','program','iabasg','adm']).filter(group__state='active').annotate(group_count=Count('group'))
return render(request, 'group/active_groups.html', {'grouptypes':grouptypes})
grouptypes = (
GroupTypeName.objects.filter(
slug__in=[
"wg",
"rg",
"ag",
"rag",
"team",
"dir",
"review",
"area",
"program",
"iabasg",
"adm",
]
)
.filter(group__state="active")
.order_by('order', 'name') # default ordering ignored for "GROUP BY" queries, make it explicit
.annotate(group_count=Count("group"))
)
return render(request, "group/active_groups.html", {"grouptypes": grouptypes})

def active_dirs(request):
dirs = Group.objects.filter(type__in=['dir', 'review'], state="active").order_by("name")
Expand Down
5 changes: 2 additions & 3 deletions ietf/ietfauth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import oidc_provider.lib.claims


from functools import wraps
from functools import wraps, WRAPPER_ASSIGNMENTS

from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.decorators import available_attrs
from django.utils.http import urlquote

import debug # pyflakes:ignore
Expand Down Expand Up @@ -113,7 +112,7 @@ def passes_test_decorator(test_func, message):
error. The test function should be on the form fn(user) ->
true/false."""
def decorate(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
@wraps(view_func, assigned=WRAPPER_ASSIGNMENTS)
def inner(request, *args, **kwargs):
if not request.user.is_authenticated:
return HttpResponseRedirect('%s?%s=%s' % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path())))
Expand Down
4 changes: 2 additions & 2 deletions ietf/ipr/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.feedgenerator import Atom1Feed
from django.urls import reverse_lazy
from django.utils.safestring import mark_safe
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from ietf.ipr.models import IprDisclosureBase

Expand All @@ -25,7 +25,7 @@ def item_title(self, item):
return mark_safe(item.title)

def item_description(self, item):
return force_text(item.title)
return force_str(item.title)

def item_pubdate(self, item):
return item.time
Expand Down
4 changes: 2 additions & 2 deletions ietf/ipr/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from email.utils import parsedate_tz

from django.template.loader import render_to_string
from django.utils.encoding import force_text, force_bytes
from django.utils.encoding import force_str, force_bytes

import debug # pyflakes:ignore

Expand Down Expand Up @@ -102,7 +102,7 @@ def get_reply_to():
address with "plus addressing" using a random string. Guaranteed to be unique"""
local,domain = get_base_ipr_request_address().split('@')
while True:
rand = force_text(base64.urlsafe_b64encode(os.urandom(12)))
rand = force_str(base64.urlsafe_b64encode(os.urandom(12)))
address = "{}+{}@{}".format(local,rand,domain)
q = Message.objects.filter(reply_to=address)
if not q:
Expand Down
Loading