Skip to content

Commit

Permalink
Replace datetime with timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Oct 23, 2023
1 parent 1533aff commit 9b1b1de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lemarche/siaes/management/commands/sync_c1_c4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import re
from datetime import datetime, timedelta
from datetime import timedelta

import psycopg2
import psycopg2.extras
Expand Down Expand Up @@ -360,8 +360,8 @@ def c4_delist_old_siae(self, dry_run):
- all the ones who have is_active as False
"""
if not dry_run:
date_yesterday = datetime.now() - timedelta(days=1)
Siae.objects.exclude(c1_sync_skip=True).filter(
c1_last_sync_date__lt=timezone.make_aware(date_yesterday)
).update(is_delisted=True)
date_yesterday = timezone.now() - timedelta(days=1)
Siae.objects.exclude(c1_sync_skip=True).filter(c1_last_sync_date__lt=date_yesterday).update(
is_delisted=True
)
Siae.objects.filter(is_active=False).update(is_delisted=True)
6 changes: 3 additions & 3 deletions lemarche/siaes/management/commands/sync_c2_c4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timedelta
from datetime import timedelta

import psycopg2
import psycopg2.extras
Expand Down Expand Up @@ -64,10 +64,10 @@ def handle(self, dry_run=False, **options):

# count after
siae_etp_count_after = Siae.objects.filter(c2_etp_count__isnull=False).count()
date_yesterday = datetime.now() - timedelta(days=1)
date_yesterday = timezone.now() - timedelta(days=1)
siae_etp_updated = (
Siae.objects.filter(c2_etp_count__isnull=False)
.filter(c2_etp_count_last_sync_date__gte=timezone.make_aware(date_yesterday))
.filter(c2_etp_count_last_sync_date__gte=date_yesterday)
.count()
)

Expand Down
5 changes: 3 additions & 2 deletions lemarche/stats/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from datetime import timedelta

from django.db import models
from django.utils import timezone

from lemarche.siaes import constants as siae_constants
from lemarche.utils import constants
Expand All @@ -17,7 +18,7 @@ def siae_views_last_3_months(self, siae_slug):
return self.env_prod().filter(
action="load",
page=f"/prestataires/{siae_slug}/",
date_created__gte=datetime.now() - timedelta(days=90),
date_created__gte=timezone.now() - timedelta(days=90),
)

def siae_buyer_views_last_3_months(self, siae_slug):
Expand Down

0 comments on commit 9b1b1de

Please sign in to comment.