keep a log of changes
This commit is contained in:
parent
caf8630d61
commit
82c83c1309
12 changed files with 61 additions and 3 deletions
|
@ -11,6 +11,7 @@ import ox
|
|||
|
||||
from archive import extract
|
||||
from clip.models import Clip
|
||||
from changelog.models import Changelog
|
||||
|
||||
from item.utils import sort_string
|
||||
import managers
|
||||
|
@ -202,6 +203,11 @@ class Annotation(models.Model):
|
|||
j['videoRatio'] = streams[0].aspect_ratio
|
||||
return j
|
||||
|
||||
def log(self):
|
||||
c = Changelog(type='annotation')
|
||||
c.value = self.json()
|
||||
c.save()
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s %s-%s" %(self.public_id, self.start, self.end)
|
||||
|
||||
|
|
|
@ -164,6 +164,7 @@ def removeAnnotation(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
a = get_object_or_404_json(models.Annotation, public_id=data['id'])
|
||||
if a.editable(request.user):
|
||||
a.log()
|
||||
a.delete()
|
||||
if a.clip.annotations.count() == 0:
|
||||
a.clip.delete()
|
||||
|
@ -193,6 +194,7 @@ def editAnnotation(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
a = get_object_or_404_json(models.Annotation, public_id=data['id'])
|
||||
if a.editable(request.user):
|
||||
a.log()
|
||||
for key in ('value', 'in', 'out'):
|
||||
if key in data:
|
||||
setattr(a, {
|
||||
|
|
0
pandora/changelog/__init__.py
Normal file
0
pandora/changelog/__init__.py
Normal file
13
pandora/changelog/models.py
Normal file
13
pandora/changelog/models.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, with_statement
|
||||
from django.db import models
|
||||
from ox.django import fields
|
||||
|
||||
class Changelog(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
type = models.CharField(max_length=255, db_index=True)
|
||||
value = fields.DictField(default={})
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s %s' %(self.type, self.created)
|
16
pandora/changelog/tests.py
Normal file
16
pandora/changelog/tests.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
1
pandora/changelog/views.py
Normal file
1
pandora/changelog/views.py
Normal file
|
@ -0,0 +1 @@
|
|||
# Create your views here.
|
|
@ -36,7 +36,6 @@ class MetaClip:
|
|||
if streams:
|
||||
self.aspect_ratio = streams[0].aspect_ratio
|
||||
sortvalue = ''
|
||||
findvalue = ''
|
||||
for l in settings.CONFIG['clipLayers']:
|
||||
sortvalue += ''.join(filter(lambda s: s,
|
||||
[a.sortvalue
|
||||
|
@ -45,7 +44,7 @@ class MetaClip:
|
|||
self.sortvalue = sortvalue[:1000]
|
||||
else:
|
||||
self.sortvalue = None
|
||||
self.findvalue = '\n'.join([a.findvalue for a in self.annotations.all()])
|
||||
self.findvalue = '\n'.join(filter(None, [a.findvalue for a in self.annotations.all()]))
|
||||
if self.id:
|
||||
for l in settings.CONFIG['clipLayers']:
|
||||
setattr(self, l, self.annotations.filter(layer=l).count()>0)
|
||||
|
|
|
@ -16,6 +16,7 @@ from item.models import Item
|
|||
from item import utils
|
||||
from person.models import get_name_sort
|
||||
from title.models import get_title_sort
|
||||
from changelog.models import Changelog
|
||||
|
||||
import managers
|
||||
|
||||
|
@ -128,3 +129,8 @@ class Event(models.Model):
|
|||
j[key] = getattr(self, key)
|
||||
j['nameSort'] = self.name_sort
|
||||
return j
|
||||
|
||||
def log(self):
|
||||
c = Changelog(type='event')
|
||||
c.value = self.json()
|
||||
c.save()
|
||||
|
|
|
@ -35,6 +35,7 @@ from data_api import external_data
|
|||
from archive import extract
|
||||
from annotation.models import Annotation
|
||||
from clip.models import Clip
|
||||
from changelog.models import Changelog
|
||||
import archive.models
|
||||
|
||||
from person.models import get_name_sort
|
||||
|
@ -228,6 +229,11 @@ class Item(models.Model):
|
|||
self.data[key] = data[key]
|
||||
return self.save()
|
||||
|
||||
def log(self):
|
||||
c = Changelog(type='item')
|
||||
c.value = self.json
|
||||
c.save()
|
||||
|
||||
def update_external(self):
|
||||
if settings.DATA_SERVICE and not self.itemId.startswith('0x'):
|
||||
response = external_data('getData', {'id': self.itemId})
|
||||
|
@ -572,7 +578,7 @@ class Item(models.Model):
|
|||
qs = Annotation.objects.filter(item=self)
|
||||
qs = qs.filter(layer=i)
|
||||
qs = qs.order_by('start')
|
||||
save(i, u'\n'.join([l.findvalue for l in qs]))
|
||||
save(i, u'\n'.join(filter(None, [l.findvalue for l in qs])))
|
||||
elif i != '*' and i not in self.facet_keys:
|
||||
value = self.get(i)
|
||||
if isinstance(value, list):
|
||||
|
|
|
@ -429,6 +429,7 @@ def edit(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||
if item.editable(request.user):
|
||||
item.log()
|
||||
response = json_response(status=200, text='ok')
|
||||
if 'notes' in data:
|
||||
if request.user.get_profile().capability('canEditMetadata'):
|
||||
|
@ -459,6 +460,7 @@ def remove(request):
|
|||
data = json.loads(request.POST['data'])
|
||||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||
if item.editable(request.user):
|
||||
item.log()
|
||||
#FIXME: is this cascading enough or do we end up with orphan files etc.
|
||||
item.delete()
|
||||
response = json_response(status=200, text='removed')
|
||||
|
|
|
@ -14,6 +14,7 @@ from ox.django import fields
|
|||
import managers
|
||||
from annotation.models import Annotation, get_matches
|
||||
from item.models import Item
|
||||
from changelog.models import Changelog
|
||||
|
||||
|
||||
class Place(models.Model):
|
||||
|
@ -119,3 +120,8 @@ class Place(models.Model):
|
|||
#self.area= ox.location.area(self.south, self.west, self.north, self.east)
|
||||
|
||||
super(Place, self).save(*args, **kwargs)
|
||||
|
||||
def log(self):
|
||||
c = Changelog(type='place')
|
||||
c.value = self.json()
|
||||
c.save()
|
||||
|
|
|
@ -99,6 +99,7 @@ INSTALLED_APPS = (
|
|||
'clip',
|
||||
'archive',
|
||||
'event',
|
||||
'changelog',
|
||||
'item',
|
||||
'itemlist',
|
||||
'person',
|
||||
|
|
Loading…
Reference in a new issue