Track the git revision with every model instance saved
Project description
django-revision
Add a Django field class to your models to track the git revision with every model instance saved.
python 3.7, Django 3.0+. Uses GitPython.
For example:
from django.db import models
from django_revision import RevisionField
class TestModel(models.Model):
revision = RevisionField()
>>> test_model = TestModel.objects.create()
>>>test_model.revision
'0.1dev0'
If the source is modified after the git tag was applied:
>>> test_model = TestModel.objects.create()
>>>test_model.revision
>>> '0.1dev0-35-ge9f632e:develop:e9f632e92143c53411290b576487f48c15156603'
Reference git information from anywhere in your app:
>>> from django_revision import site_revision
>>> site_revision.tag
'0.1dev0'
>>>site_revision.revision
'0.1dev0'
For research trial data, we need to track the source code revision at time of data collection. We deploy our source as a git branch and django-revision picks up the tag:branch:commit and updates each saved model instance as data is collected.
Installation
Add to settings:
INSTALLED_APPS = [
...
'django_revision.apps.AppConfig',
...
]
If your git working directory is something other than settings.BASE_DIR add GIT_DIR to settings with the path to your git working directory. For example:
GIT_DIR = BASE_DIR.ancestor(2)
If you have a deployment case where the source folder is not a git repo, you can set the revision manually in settings:
REVISION = '0.1.3'
Using in a View and Template
In the view’s get_context_data set a context attribute to revision.tag or just use the RevisionMixin:
from django_revision.views import RevisionMixin
class MyView(RevisionMixin, TemplateView):
...
In your template:
{% block footer %}
<footer class="footer">
<div class="container">
<div class="col-md-4"><p class="text-muted text-center"><small>{{ year }} {{ institution }}</small></p></div>
<div class="col-md-4"><p class="text-muted text-center"><small>Revision: {{ revision }}</small></p></div>
<div class="col-md-4"><p class="text-muted text-center"><small>For Research Purposes Only</small></p></div>
</div>
</footer>
{% endblock footer %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-revision-0.3.7.tar.gz
.
File metadata
- Download URL: django-revision-0.3.7.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf0dec38fb00601ec0967a12ab95ea2058b25b092b632c76c803de42595c744b |
|
MD5 | 16494e2fc1d579847a376d312dfd6ae3 |
|
BLAKE2b-256 | 7a9523f2c0464ef5253038b7d3d498fb51ea9be3c9d8af34d458595b63eabd60 |
File details
Details for the file django_revision-0.3.7-py3-none-any.whl
.
File metadata
- Download URL: django_revision-0.3.7-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a423fd1dbdc8c67fa1a2582809783ca19e4923f8bf2eec21aadb060f7046a1c |
|
MD5 | f2fc6fbc203593dba53d820923bef7a8 |
|
BLAKE2b-256 | 4605b4392c5aebe8eab18d23db87cee176ab8946cb86e0daf5380ebd55119994 |