diff --git a/website/migrations/0125_activitylog_timelog.py b/website/migrations/0125_activitylog_timelog.py new file mode 100644 index 000000000..85e9771bf --- /dev/null +++ b/website/migrations/0125_activitylog_timelog.py @@ -0,0 +1,75 @@ +# Generated by Django 5.0.7 on 2024-08-09 19:52 + +import django.db.models.deletion +import django.utils.timezone +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("website", "0124_company_tags_domain_tags_project_tags_and_more"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="ActivityLog", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("window_title", models.CharField(max_length=255)), + ("url", models.URLField(blank=True, null=True)), + ("recorded_at", models.DateTimeField(auto_now_add=True)), + ( + "created", + models.DateTimeField(default=django.utils.timezone.now, editable=False), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="activity_logs", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.CreateModel( + name="TimeLog", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("start_time", models.DateTimeField()), + ("end_time", models.DateTimeField(blank=True, null=True)), + ("duration", models.DurationField(blank=True, null=True)), + ("github_issue_url", models.URLField(blank=True, null=True)), + ( + "created", + models.DateTimeField(default=django.utils.timezone.now, editable=False), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="timelogs", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/website/models.py b/website/models.py index 20b998ba5..1911c51de 100644 --- a/website/models.py +++ b/website/models.py @@ -786,3 +786,35 @@ class BaconToken(models.Model): def __str__(self): return f"{self.user.username} - {self.amount} BACON" + + +class TimeLog(models.Model): + user = models.ForeignKey( + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="timelogs" + ) + start_time = models.DateTimeField() + end_time = models.DateTimeField(null=True, blank=True) + duration = models.DurationField(null=True, blank=True) + github_issue_url = models.URLField(null=True, blank=True) # URL field for GitHub issue + created = models.DateTimeField(default=timezone.now, editable=False) + + def save(self, *args, **kwargs): + if self.end_time and self.start_time <= self.end_time: + self.duration = self.end_time - self.start_time + super().save(*args, **kwargs) + + def __str__(self): + return f"TimeLog by {self.user.username} from {self.start_time} to {self.end_time}" + + +class ActivityLog(models.Model): + user = models.ForeignKey( + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="activity_logs" + ) + window_title = models.CharField(max_length=255) + url = models.URLField(null=True, blank=True) # URL field for activity-related URL + recorded_at = models.DateTimeField(auto_now_add=True) + created = models.DateTimeField(default=timezone.now, editable=False) + + def __str__(self): + return f"ActivityLog by {self.user.username} at {self.recorded_at}"