feat: add Django web app, CloudKit sync, dashboard, and game_datetime_utc export
Adds the full Django application layer on top of sportstime_parser: - core: Sport, Team, Stadium, Game models with aliases and league structure - scraper: orchestration engine, adapter, job management, Celery tasks - cloudkit: CloudKit sync client, sync state tracking, sync jobs - dashboard: staff dashboard for monitoring scrapers, sync, review queue - notifications: email reports for scrape/sync results - Docker setup for deployment (Dockerfile, docker-compose, entrypoint) Game exports now use game_datetime_utc (ISO 8601 UTC) instead of venue-local date+time strings, matching the canonical format used by the iOS app. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
131
notifications/models.py
Normal file
131
notifications/models.py
Normal file
@@ -0,0 +1,131 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
|
||||
class EmailConfiguration(models.Model):
|
||||
"""
|
||||
Email notification configuration.
|
||||
"""
|
||||
name = models.CharField(
|
||||
max_length=100,
|
||||
default='Default',
|
||||
help_text='Configuration name'
|
||||
)
|
||||
is_enabled = models.BooleanField(
|
||||
default=True,
|
||||
help_text='Whether email notifications are enabled'
|
||||
)
|
||||
|
||||
# Recipients
|
||||
recipient_emails = models.TextField(
|
||||
help_text='Comma-separated list of recipient email addresses'
|
||||
)
|
||||
|
||||
# What to notify about
|
||||
notify_on_scrape_complete = models.BooleanField(
|
||||
default=True,
|
||||
help_text='Send email after each scraper job completes'
|
||||
)
|
||||
notify_on_scrape_failure = models.BooleanField(
|
||||
default=True,
|
||||
help_text='Send email when scraper job fails'
|
||||
)
|
||||
notify_on_sync_complete = models.BooleanField(
|
||||
default=False,
|
||||
help_text='Send email after CloudKit sync completes'
|
||||
)
|
||||
notify_on_sync_failure = models.BooleanField(
|
||||
default=True,
|
||||
help_text='Send email when CloudKit sync fails'
|
||||
)
|
||||
notify_on_new_reviews = models.BooleanField(
|
||||
default=True,
|
||||
help_text='Include review items in scrape notifications'
|
||||
)
|
||||
|
||||
# Thresholds
|
||||
min_games_for_notification = models.PositiveIntegerField(
|
||||
default=0,
|
||||
help_text='Minimum games changed to trigger notification (0 = always)'
|
||||
)
|
||||
|
||||
# Metadata
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
# Audit trail
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Email Configuration'
|
||||
verbose_name_plural = 'Email Configurations'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_recipients(self):
|
||||
"""Return list of recipient emails."""
|
||||
return [
|
||||
email.strip()
|
||||
for email in self.recipient_emails.split(',')
|
||||
if email.strip()
|
||||
]
|
||||
|
||||
|
||||
class EmailLog(models.Model):
|
||||
"""
|
||||
Log of sent email notifications.
|
||||
"""
|
||||
STATUS_CHOICES = [
|
||||
('sent', 'Sent'),
|
||||
('failed', 'Failed'),
|
||||
]
|
||||
|
||||
configuration = models.ForeignKey(
|
||||
EmailConfiguration,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='logs'
|
||||
)
|
||||
subject = models.CharField(max_length=255)
|
||||
recipients = models.TextField(
|
||||
help_text='Comma-separated list of recipients'
|
||||
)
|
||||
body_preview = models.TextField(
|
||||
blank=True,
|
||||
help_text='First 500 chars of email body'
|
||||
)
|
||||
status = models.CharField(
|
||||
max_length=10,
|
||||
choices=STATUS_CHOICES
|
||||
)
|
||||
error_message = models.TextField(blank=True)
|
||||
|
||||
# Related objects
|
||||
scrape_job = models.ForeignKey(
|
||||
'scraper.ScrapeJob',
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='email_logs'
|
||||
)
|
||||
sync_job = models.ForeignKey(
|
||||
'cloudkit.CloudKitSyncJob',
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='email_logs'
|
||||
)
|
||||
|
||||
# Metadata
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
verbose_name = 'Email Log'
|
||||
verbose_name_plural = 'Email Logs'
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.subject} ({self.status})"
|
||||
Reference in New Issue
Block a user