Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 15 additions & 5 deletions django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,32 @@
return;
}

const serverTimezone =
document.body.dataset.adminServerTimezone || gettext("server");
let message;
if (timezoneOffset > 0) {
message = ngettext(
"Note: You are %s hour ahead of server time.",
"Note: You are %s hours ahead of server time.",
"Note: Enter times in the %(timezone)s timezone. " +
"(You are %(offset)s hour ahead.)",
"Note: Enter times in the %(timezone)s timezone. " +
"(You are %(offset)s hours ahead.)",
timezoneOffset,
);
} else {
timezoneOffset *= -1;
message = ngettext(
"Note: You are %s hour behind server time.",
"Note: You are %s hours behind server time.",
"Note: Enter times in the %(timezone)s timezone. " +
"(You are %(offset)s hour behind.)",
"Note: Enter times in the %(timezone)s timezone. " +
"(You are %(offset)s hours behind.)",
timezoneOffset,
);
}
message = interpolate(message, [timezoneOffset]);
message = interpolate(
message,
{ timezone: serverTimezone, offset: timezoneOffset },
true,
);

const warning = document.createElement("div");
const id = inp.id;
Expand Down
5 changes: 3 additions & 2 deletions django/contrib/admin/templates/admin/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n static %}<!DOCTYPE html>
{% load i18n static tz %}<!DOCTYPE html>
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:'rtl,ltr,auto' }}">
<head>
Expand All @@ -25,7 +25,8 @@
</head>

<body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}"
data-admin-utc-offset="{% now "Z" %}">
data-admin-utc-offset="{% now "Z" %}"
data-admin-server-timezone="{% get_current_timezone as time_zone %}{{ time_zone }}">
<a href="#content-start" class="skip-to-content-link">{% translate 'Skip to main content' %}</a>
<!-- Container -->
<div id="container">
Expand Down
2 changes: 1 addition & 1 deletion django/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def django_file_prefixes():
file = getattr(django, "__file__", None)
if file is None:
return ()
return (os.path.dirname(file),)
return (os.path.join(os.path.dirname(file), ""),)


class RemovedInNextVersionWarning(DeprecationWarning):
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/6.0.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Bugfixes
``django/contrib/admin/templates/admin/change_list.html`` template added in
Django 6.0 that could be problematic when overriding the ``pagination`` block
(:ticket:`37029`).

* Fixed a bug in Django 6.0 where deprecation warnings incorrectly skipped
lines from third-party packages prefixed with "django" (:ticket:`37067`).
18 changes: 16 additions & 2 deletions js_tests/admin/DateTimeShortcuts.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/* global QUnit, DateTimeShortcuts */
"use strict";

QUnit.module("admin.DateTimeShortcuts");
QUnit.module("admin.DateTimeShortcuts", {
afterEach: function () {
const $ = django.jQuery;
$("body")
.removeAttr("data-admin-server-timezone")
.removeAttr("data-admin-utc-offset");
$(".timezonewarning").remove();
},
});

QUnit.test("init", function (assert) {
const $ = django.jQuery;
Expand Down Expand Up @@ -46,11 +54,13 @@ QUnit.test("time zone offset warning - single field", function (assert) {
"data-admin-utc-offset",
new Date().getTimezoneOffset() * -60 + 3600,
);
$("body").attr("data-admin-server-timezone", "America/Chicago");
DateTimeShortcuts.init();
$("body").attr("data-admin-utc-offset", savedOffset);
assert.equal(
$(".timezonewarning").text(),
"Note: You are 1 hour behind server time.",
"Note: Enter times in the America/Chicago timezone. " +
"(You are 1 hour behind.)",
);
assert.equal(
$(".timezonewarning").attr("id"),
Expand All @@ -74,6 +84,10 @@ QUnit.test("time zone offset warning - date and time field", function (assert) {
);
DateTimeShortcuts.init();
$("body").attr("data-admin-utc-offset", savedOffset);
assert.equal(
$(".timezonewarning").text(),
"Note: Enter times in the server timezone. (You are 1 hour behind.)",
);
assert.equal(
$(".timezonewarning").attr("id"),
"id_updated_at_timezone_warning_helptext",
Expand Down
7 changes: 6 additions & 1 deletion tests/deprecation/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import warnings
from pathlib import Path

import django
from django.test import SimpleTestCase
Expand Down Expand Up @@ -31,7 +32,11 @@ def test_with_file(self):
prefixes = django_file_prefixes()
self.assertIsInstance(prefixes, tuple)
self.assertEqual(len(prefixes), 1)
self.assertTrue(prefixes[0].endswith(f"{os.path.sep}django"))
self.assertTrue(prefixes[0].endswith(f"{os.path.sep}django{os.path.sep}"))

def test_does_not_match_packages_prefixed_with_django(self):
other_file = Path(django.__file__).parent.parent / "djangoextra" / "__init__.py"
self.assertFalse(str(other_file).startswith(django_file_prefixes()))


class RenameManagerMethods(RenameMethodsBase):
Expand Down
Loading