Skip to content

Commit

Permalink
Don't use pytz anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner authored and renovate[bot] committed Nov 4, 2024
1 parent 48671ba commit 06c71d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions admin/c2cgeoportal_admin/views/logged_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import datetime
from typing import Generic, TypeVar

import pytz
from c2cgeoform.views.abstract_views import AbstractViews, DeleteResponse, SaveResponse
from pyramid.httpexceptions import HTTPFound

Expand Down Expand Up @@ -73,7 +72,7 @@ def _create_log(
assert self._name_field is not None
assert self._id_field is not None
log = self._log_model(
date=datetime.datetime.now(pytz.utc),
date=datetime.datetime.now(datetime.timezone.utc),
action=action,
element_type=self._model.__tablename__,
element_id=getattr(obj, self._id_field),
Expand Down
7 changes: 3 additions & 4 deletions admin/tests/test_logs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# pylint: disable=no-self-use,unsubscriptable-object

import datetime
from datetime import timezone

import pytest
import pytz
from pyramid.testing import DummyRequest

from . import AbstractViewsTests

Expand All @@ -22,7 +21,7 @@ def logs_test_data(dbsession, transact):
logs = []
for i in range(0, 5):
log = MainLog(
date=datetime.datetime.now(pytz.utc),
date=datetime.datetime.now(timezone.utc),
action=[LogAction.INSERT, LogAction.UPDATE, LogAction.DELETE][i % 3],
element_type="role",
element_id=i,
Expand All @@ -34,7 +33,7 @@ def logs_test_data(dbsession, transact):
logs.append(log)

log = StaticLog(
date=datetime.datetime.now(pytz.utc),
date=datetime.datetime.now(timezone.utc),
action=[LogAction.INSERT, LogAction.UPDATE, LogAction.DELETE][i % 3],
element_type="user",
element_id=i,
Expand Down
7 changes: 3 additions & 4 deletions commons/c2cgeoportal_commons/models/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
import crypt
import logging
import os
from datetime import datetime
from datetime import datetime, timezone
from hashlib import sha1
from hmac import compare_digest as compare_hash
from typing import Any

import pytz
import sqlalchemy.schema
from c2c.template.config import config
from sqlalchemy import Column, ForeignKey, Table
Expand Down Expand Up @@ -362,10 +361,10 @@ def validate_password(self, passwd: str) -> bool:
return False

def expired(self) -> bool:
return self.expire_on is not None and self.expire_on < datetime.now(pytz.utc)
return self.expire_on is not None and self.expire_on < datetime.now(timezone.utc)

def update_last_login(self) -> None:
self.last_login = datetime.now(pytz.utc)
self.last_login = datetime.now(timezone.utc)

def __str__(self) -> str:
return self.username or ""
Expand Down

0 comments on commit 06c71d2

Please sign in to comment.