Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-11-09 16:31:34 -05:00
parent 2884bc23ce
commit eb68cf40c6
1080 changed files with 27361 additions and 56687 deletions

View File

@@ -0,0 +1,4 @@
"""
Timeline app for tracking entity lifecycle events.
"""
default_app_config = 'apps.timeline.apps.TimelineConfig'

View File

@@ -0,0 +1,33 @@
from django.contrib import admin
from unfold.admin import ModelAdmin
from .models import EntityTimelineEvent
@admin.register(EntityTimelineEvent)
class EntityTimelineEventAdmin(ModelAdmin):
list_display = ['title', 'entity_type', 'entity_id', 'event_type', 'event_date', 'is_public', 'created_by']
list_filter = ['entity_type', 'event_type', 'is_public', 'event_date', 'event_date_precision']
search_fields = ['title', 'description', 'entity_id']
date_hierarchy = 'event_date'
ordering = ['-event_date', '-created_at']
readonly_fields = ['created_at', 'updated_at']
fieldsets = (
('Event Information', {
'fields': ('title', 'description', 'event_type', 'event_date', 'event_date_precision')
}),
('Entity Reference', {
'fields': ('entity_type', 'entity_id')
}),
('Event Details', {
'fields': ('from_entity_id', 'to_entity_id', 'from_location', 'to_location', 'from_value', 'to_value'),
'classes': ('collapse',)
}),
('Visibility & Order', {
'fields': ('is_public', 'display_order')
}),
('Tracking', {
'fields': ('created_by', 'approved_by', 'submission', 'created_at', 'updated_at'),
'classes': ('collapse',)
}),
)

View File

@@ -0,0 +1,11 @@
"""
Timeline app configuration.
"""
from django.apps import AppConfig
class TimelineConfig(AppConfig):
"""Configuration for the timeline app."""
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.timeline'
verbose_name = 'Timeline Events'

View File

@@ -0,0 +1,308 @@
# Generated by Django 4.2.8 on 2025-11-09 15:45
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import pgtrigger.compiler
import pgtrigger.migrations
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
("pghistory", "0006_delete_aggregateevent"),
("moderation", "0002_alter_contentsubmission_submission_type"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("entities", "0007_add_ride_name_history"),
]
operations = [
migrations.CreateModel(
name="EntityTimelineEvent",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("entity_id", models.UUIDField(db_index=True)),
("entity_type", models.CharField(db_index=True, max_length=50)),
(
"event_type",
models.CharField(
help_text="Type of event: opening, closing, relocation, etc.",
max_length=100,
),
),
("event_date", models.DateField()),
(
"event_date_precision",
models.CharField(
blank=True,
choices=[
("day", "Day"),
("month", "Month"),
("year", "Year"),
("decade", "Decade"),
],
max_length=20,
null=True,
),
),
("title", models.CharField(max_length=255)),
("description", models.TextField(blank=True, null=True)),
("from_entity_id", models.UUIDField(blank=True, null=True)),
("to_entity_id", models.UUIDField(blank=True, null=True)),
("from_value", models.TextField(blank=True, null=True)),
("to_value", models.TextField(blank=True, null=True)),
("is_public", models.BooleanField(default=True)),
("display_order", models.IntegerField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"approved_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="timeline_events_approved",
to=settings.AUTH_USER_MODEL,
),
),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="timeline_events_created",
to=settings.AUTH_USER_MODEL,
),
),
(
"from_location",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="timeline_from_events",
to="entities.park",
),
),
(
"submission",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="timeline_events",
to="moderation.contentsubmission",
),
),
(
"to_location",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="timeline_to_events",
to="entities.park",
),
),
],
options={
"verbose_name": "Timeline Event",
"verbose_name_plural": "Timeline Events",
"ordering": ["-event_date", "-created_at"],
},
),
migrations.CreateModel(
name="EntityTimelineEventEvent",
fields=[
("pgh_id", models.AutoField(primary_key=True, serialize=False)),
("pgh_created_at", models.DateTimeField(auto_now_add=True)),
("pgh_label", models.TextField(help_text="The event label.")),
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, serialize=False
),
),
("entity_id", models.UUIDField()),
("entity_type", models.CharField(max_length=50)),
(
"event_type",
models.CharField(
help_text="Type of event: opening, closing, relocation, etc.",
max_length=100,
),
),
("event_date", models.DateField()),
(
"event_date_precision",
models.CharField(
blank=True,
choices=[
("day", "Day"),
("month", "Month"),
("year", "Year"),
("decade", "Decade"),
],
max_length=20,
null=True,
),
),
("title", models.CharField(max_length=255)),
("description", models.TextField(blank=True, null=True)),
("from_entity_id", models.UUIDField(blank=True, null=True)),
("to_entity_id", models.UUIDField(blank=True, null=True)),
("from_value", models.TextField(blank=True, null=True)),
("to_value", models.TextField(blank=True, null=True)),
("is_public", models.BooleanField(default=True)),
("display_order", models.IntegerField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"approved_by",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"created_by",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"from_location",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to="entities.park",
),
),
(
"pgh_context",
models.ForeignKey(
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to="pghistory.context",
),
),
(
"pgh_obj",
models.ForeignKey(
db_constraint=False,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="events",
related_query_name="+",
to="timeline.entitytimelineevent",
),
),
(
"submission",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to="moderation.contentsubmission",
),
),
(
"to_location",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
related_query_name="+",
to="entities.park",
),
),
],
options={
"abstract": False,
},
),
migrations.AddIndex(
model_name="entitytimelineevent",
index=models.Index(
fields=["entity_type", "entity_id", "-event_date"],
name="timeline_en_entity__1edf78_idx",
),
),
migrations.AddIndex(
model_name="entitytimelineevent",
index=models.Index(
fields=["event_type", "-event_date"],
name="timeline_en_event_t_ddeb87_idx",
),
),
migrations.AddIndex(
model_name="entitytimelineevent",
index=models.Index(
fields=["is_public", "-event_date"],
name="timeline_en_is_publ_8737ce_idx",
),
),
pgtrigger.migrations.AddTrigger(
model_name="entitytimelineevent",
trigger=pgtrigger.compiler.Trigger(
name="insert_insert",
sql=pgtrigger.compiler.UpsertTriggerSql(
func='INSERT INTO "timeline_entitytimelineeventevent" ("approved_by_id", "created_at", "created_by_id", "description", "display_order", "entity_id", "entity_type", "event_date", "event_date_precision", "event_type", "from_entity_id", "from_location_id", "from_value", "id", "is_public", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "submission_id", "title", "to_entity_id", "to_location_id", "to_value", "updated_at") VALUES (NEW."approved_by_id", NEW."created_at", NEW."created_by_id", NEW."description", NEW."display_order", NEW."entity_id", NEW."entity_type", NEW."event_date", NEW."event_date_precision", NEW."event_type", NEW."from_entity_id", NEW."from_location_id", NEW."from_value", NEW."id", NEW."is_public", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."submission_id", NEW."title", NEW."to_entity_id", NEW."to_location_id", NEW."to_value", NEW."updated_at"); RETURN NULL;',
hash="76282604c91127f10184eb954cfc832b75b6fd94",
operation="INSERT",
pgid="pgtrigger_insert_insert_5bf38",
table="timeline_entitytimelineevent",
when="AFTER",
),
),
),
pgtrigger.migrations.AddTrigger(
model_name="entitytimelineevent",
trigger=pgtrigger.compiler.Trigger(
name="update_update",
sql=pgtrigger.compiler.UpsertTriggerSql(
condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
func='INSERT INTO "timeline_entitytimelineeventevent" ("approved_by_id", "created_at", "created_by_id", "description", "display_order", "entity_id", "entity_type", "event_date", "event_date_precision", "event_type", "from_entity_id", "from_location_id", "from_value", "id", "is_public", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "submission_id", "title", "to_entity_id", "to_location_id", "to_value", "updated_at") VALUES (NEW."approved_by_id", NEW."created_at", NEW."created_by_id", NEW."description", NEW."display_order", NEW."entity_id", NEW."entity_type", NEW."event_date", NEW."event_date_precision", NEW."event_type", NEW."from_entity_id", NEW."from_location_id", NEW."from_value", NEW."id", NEW."is_public", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."submission_id", NEW."title", NEW."to_entity_id", NEW."to_location_id", NEW."to_value", NEW."updated_at"); RETURN NULL;',
hash="d8ad44ad25d075f4459a79674a168ad1afcab00b",
operation="UPDATE",
pgid="pgtrigger_update_update_1687a",
table="timeline_entitytimelineevent",
when="AFTER",
),
),
),
]

View File

@@ -0,0 +1,94 @@
"""
Timeline models for tracking entity lifecycle events.
"""
import uuid
import pghistory
from django.db import models
@pghistory.track()
class EntityTimelineEvent(models.Model):
"""
Tracks significant events in entity lifecycles (opening, closing, relocation, etc.)
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
entity_id = models.UUIDField(db_index=True)
entity_type = models.CharField(max_length=50, db_index=True)
event_type = models.CharField(max_length=100, help_text="Type of event: opening, closing, relocation, etc.")
event_date = models.DateField()
event_date_precision = models.CharField(
max_length=20,
null=True,
blank=True,
choices=[
('day', 'Day'),
('month', 'Month'),
('year', 'Year'),
('decade', 'Decade'),
]
)
title = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
# Event details - for relocations, transfers, etc.
from_entity_id = models.UUIDField(null=True, blank=True)
to_entity_id = models.UUIDField(null=True, blank=True)
from_location = models.ForeignKey(
'entities.Park',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='timeline_from_events'
)
to_location = models.ForeignKey(
'entities.Park',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='timeline_to_events'
)
from_value = models.TextField(null=True, blank=True)
to_value = models.TextField(null=True, blank=True)
# Moderation
is_public = models.BooleanField(default=True)
display_order = models.IntegerField(null=True, blank=True)
# Tracking
created_by = models.ForeignKey(
'users.User',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='timeline_events_created'
)
approved_by = models.ForeignKey(
'users.User',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='timeline_events_approved'
)
submission = models.ForeignKey(
'moderation.ContentSubmission',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='timeline_events'
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = 'Timeline Event'
verbose_name_plural = 'Timeline Events'
ordering = ['-event_date', '-created_at']
indexes = [
models.Index(fields=['entity_type', 'entity_id', '-event_date']),
models.Index(fields=['event_type', '-event_date']),
models.Index(fields=['is_public', '-event_date']),
]
def __str__(self):
return f"{self.entity_type} {self.entity_id}: {self.title} ({self.event_date})"