mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:11:10 -05:00
Implement historical tracking using django-pghistory; add middleware for context capture and update model architecture
This commit is contained in:
57
memory-bank/features/history-visualization.md
Normal file
57
memory-bank/features/history-visualization.md
Normal file
@@ -0,0 +1,57 @@
|
||||
## Feature: Unified History Timeline (HTMX Integrated)
|
||||
|
||||
### HTMX Template Pattern
|
||||
```django
|
||||
{# history/partials/history_timeline.html #}
|
||||
<div id="history-timeline"
|
||||
hx-get="{% url 'history:timeline' content_type_id=content_type.id object_id=object.id %}"
|
||||
hx-trigger="every 30s, historyUpdate from:body">
|
||||
<div class="space-y-4">
|
||||
{% for event in events %}
|
||||
<div class="component-wrapper bg-white p-4 shadow-sm">
|
||||
<div class="component-header flex items-center gap-2 mb-2">
|
||||
<span class="text-sm font-medium">{{ event.pgh_label|title }}</span>
|
||||
<time class="text-xs text-gray-500">{{ event.pgh_created_at|date:"M j, Y H:i" }}</time>
|
||||
</div>
|
||||
<div class="component-content text-sm">
|
||||
{% if event.pgh_context.metadata.user %}
|
||||
<div class="flex items-center gap-1">
|
||||
<svg class="w-4 h-4">...</svg>
|
||||
<span>{{ event.pgh_context.metadata.user }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### View Integration (Class-Based with HTMX)
|
||||
```python
|
||||
# history/views.py
|
||||
class HistoryTimelineView(View):
|
||||
def get(self, request, content_type_id, object_id):
|
||||
events = ModelHistory.objects.filter(
|
||||
pgh_obj_model=content_type_id,
|
||||
pgh_obj_id=object_id
|
||||
).order_by('-pgh_created_at')[:25]
|
||||
|
||||
if request.htmx:
|
||||
return render(request, "history/partials/history_timeline.html", {
|
||||
"events": events
|
||||
})
|
||||
|
||||
return JsonResponse({
|
||||
'history': [serialize_event(e) for e in events]
|
||||
})
|
||||
```
|
||||
|
||||
### Event Trigger Pattern
|
||||
```python
|
||||
# parks/signals.py
|
||||
from django.dispatch import Signal
|
||||
history_updated = Signal()
|
||||
|
||||
# In model save/delete handlers:
|
||||
history_updated.send(sender=Model, instance=instance)
|
||||
Reference in New Issue
Block a user