Skip to content

Commit

Permalink
Merge pull request #2752 from phillxnet/2750-Update-Django-to-latest-…
Browse files Browse the repository at this point in the history
…4.2-LTS

Update Django to latest 4.2 LTS #2750
  • Loading branch information
phillxnet authored Nov 20, 2023
2 parents e7edab7 + 04f1377 commit 84a0573
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 51 deletions.
30 changes: 21 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ generate-setup-file = false
python = "~3.9"

# [tool.poetry.group.django.dependencies]
django = "~3.2"
django = "~4.2"
django-oauth-toolkit = "*"
djangorestframework = "*"
django-pipeline = "*"
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/scripts/scheduled_tasks/reboot_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
"""
import sys
import json
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from scripts.scheduled_tasks import crontabwindow
from smart_manager.models import Task, TaskDefinition
from cli.api_wrapper import APIWrapper
from django.utils.timezone import utc
from system.osi import is_network_device_responding
from csv import reader as csv_reader
import re
Expand Down Expand Up @@ -112,7 +111,7 @@ def main():
)
return

now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=utc)
now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=timezone.utc)
schedule = now + timedelta(minutes=3)
t = Task(task_def=tdo, state="scheduled", start=now, end=schedule)

Expand Down
13 changes: 8 additions & 5 deletions src/rockstor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
# As from Django 5.0, the default is True.
USE_TZ = True

# Absolute path to the directory static files should be collected to.
Expand Down Expand Up @@ -103,6 +100,7 @@
DEFAULT_CB_DIR = os.path.join(MEDIA_ROOT, "config-backups")

# Additional locations of static files
# See build.sh for `tar zxvf` into "jslibs" dir of GitHub rockstor-jslibs release.
STATICFILES_DIRS = (os.path.join(BASE_DIR, "jslibs"),)

# List of finder classes that know how to find static files in
Expand Down Expand Up @@ -190,7 +188,12 @@
"huey.contrib.djhuey",
)

STATICFILES_STORAGE = "pipeline.storage.PipelineManifestStorage"
# STATICFILES_STORAGE = "pipeline.storage.PipelineManifestStorage"
STORAGES = {
"staticfiles": {
"BACKEND": "pipeline.storage.PipelineManifestStorage",
},
}

# Have django-pipeline collate storageadmin js/jst files into one storageadmin.js file
# which is then referenced in setup.html and base.html templates.
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/smart_manager/agents/nfsd_calls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, timezone
from smart_manager.models import (
NFSDCallDistribution,
NFSDClientDistribution,
Expand All @@ -7,11 +7,10 @@
SProbe,
NFSDUidGidDistribution,
)
from django.utils.timezone import utc


def get_datetime(ts):
return datetime.datetime.utcfromtimestamp(float(ts)).replace(tzinfo=utc)
return datetime.datetime.utcfromtimestamp(float(ts)).replace(tzinfo=timezone.utc)


def process_nfsd_calls(output, rid, l):
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/smart_manager/views/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from rest_framework.response import Response
from system.services import service_status
from django.db import transaction
from django.utils.timezone import utc
from datetime import datetime
from datetime import datetime, timezone
import logging

logger = logging.getLogger(__name__)
Expand All @@ -43,7 +42,7 @@ def _get_config(self, service):
return json.loads(service.config)

def _get_or_create_sso(self, service):
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
so = None
if ServiceStatus.objects.filter(service=service).exists():
so = ServiceStatus.objects.filter(service=service).order_by("-ts")[0]
Expand Down
11 changes: 5 additions & 6 deletions src/rockstor/smart_manager/views/receive_trail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
"""

from django.db import transaction
from django.utils.timezone import utc
from django.conf import settings
from rest_framework.response import Response
from smart_manager.models import ReplicaShare, ReceiveTrail
from smart_manager.serializers import ReceiveTrailSerializer
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import rest_framework_custom as rfc


Expand All @@ -39,7 +38,7 @@ def get_queryset(self, *args, **kwargs):
def post(self, request, rid):
with self._handle_exception(request):
rs = ReplicaShare.objects.get(id=rid)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
snap_name = request.data.get("snap_name")
rt = ReceiveTrail(
rshare=rs, snap_name=snap_name, status="pending", receive_pending=ts
Expand All @@ -52,7 +51,7 @@ def delete(self, request, rid):
with self._handle_exception(request):
days = int(request.data.get("days", 30))
rs = ReplicaShare.objects.get(id=rid)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
ts0 = ts - timedelta(days=days)
if ReceiveTrail.objects.filter(rshare=rs).count() > 100:
ReceiveTrail.objects.filter(rshare=rs, end_ts__lt=ts0).delete()
Expand All @@ -73,14 +72,14 @@ def get(self, request, *args, **kwargs):
def _convert_datestr(request, attr, default):
val = request.data.get(attr, None)
if val is not None:
return datetime.strptime(val, settings.SNAP_TS_FORMAT).replace(tzinfo=utc)
return datetime.strptime(val, settings.SNAP_TS_FORMAT).replace(tzinfo=timezone.utc)
return default

@transaction.atomic
def put(self, request, rtid):
with self._handle_exception(request):
rt = ReceiveTrail.objects.get(id=rtid)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
if "receive_succeeded" in request.data:
rt.receive_succeeded = ts
rt.status = request.data.get("status", rt.status)
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/smart_manager/views/replica_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from smart_manager.models import ReplicaShare, ReceiveTrail
from smart_manager.serializers import ReplicaShareSerializer
from storageadmin.util import handle_exception
from datetime import datetime
from django.utils.timezone import utc
from datetime import datetime, timezone
import rest_framework_custom as rfc


Expand All @@ -46,7 +45,7 @@ def post(self, request):
aip = request.data["appliance"]
self._validate_appliance(aip, request)
src_share = request.data["src_share"]
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
r = ReplicaShare(
share=sname, appliance=aip, pool=share.pool.name, src_share=src_share, ts=ts
)
Expand Down
9 changes: 4 additions & 5 deletions src/rockstor/smart_manager/views/replica_trail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
"""

from django.db import transaction
from django.utils.timezone import utc
from rest_framework.response import Response
from smart_manager.models import Replica, ReplicaTrail
from smart_manager.serializers import ReplicaTrailSerializer
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import rest_framework_custom as rfc


Expand All @@ -44,7 +43,7 @@ def post(self, request, rid):
with self._handle_exception(request):
replica = Replica.objects.get(id=rid)
snap_name = request.data["snap_name"]
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
rt = ReplicaTrail(
replica=replica,
snap_name=snap_name,
Expand All @@ -59,7 +58,7 @@ def delete(self, request, rid):
with self._handle_exception(request):
days = int(request.data.get("days", 30))
replica = Replica.objects.get(id=rid)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
ts0 = ts - timedelta(days=days)
if ReplicaTrail.objects.filter(replica=replica).count() > 100:
ReplicaTrail.objects.filter(replica=replica, end_ts__lt=ts0).delete()
Expand Down Expand Up @@ -88,7 +87,7 @@ def put(self, request, rtid):
if "kb_sent" in request.data:
rt.kb_sent = request.data["kb_sent"]
if rt.status in ("failed", "succeeded",):
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
rt.end_ts = ts
if rt.status == "failed":
rt.send_failed = ts
Expand Down
7 changes: 3 additions & 4 deletions src/rockstor/smart_manager/views/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from smart_manager.models import Replica, ReplicaTrail
from smart_manager.serializers import ReplicaSerializer
from storageadmin.util import handle_exception
from datetime import datetime
from django.utils.timezone import utc
from datetime import datetime, timezone
from django.conf import settings
import rest_framework_custom as rfc
import logging
Expand Down Expand Up @@ -111,7 +110,7 @@ def post(self, request):
replication_ip = request.data.get("listener_ip", None)
if replication_ip is not None and len(replication_ip.strip()) == 0:
replication_ip = None
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
r = Replica(
task_name=task_name,
share=sname,
Expand Down Expand Up @@ -177,7 +176,7 @@ def put(self, request, rid):
r.data_port = self._validate_port(
request.data.get("listener_port", r.data_port), request
)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
r.ts = ts
r.save()
self._refresh_crontab()
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/storageadmin/views/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
AdvancedNFSExport,
)
from storageadmin.util import handle_exception
from datetime import datetime
from django.utils.timezone import utc
from datetime import datetime, timezone
from django.conf import settings
from django.db import transaction
from storageadmin.views.share_helpers import sftp_snap_toggle, import_shares, import_snapshots
Expand Down Expand Up @@ -236,7 +235,7 @@ def post(self, request, command, rtcepoch=None):
return Response()

if command == "utcnow":
return Response(datetime.utcnow().replace(tzinfo=utc))
return Response(datetime.utcnow().replace(tzinfo=timezone.utc))

if command == "uptime":
return Response(uptime())
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/storageadmin/views/disk_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
test_logs,
run_test,
)
from datetime import datetime
from django.utils.timezone import utc
from datetime import datetime, timezone

import logging

Expand Down Expand Up @@ -77,7 +76,7 @@ def _info(disk):
e_summary, e_lines = error_logs(disk.name, disk.smart_options)
smartid = info(disk.name, disk.smart_options)
test_d, log_lines = test_logs(disk.name, disk.smart_options)
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
si = SMARTInfo(disk=disk, toc=ts)
si.save()
for k in sorted(attributes.keys(), reverse=True):
Expand Down
5 changes: 2 additions & 3 deletions src/rockstor/storageadmin/views/share_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import re
from datetime import datetime
from django.utils.timezone import utc
from datetime import datetime, timezone
from django.conf import settings
from storageadmin.models import Share, Snapshot, SFTP
from smart_manager.models import ShareUsage
Expand Down Expand Up @@ -285,7 +284,7 @@ def update_shareusage_db(subvol_name, rusage, eusage, new_entry=True):
:param new_entry: If True create a new entry with the passed params,
otherwise attempt to update the latest (by id) entry with time and count.
"""
ts = datetime.utcnow().replace(tzinfo=utc)
ts = datetime.utcnow().replace(tzinfo=timezone.utc)
if new_entry:
su = ShareUsage(name=subvol_name, r_usage=rusage, e_usage=eusage, ts=ts)
su.save()
Expand Down

0 comments on commit 84a0573

Please sign in to comment.