mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-07-07 01:24:06 +00:00
Fixed text search fileds for ACL and Logs. Added version info to footer.
This commit is contained in:
42
mysite/context_processors.py
Normal file
42
mysite/context_processors.py
Normal file
@ -0,0 +1,42 @@
|
||||
from django.conf import settings
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
def version_info(request):
|
||||
"""Add version information to template context"""
|
||||
|
||||
git_commit = getattr(settings, 'GIT_COMMIT', None)
|
||||
git_commit_short = getattr(settings, 'GIT_COMMIT_SHORT', None)
|
||||
build_date = getattr(settings, 'BUILD_DATE', None)
|
||||
|
||||
if not git_commit or git_commit == 'development':
|
||||
try:
|
||||
base_dir = getattr(settings, 'BASE_DIR', Path(__file__).resolve().parent.parent)
|
||||
result = subprocess.run(['git', 'rev-parse', 'HEAD'],
|
||||
capture_output=True, text=True, cwd=base_dir, timeout=5)
|
||||
if result.returncode == 0:
|
||||
git_commit = result.stdout.strip()
|
||||
git_commit_short = git_commit[:7]
|
||||
|
||||
date_result = subprocess.run(['git', 'log', '-1', '--format=%ci'],
|
||||
capture_output=True, text=True, cwd=base_dir, timeout=5)
|
||||
if date_result.returncode == 0:
|
||||
build_date = date_result.stdout.strip()
|
||||
except (subprocess.TimeoutExpired, subprocess.SubprocessError, FileNotFoundError):
|
||||
pass
|
||||
|
||||
if not git_commit:
|
||||
git_commit = 'development'
|
||||
if not git_commit_short:
|
||||
git_commit_short = 'dev'
|
||||
if not build_date:
|
||||
build_date = 'unknown'
|
||||
|
||||
return {
|
||||
'VERSION_INFO': {
|
||||
'git_commit': git_commit,
|
||||
'git_commit_short': git_commit_short,
|
||||
'build_date': build_date,
|
||||
'is_development': git_commit_short == 'dev'
|
||||
}
|
||||
}
|
@ -120,6 +120,10 @@ MIDDLEWARE = [
|
||||
|
||||
ROOT_URLCONF = 'mysite.urls'
|
||||
|
||||
GIT_COMMIT = ENV('GIT_COMMIT', default='development')
|
||||
GIT_COMMIT_SHORT = ENV('GIT_COMMIT_SHORT', default='dev')
|
||||
BUILD_DATE = ENV('BUILD_DATE', default='unknown')
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
@ -131,11 +135,13 @@ TEMPLATES = [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'mysite.context_processors.version_info',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
WSGI_APPLICATION = 'mysite.wsgi.application'
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user