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

Support Django 5.0 #177

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ on: [push, pull_request]
jobs:
test:
name: Test
strategy:
matrix:
python-version: ["3.10.x", "3.11.x"]
pg-version: ["14", "15"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can drop PG14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped that

django-version: ["4.2.x", "5.0.x"]
env:
python-version: "3.10.x"
pg-version: "14"
redis-version: "6.2"
runs-on: ubuntu-latest
steps:
Expand All @@ -20,15 +23,15 @@ jobs:
- name: Install PostgreSQL
uses: harmon758/postgresql-action@v1
with:
postgresql version: ${{ env.pg-version }}
postgresql version: ${{ matrix.pg-version }}
postgresql db: dash
postgresql user: dash
postgresql password: rapidpro

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.python-version }}
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
Expand All @@ -38,6 +41,7 @@ jobs:
- name: Initialize environment
run: |
poetry install
poetry add django==${{ matrix.django-version }}

- name: Run pre-test checks
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.8 on 2023-12-05 16:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("dashblocks", "0011_alter_dashblock_index_together_and_more"),
]

operations = [
migrations.RenameIndex(
model_name="dashblock",
new_name="dashblocks__org_id_024805_idx",
old_fields=("org", "is_active", "dashblock_type", "priority"),
),
migrations.RenameIndex(
model_name="dashblocktype",
new_name="dashblocks__slug_c0c6c6_idx",
old_fields=("slug", "name"),
),
]
4 changes: 2 additions & 2 deletions dash/dashblocks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __str__(self):

class Meta:
ordering = ["name"]
index_together = ("slug", "name")
indexes = [models.Index(fields=["slug", "name"])]


class DashBlock(SmartModel):
Expand Down Expand Up @@ -149,7 +149,7 @@ def __str__(self):

class Meta:
ordering = ["dashblock_type", "title"]
index_together = ("org", "is_active", "dashblock_type", "priority")
indexes = [models.Index(fields=["org", "is_active", "dashblock_type", "priority"])]


class DashBlockImage(SmartModel):
Expand Down
5 changes: 3 additions & 2 deletions dash/orgs/management/commands/orgtasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import timezone as tzone

from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone

from dash.orgs.models import Org, TaskState

Expand Down Expand Up @@ -104,4 +105,4 @@ def cell(val, width):


def format_date(dt):
return dt.astimezone(timezone.utc).strftime("%b %d, %Y %H:%M") if dt else ""
return dt.astimezone(tzone.utc).strftime("%b %d, %Y %H:%M") if dt else ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.8 on 2023-12-05 16:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("orgs", "0031_alter_orgbackend_index_together"),
]

operations = [
migrations.RenameIndex(
model_name="orgbackend",
new_name="orgs_orgbac_org_id_607508_idx",
old_fields=("org", "is_active", "slug"),
),
]
2 changes: 1 addition & 1 deletion dash/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,4 @@ def __str__(self):

class Meta:
unique_together = ("org", "slug")
index_together = ("org", "is_active", "slug")
indexes = [models.Index(fields=["org", "is_active", "slug"])]
5 changes: 2 additions & 3 deletions dash/orgs/templatetags/dashorgs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime
from datetime import datetime, timezone as tzone

import phonenumbers

from django import template
from django.utils import timezone

register = template.Library()

Expand All @@ -14,7 +13,7 @@ def display_time(text_timestamp, org, time_format=None):
if not time_format:
time_format = "%b %d, %Y %H:%M"

parsed_time = datetime.strptime(text_timestamp, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
parsed_time = datetime.strptime(text_timestamp, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=tzone.utc)
output_time = parsed_time.astimezone(org.timezone)

return output_time.strftime(time_format)
Expand Down
6 changes: 3 additions & 3 deletions dash/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import calendar
import datetime
import json
import os
import random
from collections import OrderedDict
from datetime import datetime, timezone as tzone
from itertools import islice
from uuid import uuid4

Expand Down Expand Up @@ -101,8 +101,8 @@ def ms_to_datetime(ms):
"""
Converts a millisecond accuracy timestamp to a datetime
"""
dt = datetime.datetime.utcfromtimestamp(ms / 1000)
return dt.replace(microsecond=(ms % 1000) * 1000).replace(tzinfo=timezone.utc)
dt = datetime.utcfromtimestamp(ms / 1000)
return dt.replace(microsecond=(ms % 1000) * 1000).replace(tzinfo=tzone.utc)


def get_month_range(d=None):
Expand Down
9 changes: 4 additions & 5 deletions dash/utils/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
import zoneinfo
from datetime import datetime
from datetime import datetime, timezone as tzone
from itertools import chain

from django.core.cache import cache
from django.utils import timezone

from dash.test import DashTest

Expand Down Expand Up @@ -77,16 +76,16 @@ def calculate():
self.assertEqual(get_obj_cacheable(self, "_test_value", calculate, recalculate=True), "CALCULATED")

def test_datetime_to_ms(self):
d1 = datetime(2014, 1, 2, 3, 4, 5, 678900, tzinfo=timezone.utc)
d1 = datetime(2014, 1, 2, 3, 4, 5, 678900, tzinfo=tzone.utc)
self.assertEqual(datetime_to_ms(d1), 1388631845678) # from http://unixtimestamp.50x.eu

# conversion to millis loses some accuracy
self.assertEqual(ms_to_datetime(1388631845678), datetime(2014, 1, 2, 3, 4, 5, 678000, tzinfo=timezone.utc))
self.assertEqual(ms_to_datetime(1388631845678), datetime(2014, 1, 2, 3, 4, 5, 678000, tzinfo=tzone.utc))

tz = zoneinfo.ZoneInfo("Africa/Kigali")
d2 = datetime(2014, 1, 2, 3, 4, 5, 600000, tz)
self.assertEqual(datetime_to_ms(d2), 1388624645600)
self.assertEqual(ms_to_datetime(1388624645600), d2.astimezone(timezone.utc))
self.assertEqual(ms_to_datetime(1388624645600), d2.astimezone(tzone.utc))

def test_get_month_range(self):
self.assertEqual(
Expand Down
Loading