Skip to content

Commit

Permalink
Merge pull request #179 from nyaruka/django5
Browse files Browse the repository at this point in the history
Django5
  • Loading branch information
rowanseymour authored Dec 6, 2023
2 parents 115f821 + fff6b83 commit f311c1c
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
matrix:
python-version: ["3.10.x", "3.11.x"]
pg-version: ["14", "15"]
django-version: ["4.1.x", "4.2.x"]
django-version: ["4.1.x", "4.2.x", "5.0.x"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
137 changes: 63 additions & 74 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ repository = "https://github.com/nyaruka/smartmin"

[tool.poetry.dependencies]
python = "^3.10"
Django = ">= 4.0, < 5.0"
Django = ">= 4.0, < 5.1"
celery = ">= 5.1"
pytz = "*"
redis = ">= 3.5.3"
sqlparse = "^0.4.1"
xlrd = "^1.2.0"
Expand Down
14 changes: 7 additions & 7 deletions smartmin/csv_imports/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def test_csv_import(self):
pass

def test_generate_file_path(self):
self.assertEquals(generate_file_path(ImportTask(), "allo.csv"), "csv_imports/allo.csv")
self.assertEquals(generate_file_path(ImportTask(), "allo.xlsx"), "csv_imports/allo.xlsx")
self.assertEquals(generate_file_path(ImportTask(), "allo.foo.bar"), "csv_imports/allo.foo.bar")
self.assertEqual(generate_file_path(ImportTask(), "allo.csv"), "csv_imports/allo.csv")
self.assertEqual(generate_file_path(ImportTask(), "allo.xlsx"), "csv_imports/allo.xlsx")
self.assertEqual(generate_file_path(ImportTask(), "allo.foo.bar"), "csv_imports/allo.foo.bar")

long_name = "foo" * 100

test_file_name = "%s.xls.csv" % long_name
self.assertEquals(len(generate_file_path(ImportTask(), test_file_name)), 100)
self.assertEquals(generate_file_path(ImportTask(), test_file_name), "csv_imports/%s.csv" % long_name[:84])
self.assertEqual(len(generate_file_path(ImportTask(), test_file_name)), 100)
self.assertEqual(generate_file_path(ImportTask(), test_file_name), "csv_imports/%s.csv" % long_name[:84])

test_file_name = "%s.abc.xlsx" % long_name
self.assertEquals(len(generate_file_path(ImportTask(), test_file_name)), 100)
self.assertEquals(generate_file_path(ImportTask(), test_file_name), "csv_imports/%s.xlsx" % long_name[:83])
self.assertEqual(len(generate_file_path(ImportTask(), test_file_name)), 100)
self.assertEqual(generate_file_path(ImportTask(), test_file_name), "csv_imports/%s.xlsx" % long_name[:83])
6 changes: 2 additions & 4 deletions smartmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import traceback
import zoneinfo
from datetime import datetime
from datetime import datetime, timezone as tzone

from xlrd import XL_CELL_DATE, XLRDError, open_workbook, xldate_as_tuple

Expand Down Expand Up @@ -220,9 +220,7 @@ def import_xls(cls, filename, user, import_params, log=None, import_results=None
# timezone for date cells can be specified as an import parameter or defaults to UTC
# use now to determine a relevant timezone
naive_timezone = (
zoneinfo.ZoneInfo(import_params["timezone"])
if import_params and "timezone" in import_params
else timezone.utc
zoneinfo.ZoneInfo(import_params["timezone"]) if import_params and "timezone" in import_params else tzone.utc
)
tz = timezone.now().astimezone(naive_timezone).tzinfo

Expand Down
8 changes: 4 additions & 4 deletions smartmin/templatetags/smartmin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import re
import zoneinfo
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone as tzone

from django import template
from django.conf import settings
Expand Down Expand Up @@ -34,7 +34,7 @@ def format_datetime(time):
"""
user_time_zone = timezone.get_current_timezone()
if time.tzinfo is None:
time = time.replace(tzinfo=timezone.utc)
time = time.replace(tzinfo=tzone.utc)
user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT"))

time = time.astimezone(user_time_zone)
Expand Down Expand Up @@ -164,7 +164,7 @@ def map(string, args):
@register.filter
def gmail_time(dtime, now=None):
if dtime.tzinfo is None:
dtime = dtime.replace(tzinfo=timezone.utc)
dtime = dtime.replace(tzinfo=tzone.utc)
user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT"))
dtime = dtime.astimezone(user_time_zone)
else:
Expand All @@ -174,7 +174,7 @@ def gmail_time(dtime, now=None):
now = timezone.now()

if now.tzinfo is None:
now = now.replace(tzinfo=timezone.utc)
now = now.replace(tzinfo=tzone.utc)

twelve_hours_ago = now - timedelta(hours=12)

Expand Down
8 changes: 4 additions & 4 deletions smartmin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def fetch_protected(self, url, user, post_data=None, failOnFormValidation=True):
# but now we can!
if not post_data:
response = self.client.get(url)
self.assertEquals(200, response.status_code)
self.assertEqual(200, response.status_code)
else:
response = self.client.post(url, data=post_data)
self.assertNotRedirect(response, reverse("users.user_login"), msg="Unexpected redirect to login")

if failOnFormValidation:
self.assertNoFormErrors(response, post_data)
self.assertEquals(302, response.status_code)
self.assertEqual(302, response.status_code)

return response

Expand Down Expand Up @@ -162,7 +162,7 @@ def testDelete(self):
return
object = self.getTestObject()
self._do_test_view("delete", object, post_data=dict())
self.assertEquals(0, len(self.getManager().filter(pk=object.pk)))
self.assertEqual(0, len(self.getManager().filter(pk=object.pk)))

def testList(self):
if "list" not in self.getCRUDL().actions:
Expand Down Expand Up @@ -222,7 +222,7 @@ def _do_test_view(self, action=None, object=None, post_data=None, query_string=N
def assertPageGet(self, action, response):
if response.status_code == 302:
self.fail("'%s' resulted in an unexpected redirect to: %s" % (action, response.get("Location")))
self.assertEquals(
self.assertEqual(
200,
response.status_code,
)
Expand Down
Loading

0 comments on commit f311c1c

Please sign in to comment.