django-revision


Namedjango-revision JSON
Version 0.3.6 PyPI version JSON
download
home_pagehttp://github.com/erikvw/django-revision
SummaryTrack the git revision with every model instance saved
upload_time2022-09-26 02:21:06
maintainer
docs_urlNone
authorErik van Widenfelt
requires_python>=3.8
licenseGPL license, see LICENSE
keywords django edc fields git
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |pypi| |actions| |codecov| |downloads|

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:

.. code-block:: python

    from django.db import models

    from django_revision import RevisionField

    class TestModel(models.Model):

        revision = RevisionField()

.. code-block:: python

    >>> test_model = TestModel.objects.create()
    >>>test_model.revision
    '0.1dev0'

If the source is modified after the git tag was applied:

.. code-block:: python

    >>> test_model = TestModel.objects.create()
    >>>test_model.revision
    >>> '0.1dev0-35-ge9f632e:develop:e9f632e92143c53411290b576487f48c15156603'

Reference git information from anywhere in your app:

.. code-block:: python

    >>> 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:

.. code-block:: python

    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:

.. code-block:: python

    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:

.. code-block:: python

    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``:

.. code-block:: python

    from django_revision.views import RevisionMixin

    class MyView(RevisionMixin, TemplateView):
        ...

In your template:

.. code-block:: python

    {% block footer %}
	<footer class="footer">
	  <div class="container">
	    <div class="col-md-4"><p class="text-muted text-center"><small>{{ year }}&nbsp;{{ 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 %}

.. |pypi| image:: https://img.shields.io/pypi/v/django-revision.svg
    :target: https://pypi.python.org/pypi/django-revision

.. |actions| image:: https://github.com/erikvw/django-revision/workflows/build/badge.svg?branch=develop
  :target: https://github.com/erikvw/django-revision/actions?query=workflow:build

.. |codecov| image:: https://codecov.io/gh/erikvw/django-revision/branch/develop/graph/badge.svg
  :target: https://codecov.io/gh/erikvw/django-revision

.. |downloads| image:: https://pepy.tech/badge/django-revision
   :target: https://pepy.tech/project/django-revision

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/erikvw/django-revision",
    "name": "django-revision",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "django Edc fields git",
    "author": "Erik van Widenfelt",
    "author_email": "ew2789@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0a/79/19cab5f5d47d9fae06f9c6ec2bede1394efbc2b334de4f598c7fa4a63b2e/django-revision-0.3.6.tar.gz",
    "platform": null,
    "description": "|pypi| |actions| |codecov| |downloads|\n\ndjango-revision\n---------------\n\nAdd a Django field class to your models to track the git revision with every model instance saved.\n\npython 3.7, Django 3.0+. Uses `GitPython`.\n\nFor example:\n\n.. code-block:: python\n\n    from django.db import models\n\n    from django_revision import RevisionField\n\n    class TestModel(models.Model):\n\n        revision = RevisionField()\n\n.. code-block:: python\n\n    >>> test_model = TestModel.objects.create()\n    >>>test_model.revision\n    '0.1dev0'\n\nIf the source is modified after the git tag was applied:\n\n.. code-block:: python\n\n    >>> test_model = TestModel.objects.create()\n    >>>test_model.revision\n    >>> '0.1dev0-35-ge9f632e:develop:e9f632e92143c53411290b576487f48c15156603'\n\nReference git information from anywhere in your app:\n\n.. code-block:: python\n\n    >>> from django_revision import site_revision\n    >>> site_revision.tag\n    '0.1dev0'\n    >>>site_revision.revision\n    '0.1dev0'\n\n\nFor 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\neach saved model instance as data is collected.\n\nInstallation\n------------\n\nAdd to settings:\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        ...\n        'django_revision.apps.AppConfig',\n        ...\n    ]\n\nIf 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:\n\n.. code-block:: python\n\n    GIT_DIR = BASE_DIR.ancestor(2)\n\nIf you have a deployment case where the source folder is not a `git` repo, you can set the revision manually in settings:\n\n.. code-block:: python\n\n    REVISION = '0.1.3'\n\nUsing in a View and Template\n----------------------------\n\nIn the view's ``get_context_data`` set a context attribute to ``revision.tag`` or just use the ``RevisionMixin``:\n\n.. code-block:: python\n\n    from django_revision.views import RevisionMixin\n\n    class MyView(RevisionMixin, TemplateView):\n        ...\n\nIn your template:\n\n.. code-block:: python\n\n    {% block footer %}\n\t<footer class=\"footer\">\n\t  <div class=\"container\">\n\t    <div class=\"col-md-4\"><p class=\"text-muted text-center\"><small>{{ year }}&nbsp;{{ institution }}</small></p></div>\n\t    <div class=\"col-md-4\"><p class=\"text-muted text-center\"><small>Revision: {{ revision }}</small></p></div>\n\t    <div class=\"col-md-4\"><p class=\"text-muted text-center\"><small>For Research Purposes Only</small></p></div>\n\t  </div>\n\t</footer>\n    {% endblock footer %}\n\n.. |pypi| image:: https://img.shields.io/pypi/v/django-revision.svg\n    :target: https://pypi.python.org/pypi/django-revision\n\n.. |actions| image:: https://github.com/erikvw/django-revision/workflows/build/badge.svg?branch=develop\n  :target: https://github.com/erikvw/django-revision/actions?query=workflow:build\n\n.. |codecov| image:: https://codecov.io/gh/erikvw/django-revision/branch/develop/graph/badge.svg\n  :target: https://codecov.io/gh/erikvw/django-revision\n\n.. |downloads| image:: https://pepy.tech/badge/django-revision\n   :target: https://pepy.tech/project/django-revision\n",
    "bugtrack_url": null,
    "license": "GPL license, see LICENSE",
    "summary": "Track the git revision with every model instance saved",
    "version": "0.3.6",
    "split_keywords": [
        "django",
        "edc",
        "fields",
        "git"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9209459b44a4ba5da04293ffe2154f53",
                "sha256": "52dfd9c6f2b498c1ba1488e8713902d0dd4aab1840537d53d62289f41a6baa3e"
            },
            "downloads": -1,
            "filename": "django_revision-0.3.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9209459b44a4ba5da04293ffe2154f53",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16563,
            "upload_time": "2022-09-26T02:21:05",
            "upload_time_iso_8601": "2022-09-26T02:21:05.055811Z",
            "url": "https://files.pythonhosted.org/packages/f5/0f/adbb8f0d10a00c6f6d79e8f84b5e24b179461632bd042b0aad7625478a3a/django_revision-0.3.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ac14cdbd671e0d10c5d6b1c66426b9dc",
                "sha256": "9e970ca417d9c02225f61181d89c5f323ec875d257de989bc2bed7a3770c4227"
            },
            "downloads": -1,
            "filename": "django-revision-0.3.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ac14cdbd671e0d10c5d6b1c66426b9dc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18427,
            "upload_time": "2022-09-26T02:21:06",
            "upload_time_iso_8601": "2022-09-26T02:21:06.880912Z",
            "url": "https://files.pythonhosted.org/packages/0a/79/19cab5f5d47d9fae06f9c6ec2bede1394efbc2b334de4f598c7fa4a63b2e/django-revision-0.3.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-26 02:21:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "erikvw",
    "github_project": "django-revision",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "django-revision"
}
        
Elapsed time: 0.45988s