Add version control context processor and integrate map functionality with dedicated JavaScript

This commit is contained in:
pacnpal
2025-02-06 20:06:10 -05:00
parent 939eaed201
commit d3141ab320
16 changed files with 1671 additions and 89 deletions

View 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}