Skip to main content

Versioned file field for django models

Project description

django-vff

Introduction

This package offers a file field for django models, that stores the file contents under a VCS (version control system). Everytime a field of this type is changed for a particular model instance, the new content will be commited as a new version in the repository. Thus, there will be one file in the repository for each vff field and instance. The repository will be a subdirectory of django’s settings.MEDIA_ROOT.

Different VCSs can be used to manage the repository, using pluggable backends. The package only provides a GIT backend out of the box.

Installation

Install django-vff like you would install any other pypi package:

$ pip install django-vff

You do not need to add anything into Django’s INSTALLED_APPS.

Configuration

You have to set the following variables in django’s settings.py:

VERSIONEDFILE_BACKEND

A dotted name leading to a backend class, e.g. "vff.git_backend.GitBackend".

Usage

You use it like you would use django.db.models.FileField:

from django.db import models
from vff.field import VersionedFileField


class MyModel(models.model):
    name = models.CharField('Name')
    content = VersionedFileField(name='content', verbose_name='file content')

Once you have an instance of the MyModel class, you can use three special methods to list available versions, to get specific versions, and to get diffs between versions:

  • list revisions:

    >>> revs = instance.content.list_revisions()
    >>> from pprint import pprint
    >>> pprint(revs)
    [{'author': u'John Smith',
      'date': datetime.datetime(2011, 6, 16, 13, 25, 30),
      'message': u'second version',
      'versionid': 'a64ea785e195bbf4b3064e6701adbdbf4b5d13be'},
     {'author': u'Martha Brown',
      'date': datetime.datetime(2011, 6, 16, 8, 24, 36),
      'message': u'first version',
      'versionid': '048848a70205d0e18d836f403e2a02830492cbf9'}]
  • get the string content of a specific revision:

    >>> rev1_id = revs[-1]['versionid']
    >>> instance.content.get_revision(rev1_id)
    u'These are the contents of the first version of the file'
  • get the diff between two revisions:

    >>> rev2_id = revs[-2]['versionid']
    >>> print instance.content.get_diff(rev1_id, rev2_id)
    --- 048848a70205d0e18d836f403e2a02830492cbf9
    
    +++ a64ea785e195bbf4b3064e6701adbdbf4b5d13be
    
    @@ -1,1 +1,1 @@
    
    -These are the contents of the first version of the file
    +These are the contents of the second version of the file

Providing new backends

To develop a new backend for django-vff, you have to subclass the abstract base class vff.abcs.VFFBackend. The methods that need to be implemented are well documented in the docstrings of the class.

CHANGES

0.1b1 (2011-09-02)

  • Initial version which includes a VersionedFileField and a git backend.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-vff-0.1b1.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file django-vff-0.1b1.tar.gz.

File metadata

  • Download URL: django-vff-0.1b1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-vff-0.1b1.tar.gz
Algorithm Hash digest
SHA256 9900abfb07d8590d7e8d3c8d83e1c38acf8390bc6499fb201505151eb65e42b9
MD5 8f6ed99779d3334b7b3cadb2e4fbb3c2
BLAKE2b-256 3ec604787dcd043b6d1183ae2b4642df1686ce1b52ce326a890899021115cb68

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page