Commit 32550bcf authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Add time fields to Contact and Notification models

Too many users are complaining about not receiving phone or email
alerts. I need to know when the relevant contacts and notifications
were created, updated, verified, etc. so I can confirm or deny that
they had configured things correctly.
parent 1bb31103
Pipeline #60280 passed with stages
in 10 minutes and 9 seconds
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-05-03 17:31
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
def set_verified_time_default(apps, schema_editor):
Contact = apps.get_model('alerts', 'Contact')
# Data migration to set verified_time for all contacts
# which are already verified
for c in Contact.objects.filter(verified=True).iterator():
c.verified_time = c.updated
c.save(update_fields=['verified_time'])
class Migration(migrations.Migration):
dependencies = [
('alerts', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='contact',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='contact',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='contact',
name='verified_time',
field=models.DateTimeField(blank=True, editable=False, null=True),
),
migrations.RunPython(
set_verified_time_default,
migrations.RunPython.noop
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-05-03 17:59
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('alerts', '0002_add_created_updated_verified_time_fields_to_contact'),
]
operations = [
migrations.AddField(
model_name='notification',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='notification',
name='updated',
field=models.DateTimeField(auto_now=True),
),
]
......@@ -50,6 +50,10 @@ class Contact(CleanSaveModel):
verified = models.BooleanField(default=False, editable=False)
verification_code = models.IntegerField(null=True, editable=False)
verification_expiration = models.DateTimeField(null=True, editable=False)
# Fields for tracking when certain things happen
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
verified_time = models.DateTimeField(null=True, blank=True, editable=False)
def __str__(self):
......@@ -129,8 +133,10 @@ class Contact(CleanSaveModel):
body=msg)
def verify(self):
self.verified = True
self.save(update_fields=['verified'])
if not self.verified:
self.verified = True
self.verified_time = timezone.now()
self.save(update_fields=['verified', 'verified_time'])
def display(self):
if self.email:
......@@ -149,10 +155,13 @@ class Contact(CleanSaveModel):
Contact "{description}" (user {username})
E-mail: {email}
Phone: {phone} (method={method})
Verified: {verified}
Created: {created_time}
Last updated: {updated_time}
Verified: {verified} ({verified_time})
""").format(description=self.description, username=self.user.username,
email=self.email, phone=self.phone, method=self.phone_method,
verified=self.verified)
created_time=self.created, updated_time=self.updated,
verified=self.verified, verified_time=self.verified_time)
print(info_str)
......@@ -176,6 +185,9 @@ class Notification(models.Model):
category = models.CharField(max_length=1, null=False, blank=False,
choices=NOTIFICATION_CATEGORY_CHOICES,
default=NOTIFICATION_CATEGORY_SUPEREVENT)
# Fields for tracking when certain things happen
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
# Whether the event possibly has a neutron star in it.
# The logic for determining this is defined in a method below.
ns_candidate = models.BooleanField(default=False)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment