mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 16:31:08 -05:00
Add version control context processor and integrate map functionality with dedicated JavaScript
This commit is contained in:
43
history_tracking/context_processors.py
Normal file
43
history_tracking/context_processors.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from typing import Dict, Any
|
||||
from django.http import HttpRequest
|
||||
from .signals import get_current_branch
|
||||
from .models import VersionBranch, ChangeSet
|
||||
|
||||
def version_control(request: HttpRequest) -> Dict[str, Any]:
|
||||
"""
|
||||
Add version control information to the template context
|
||||
"""
|
||||
current_branch = get_current_branch()
|
||||
context = {
|
||||
'vcs_enabled': True,
|
||||
'current_branch': current_branch,
|
||||
'recent_changes': []
|
||||
}
|
||||
|
||||
if current_branch:
|
||||
# Get recent changes for the current branch
|
||||
recent_changes = ChangeSet.objects.filter(
|
||||
branch=current_branch,
|
||||
status='applied'
|
||||
).order_by('-created_at')[:5]
|
||||
|
||||
context.update({
|
||||
'recent_changes': recent_changes,
|
||||
'branch_name': current_branch.name,
|
||||
'branch_metadata': current_branch.metadata
|
||||
})
|
||||
|
||||
# Get available branches for switching
|
||||
context['available_branches'] = VersionBranch.objects.filter(
|
||||
is_active=True
|
||||
).order_by('-created_at')
|
||||
|
||||
# Check if current page is versioned
|
||||
if hasattr(request, 'resolver_match') and request.resolver_match:
|
||||
view_func = request.resolver_match.func
|
||||
if hasattr(view_func, 'view_class'):
|
||||
view_class = view_func.view_class
|
||||
context['page_is_versioned'] = hasattr(view_class, 'model') and \
|
||||
hasattr(view_class.model, 'history')
|
||||
|
||||
return {'version_control': context}
|
||||
Reference in New Issue
Block a user