Media suffix context processor

I’m using this Django context processor for automatically appending a query string for file cache versioning. It generates the query string off of the git revision and saves me many headaches.

from django.conf import settings
from git import Repo
import hashlib, os
git_head = Repo(settings.PROJECT_DIR).heads[0].commit.hexsha
salted_git_head = hashlib.sha512("".join([
    git_head,
    os.getlogin(),
    "".join(os.uname()),
])).hexdigest()[0:6]
def git_head(request):
    return {
        "GIT_HEAD": git_head,
        "SALTED_GIT_HEAD": salted_git_head,
        "SALTED_GIT_QS": "v=%s" % salted_git_head,
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>