Skip to content

Commit

Permalink
Merge branch 'release/0.1.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jul 20, 2018
2 parents 413b561 + e9e0f96 commit c326991
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 52 deletions.
30 changes: 26 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
.pypirc
etc/*
.venv/*

# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags

.settings
.project
.pydevproject
.settings
test-*
db.sqlite3

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
_build/
# C extensions
*.so

Expand Down
39 changes: 18 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
language: python
python:
- "2.7"
# - "3.2"
- "3.3"
- "3.4"
# - "nightly"
env:
- DJANGO_VERSION=1.6
- DJANGO_VERSION=1.7
- DJANGO_VERSION=1.8

- 3.6
services:
- mysql
branches:
only:
- develop
install:
- pip install -q Django==$DJANGO_VERSION --use-mirrors
- pip install flake8 --use-mirrors
- pip install coveralls --use-mirrors
- pip install -q -r requirements.txt --use-mirrors

- pip install --upgrade pip
- pip install -r requirements.txt
- pip install flake8
- pip install coveralls
before_script:
- flake8 django_revision

script:
- coverage run --source=django_revision manage.py test

- flake8 django_revision
- mysql -e 'create database edc character set utf8;'
script:
- coverage run --source=django_revision manage.py test
after_success:
- coveralls
- coveralls
notifications:
slack:
secure: TrzrTrCafFN7dqD/jjS0qLsLrkkwprOquFStWvHbPQ/sX44HODyDH7A8duu5f84WnPVYV0d+nHNDjJ6/6pBIyKDmwEt0bZblZSb4vQ9q1D60Qocs3gMPLQU8g2U5SZLfk5jWCKWN1JPLkP5ElKazUdNMOv4E0o58m1DmdO8WFGK1aO7geTL6rjf1qLdXdbj5q4gvRjMKZ8tv5HxARMYg1heqeTHO1t9CxXJWfGrSn4NaHNUcnWW6hCaBtZzeKtFPbUzpv2sDxpw7hEx3gNyGD5+HdmfrJpR9WtbIHfQKN/P/dbLq4cXS6zX+iE23BDjGSmeGpJrzCt/FHaKwwaFr5Aa0Jlms1ciijd/bLPCjey1lHIkYsmp298j2ow1P4JvTj9wlKJb25vyUFlHgYlQZRuUZRfFa9jPxVzslbfIVi1cgHRbW2psBHp0rHrZPKdiYW2HpGwNlgtkLaVtR7x6xJvHDG0wjmMQSnyP1IcRWMtMv63RqEC28YQGGknl7Uy+iyxxixnUauK+Z/mtAY7LrInvj66LV3oKdPFsPuIX8cjttJEyALwZn0GoS837kgJ48neoJyQcRudLDIgSa7Bh4WNoB4mWB9ZFz+cqPXV8JDnE84gHSqcdz8Dp6WCPTLxtTKp8nhS3I1/Omu7r5RgdhIqRzmE1R/VkuH4CLWzsLCaA=
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include AUTHORS CHANGES README.md LICENCE
include AUTHORS CHANGES README.rst LICENCE VERSION
recursive-include docs *
recursive-exclude edc_example/*
recursive-exclude etc/*
51 changes: 38 additions & 13 deletions README.md → README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[![Build Status](https://travis-ci.org/erikvw/django-revision.svg?branch=master)](https://travis-ci.org/erikvw/django-revision)[![Coverage Status](https://coveralls.io/repos/erikvw/django-revision/badge.svg)](https://coveralls.io/r/erikvw/django-revision)
|pypi| |travis| |coverage|

# django-revision

django-revision
---------------

Add a Django field class to your models to track the git revision with every model instance saved.

Uses `GitPython` (does not work on python version 3.2.)
python 3.6, Django 2.0+. Uses `GitPython`.

For example:

.. code-block:: python
from django.db import models
from django_revision import RevisionField
Expand All @@ -16,20 +20,24 @@ For example:
revision = RevisionField()
... then
.. 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'
Expand All @@ -40,30 +48,37 @@ Reference git information from anywhere in your app:
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

Get the latest version:

pip install git+https://github.com/erikvw/django-revision@develop#egg=django_revision
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:
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:
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`:
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
Expand All @@ -72,6 +87,8 @@ In the view's `get_context_data` set a context attribute to `revision.tag` or ju
In your template:

.. code-block:: python
{% block footer %}
<footer class="footer">
<div class="container">
Expand All @@ -82,3 +99,11 @@ In your template:
</footer>
{% endblock footer %}
.. |pypi| image:: https://img.shields.io/pypi/v/django-revision.svg
:target: https://pypi.python.org/pypi/django-revision

.. |travis| image:: https://travis-ci.org/clinicedc/django-revision.svg?branch=develop
:target: https://travis-ci.org/clinicedc/django-revision

.. |coverage| image:: https://coveralls.io/repos/github/clinicedc/django-revision/badge.svg?branch=develop
:target: https://coveralls.io/github/clinicedc/django-revision?branch=develop
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.15
3 changes: 2 additions & 1 deletion django_revision/modeladmin_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ModelAdminRevisionMixin:
def add_view(self, request, form_url='', extra_context=None):
extra_context = extra_context or {}
extra_context.update({'revision': site_revision.revision})
return super(ModelAdminRevisionMixin, self).add_view(request, form_url=form_url, extra_context=extra_context)
return super(ModelAdminRevisionMixin, self).add_view(
request, form_url=form_url, extra_context=extra_context)

def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {}
Expand Down
2 changes: 1 addition & 1 deletion django_revision/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from django.urls.conf import path

urlpatterns = [
path(r'^admin/', admin.site.urls),
path(r'admin/', admin.site.urls),
]
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = E226,E302,E41,F401
max-line-length = 120
ignore = E226,E302,E41,F401,W503
max-line-length = 95
max-complexity = 10
exclude = django_revision/tests/*,edc_example/*
exclude = django_revision/tests/*,.venv/*
18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
from setuptools import setup
from setuptools import find_packages

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()

with open(os.path.join(os.path.dirname(__file__), 'VERSION')) as f:
VERSION = f.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='django-revision',
version='0.1.14',
version=VERSION,
author=u'Erik van Widenfelt',
author_email='ew2789@gmail.com',
packages=find_packages(),
include_package_data=True,
url='http://github/erikvw/django-revision',
license='GPL licence, see LICENCE',
description='Add a Django field class to your models to track the git revision with every model instance saved.',
description='Track the git revision with every model instance saved.',
long_description=README,
zip_safe=False,
keywords='django fields git',
Expand All @@ -30,12 +33,11 @@
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
Expand Down

0 comments on commit c326991

Please sign in to comment.