-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
200 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# One-shot command to migrate the new unseen observations to the new mechanism | ||
# (was hard to do in a data migration) | ||
|
||
import datetime | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db import IntegrityError | ||
from django.utils import timezone | ||
|
||
from dashboard.models import Observation, User, ObservationUnseen | ||
|
||
one_year_ago = (timezone.now() - datetime.timedelta(days=365)).date() | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
all_users = User.objects.all() | ||
|
||
for user in all_users: | ||
self.stdout.write( | ||
f"{str(datetime.datetime.now())} - Migrating data for user: " | ||
+ user.username | ||
) | ||
|
||
# We only migrate that for unseen observations, pertaining to user alers and that are less than a year old | ||
for alert in user.alert_set.all(): | ||
for obs in alert.observations(): | ||
if obs.date > one_year_ago: | ||
if not obs.observationview_set.filter(user=user).exists(): | ||
try: | ||
ObservationUnseen.objects.create( | ||
user=user, observation_id=obs.id | ||
) | ||
except IntegrityError: | ||
# The same user might have already seen the observation from another alert | ||
pass | ||
|
||
self.stdout.write("Done") |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ions/0020_user_notification_delay_days.py → ...ions/0019_user_notification_delay_days.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.