add new changelog and call add_changelog all over the place

This commit is contained in:
j 2014-12-17 13:45:46 +00:00
parent 8ec99ddef7
commit 9e9bf30c42
27 changed files with 365 additions and 44 deletions

View file

@ -265,11 +265,6 @@ class Annotation(models.Model):
del j['id']
return j
def log(self):
c = Changelog(type='annotation')
c.value = self.json(layer=True)
c.save()
def __unicode__(self):
return u"%s %s-%s" %(self.public_id, self.start, self.end)

View file

@ -15,6 +15,7 @@ from item import utils
from item.models import Item
from item.utils import get_by_id
from entity.models import Entity
from changelog.models import add_changelog
import models
from tasks import update_item, add_annotations
@ -186,6 +187,7 @@ def addAnnotation(request, data):
value=value)
annotation.save()
update_item.delay(annotation.id)
add_changelog(request, data, annotation.public_id)
response = json_response(annotation.json())
response['data']['editable'] = True
else:
@ -228,6 +230,7 @@ def addAnnotations(request, data):
response = json_response()
data['user'] = request.user.username
t = add_annotations.delay(data)
add_changelog(request, data, item.public_id)
response['data']['taskId'] = t.task_id
else:
response = json_response(status=403, text='permission denied')
@ -248,7 +251,7 @@ def removeAnnotation(request, data):
response = json_response({})
a = get_object_or_404_json(models.Annotation, public_id=data['id'])
if a.editable(request.user):
a.log()
add_changelog(request, data, a.public_id)
a.delete()
else:
response = json_response(status=403, text='permission denied')
@ -275,7 +278,7 @@ def editAnnotation(request, data):
a = get_object_or_404_json(models.Annotation, public_id=data['id'])
if a.editable(request.user):
layer = get_by_id(settings.CONFIG['layers'], a.layer)
a.log()
add_changelog(request, data)
for key in ('value', 'in', 'out'):
if key == 'value' and layer['type'] == 'entity':
value = Entity.get_by_name(data['value']).get_id()

View file

@ -19,14 +19,6 @@ class Page(models.Model):
def __unicode__(self):
return self.name
def log(self):
c = Changelog(type='page')
c.value = {
'name': self.name,
'text': self.text,
}
c.save()
class Settings(models.Model):
created = models.DateTimeField(auto_now_add=True)

View file

@ -17,6 +17,7 @@ from ox.utils import json, ET
import models
from user.models import init_user
from changelog.models import add_changelog
from ox.django.api import actions
@ -130,10 +131,9 @@ def editPage(request, data):
'''
if request.user.get_profile().capability('canEditSitePages'):
page, created = models.Page.objects.get_or_create(name=data['name'])
if not created:
page.log()
page.text = ox.sanitize_html(data['text'])
page.save()
add_changelog(request, data, page.name)
response = json_response({'name': page.name, 'text': page.text})
else:
response = json_response(status=403, text='permission denied')

View file

@ -20,6 +20,7 @@ from item.models import get_item, Item
from item.views import parse_query
import item.tasks
from ox.django.api import actions
from changelog.models import add_changelog
import models
import tasks
@ -375,6 +376,7 @@ def moveMedia(request, data):
item.tasks.update_timeline.delay(public_id)
response = json_response(text='updated')
response['data']['item'] = i.public_id
add_changelog(request, data, i.public_id)
return render_to_json_response(response)
actions.register(moveMedia, cache=False)
@ -431,6 +433,7 @@ def editMedia(request, data):
if save_items:
for i in Item.objects.filter(id__in=list(set(save_items))):
i.save()
add_changelog(request, data, [f['id'] for f in response['data']['files']])
return render_to_json_response(response)
actions.register(editMedia, cache=False)
@ -448,6 +451,7 @@ def removeMedia(request, data):
i.update_timeline()
else:
i.save()
add_changelog(request, data, data['ids'])
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)

View file

@ -0,0 +1,146 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.db.models import Q, Manager
from ox.django.query import QuerySet
from item.utils import decode_id
def parseCondition(condition, user):
'''
condition: {
value: "war"
}
or
condition: {
key: "year",
value: "1970-1980,
operator: "!="
}
...
'''
k = condition.get('key', 'name')
k = {
'user': 'user__username',
}.get(k, k)
if not k:
k = 'name'
v = condition['value']
op = condition.get('operator')
if not op:
op = '='
if op.startswith('!'):
op = op[1:]
exclude = True
else:
exclude = False
if op == '-':
q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
& parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
if exclude:
return ~q
else:
return q
if k == 'id':
v = decode_id(v)
if isinstance(v, bool): #featured and public flag
key = k
elif k in ('id', ):
key = '%s%s' % (k, {
'>': '__gt',
'>=': '__gte',
'<': '__lt',
'<=': '__lte',
}.get(op,''))
else:
key = '%s%s' % (k, {
'==': '__iexact',
'^': '__istartswith',
'$': '__iendswith',
}.get(op,'__icontains'))
key = str(key)
if exclude:
q = ~Q(**{key: v})
else:
q = Q(**{key: v})
return q
def parseConditions(conditions, operator, user):
'''
conditions: [
{
value: "war"
}
{
key: "year",
value: "1970-1980,
operator: "!="
},
{
key: "country",
value: "f",
operator: "^"
}
],
operator: "&"
'''
conn = []
for condition in conditions:
if 'conditions' in condition:
q = parseConditions(condition['conditions'],
condition.get('operator', '&'), user)
if q:
conn.append(q)
pass
else:
conn.append(parseCondition(condition, user))
if conn:
q = conn[0]
for c in conn[1:]:
if operator == '|':
q = q | c
else:
q = q & c
return q
return None
class LogManager(Manager):
def get_query_set(self):
return QuerySet(self.model)
def find(self, data, user):
'''
query: {
conditions: [
{
value: "war"
}
{
key: "year",
value: "1970-1980,
operator: "!="
},
{
key: "country",
value: "f",
operator: "^"
}
],
operator: "&"
}
'''
#join query with operator
qs = self.get_query_set()
query = data.get('query', {})
conditions = parseConditions(query.get('conditions', []),
query.get('operator', '&'),
user)
if conditions:
qs = qs.filter(conditions)
return qs

View file

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Log'
db.create_table('changelog_log', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('action', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
('data', self.gf('ox.django.fields.DictField')(default={})),
('created', self.gf('django.db.models.fields.DateTimeField')()),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='changelog', null=True, to=orm['auth.User'])),
('changeid', self.gf('django.db.models.fields.CharField')(max_length=255)),
))
db.send_create_signal('changelog', ['Log'])
def backwards(self, orm):
# Deleting model 'Log'
db.delete_table('changelog_log')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'changelog.changelog': {
'Meta': {'object_name': 'Changelog'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'value': ('ox.django.fields.DictField', [], {'default': '{}'})
},
'changelog.log': {
'Meta': {'object_name': 'Log'},
'action': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'changeid': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'data': ('ox.django.fields.DictField', [], {'default': '{}'}),
'created': ('django.db.models.fields.DateTimeField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'changelog'", 'null': 'True', 'to': "orm['auth.User']"})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['changelog']

View file

@ -1,9 +1,19 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, with_statement
from datetime import datetime
from django.contrib.auth.models import User
from django.db import models
from ox.django import fields
import ox
import managers
'''
FIXME: remove this table more migrate to new ChangeLog
'''
class Changelog(models.Model):
created = models.DateTimeField(auto_now_add=True)
type = models.CharField(max_length=255, db_index=True)
@ -14,3 +24,44 @@ class Changelog(models.Model):
def json(self):
return self.value
def add_changelog(request, data, id=None):
user = request.user
action = request.POST['action']
c = Log(user=user, action=action, data=data)
if id and isinstance(id, list):
id = ', '.join(id)
c.changeid = id or data.get('id')
c.created = datetime.now()
c.save()
class Log(models.Model):
action = models.CharField(max_length=255, db_index=True)
data = fields.DictField(default={})
created = models.DateTimeField()
user = models.ForeignKey(User, null=True, related_name='changelog')
changeid = models.CharField(max_length=255)
objects = managers.LogManager()
def __unicode__(self):
return u'%s %s %s' % (self.created, self.action, self.changeid)
def get_id(self):
return ox.toAZ(self.id)
def json(self, keys=None):
r = {
'id': self.get_id(),
'action': self.action,
'created': self.created,
'data': self.data,
'changeid': self.changeid,
'user': self.user.username,
}
if keys:
for k in r.keys():
if k not in keys:
del r[k]
return r

View file

@ -21,8 +21,7 @@ def parse_query(data, user):
for key in ('keys', 'group', 'list', 'range', 'sort', 'query'):
if key in data:
query[key] = data[key]
#query['qs'] = models.Changelog.objects.find(query, user)
query['qs'] = models.Changelog.all()
query['qs'] = models.Log.objects.find(query, user)
return query
def order_query(qs, sort):
@ -53,7 +52,7 @@ def findChangeLogs(request, data):
]
operator: ","
},
sort: [{key: 'created', operator: '+'}],
sort: [{key: 'date', operator: '+'}],
range: [int, int]
keys: [string]
}

View file

@ -11,6 +11,7 @@ from ox.django.api import actions
from annotation.models import Annotation
from item.models import Item
from item import utils
from changelog.models import add_changelog
import models

View file

@ -14,6 +14,7 @@ from item import utils
from item.models import Item
from itemlist.models import List
from archive.chunk import process_chunk
from changelog.models import add_changelog
import models
@ -51,6 +52,7 @@ def addDocument(request, data):
for id in ids:
document = models.Document.get(id)
document.add(item)
add_changelog(request, data, item.public_id)
else:
response = json_response(status=403, text='permission denied')
else:
@ -59,6 +61,7 @@ def addDocument(request, data):
for id in ids:
document = models.Document.get(id)
document.add(item)
add_changelog(request, data, data['item'])
return render_to_json_response(response)
actions.register(addDocument, cache=False)
@ -81,6 +84,7 @@ def editDocument(request, data):
if data['id']:
document = models.Document.get(data['id'])
if document.editable(request.user, item):
add_changelog(request, data)
document.edit(data, request.user, item)
document.save()
response['data'] = document.json(user=request.user, item=item)
@ -228,12 +232,14 @@ def removeDocument(request, data):
item = 'item' in data and Item.objects.get(public_id=data['item']) or None
if item:
if item.editable(request.user):
add_changelog(request, data, item.public_id)
for id in ids:
document = models.Document.get(id)
document.remove(item)
else:
response = json_response(status=403, text='not allowed')
else:
add_changelog(request, data, ids)
for id in ids:
document = models.Document.get(id)
if document.editable(request.user):
@ -263,6 +269,7 @@ def sortDocuments(request, data):
models.ItemProperties.objects.filter(item=item, document=document).update(index=index)
index += 1
response = json_response()
add_changelog(request, data, item.public_id)
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)

View file

@ -15,6 +15,7 @@ from ox.django.api import actions
from django.conf import settings
from item import utils
from changelog.models import add_changelog
import models
@ -62,6 +63,7 @@ def addClips(request, data):
return render_to_json_response(response)
else:
clips.append(clip.json(request.user))
add_changelog(request, data, edit.get_id())
response['data']['clips'] = clips
else:
response = json_response(status=403, text='permission denied')
@ -89,6 +91,7 @@ def removeClips(request, data):
if edit.editable(request.user):
for clip in edit.clips.filter(id__in=ids):
clip.delete()
add_changelog(request, data, edit.get_id())
response['data'] = edit.json(user=request.user)
else:
response = json_response(status=403, text='permission denied')
@ -126,6 +129,7 @@ def editClip(request, data):
if valid:
clip.save()
response['data'] = clip.json(user=request.user)
add_changelog(request, data, clip.get_id())
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
@ -151,6 +155,7 @@ def orderClips(request, data):
for i in ids:
models.Clip.objects.filter(edit=edit, id=i).update(index=index)
index += 1
add_changelog(request, data, edit.get_id())
else:
response = json_response(status=500, text='sorting smart lists not possible')
else:
@ -279,6 +284,7 @@ def addEdit(request, data):
pos.save()
response = json_response(status=200, text='created')
response['data'] = edit.json(user=request.user)
add_changelog(request, data, edit.get_id())
return render_to_json_response(response)
actions.register(addEdit, cache=False)
@ -301,6 +307,7 @@ def editEdit(request, data):
'id', 'name', 'posterFrames', 'status',
'subscribed', 'user'
], user=request.user)
add_changelog(request, data, edit.get_id())
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
@ -319,6 +326,7 @@ def removeEdit(request, data):
edit = get_edit_or_404_json(data['id'])
response = json_response()
if edit.editable(request.user):
add_changelog(request, data, edit.get_id())
edit.delete()
else:
response = json_response(status=403, text='not allowed')
@ -436,6 +444,7 @@ def subscribeToEdit(request, data):
qs = models.Position.objects.filter(user=user, section='public')
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save()
add_changelog(request, data, edit.get_id())
response = json_response()
return render_to_json_response(response)
actions.register(subscribeToEdit, cache=False)
@ -455,6 +464,7 @@ def unsubscribeFromEdit(request, data):
edit.subscribed_users.remove(user)
models.Position.objects.filter(edit=edit, user=user, section='public').delete()
response = json_response()
add_changelog(request, data, edit.get_id())
return render_to_json_response(response)
actions.register(unsubscribeFromEdit, cache=False)

View file

@ -16,6 +16,7 @@ from django.db.models import Sum
from item import utils
from item.models import Item
from itemlist.models import List
from changelog.models import add_changelog
import models
@ -64,6 +65,7 @@ def addEntity(request, data):
entity.matches = 0
entity.save()
response = json_response(status=200, text='created')
add_changelog(request, data, entity.get_id())
response['data'] = entity.json()
else:
response = json_response(status=409, text='name exists')
@ -159,6 +161,7 @@ def editEntity(request, data):
entity.edit(data)
entity.save()
response['data'] = entity.json(user=request.user)
add_changelog(request, data)
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
@ -282,6 +285,7 @@ def removeEntity(request, data):
else:
response = json_response(status=403, text='not allowed')
break
add_changelog(request, data, ids)
return render_to_json_response(response)
actions.register(removeEntity, cache=False)

View file

@ -161,8 +161,3 @@ 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()

View file

@ -12,6 +12,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from ox.django.api import actions
from item import utils
from changelog.models import add_changelog
import models
@ -57,6 +58,7 @@ def addEvent(request, data):
event.update_matches()
response = json_response(status=200, text='created')
response['data'] = event.json()
add_changelog(request, data, event.get_id())
else:
response = json_response(status=409, text='name exists')
response['data']['names'] = existing_names
@ -108,6 +110,7 @@ def editEvent(request, data):
event.update_matches()
response = json_response(status=200, text='updated')
response['data'] = event.json()
add_changelog(request, data)
else:
response = json_response(status=409, text='Event name conflict')
response['data']['names'] = conflict_names
@ -128,6 +131,7 @@ def removeEvent(request, data):
'''
event = get_object_or_404_json(models.Event, pk=ox.fromAZ(data['id']))
if event.editable(request.user):
add_changelog(request, data)
event.delete()
response = json_response(status=200, text='removed')
else:

View file

@ -293,11 +293,6 @@ class Item(models.Model):
p = tasks.update_poster.delay(self.public_id)
return p
def log(self):
c = Changelog(type='item')
c.value = self.json
c.save()
def update_external(self):
if settings.DATA_SERVICE and not self.public_id.startswith('0x'):
response = external_data('getData', {'id': self.public_id})

View file

@ -32,6 +32,7 @@ from archive.models import File, Stream
from archive import extract
from clip.models import Clip
from user.models import has_capability
from changelog.models import add_changelog
from ox.django.api import actions
@ -552,6 +553,7 @@ def add(request, data):
i.make_poster(True)
response = json_response(status=200, text='created')
response['data'] = i.get_json()
add_changelog(request, data)
return render_to_json_response(response)
actions.register(add, cache=False)
@ -574,7 +576,6 @@ def edit(request, data):
update_clips = False
item = get_object_or_404_json(models.Item, public_id=data['id'])
if item.editable(request.user):
item.log()
response = json_response(status=200, text='ok')
if 'rightslevel' in data:
if request.user.get_profile().capability('canEditRightsLevel') == True:
@ -603,6 +604,7 @@ def edit(request, data):
if update_clips:
tasks.update_clips.delay(item.public_id)
response['data'] = item.get_json()
add_changelog(request, data)
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
@ -626,7 +628,7 @@ def remove(request, data):
user.is_staff or \
item.user == user or \
item.groups.filter(id__in=user.groups.all()).count() > 0:
item.log()
add_changelog(request, data)
#FIXME: is this cascading enough or do we end up with orphan files etc.
item.delete()
response = json_response(status=200, text='removed')
@ -650,6 +652,7 @@ def setPosterFrame(request, data):
item.save()
tasks.update_poster(item.public_id)
response = json_response()
add_changelog(request, data)
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)
@ -682,6 +685,7 @@ def setPoster(request, data):
tasks.update_poster(item.public_id)
response = json_response()
response['data']['posterAspect'] = item.poster_width/item.poster_height
add_changelog(request, data)
else:
response = json_response(status=403, text='invalid poster url')
else:

View file

@ -18,6 +18,7 @@ from ox.django.api import actions
from item import utils
from item.models import Item
from user.tasks import update_numberoflists
from changelog.models import add_changelog
def get_list_or_404_json(id):
id = id.split(':')
@ -159,6 +160,7 @@ def addListItems(request, data):
for item in Item.objects.filter(public_id__in=data['items']):
list.add(item)
response = json_response(status=200, text='items added')
add_changelog(request, data, data['list'])
else:
response = json_response(status=403, text='not allowed')
elif 'query' in data:
@ -185,6 +187,7 @@ def removeListItems(request, data):
if list.editable(request.user):
list.remove(items=data['items'])
response = json_response(status=200, text='items removed')
add_changelog(request, data, data['list'])
else:
response = json_response(status=403, text='not allowed')
elif 'query' in data:
@ -274,6 +277,7 @@ def addList(request, data):
pos.save()
response = json_response(status=200, text='created')
response['data'] = list.json()
add_changelog(request, data, list.get_id())
return render_to_json_response(response)
actions.register(addList, cache=False)
@ -300,6 +304,7 @@ def editList(request, data):
response = json_response()
list.edit(data, request.user)
response['data'] = list.json(user=request.user)
add_changelog(request, data)
else:
response = json_response(status=403, text='not allowed')
return render_to_json_response(response)
@ -317,6 +322,7 @@ def removeList(request, data):
list = get_list_or_404_json(data['id'])
response = json_response()
if list.editable(request.user):
add_changelog(request, data)
list.delete()
update_numberoflists.delay(request.user.username)
else:
@ -344,6 +350,7 @@ def subscribeToList(request, data):
qs = models.Position.objects.filter(user=user, section='public')
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save()
add_changelog(request, data)
response = json_response()
return render_to_json_response(response)
actions.register(subscribeToList, cache=False)
@ -364,6 +371,7 @@ def unsubscribeFromList(request, data):
list.subscribed_users.remove(user)
models.Position.objects.filter(list=list, user=user, section='public').delete()
response = json_response()
add_changelog(request, data)
return render_to_json_response(response)
actions.register(unsubscribeFromList, cache=False)

View file

@ -24,16 +24,13 @@ class News(models.Model):
def save(self, *args, **kwargs):
super(News, self).save(*args, **kwargs)
self.log()
def log(self):
c = Changelog(type='news')
c.value = self.json()
c.save()
def get_id(self):
return ox.toAZ(self.id)
def json(self, keys=None):
j = {
'id': ox.toAZ(self.id),
'id': self.get_id(),
'date': self.date,
'title': self.title,
'text': self.text,

View file

@ -9,6 +9,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from ox.django.api import actions
from changelog.models import add_changelog
import models
@ -59,6 +60,7 @@ def addNews(request, data):
setattr(news, key, data[key])
news.save()
response = json_response(news.json())
add_changelog(request, data, news.get_id())
return render_to_json_response(response)
actions.register(addNews, cache=False)
@ -66,13 +68,14 @@ actions.register(addNews, cache=False)
def removeNews(request, data):
'''
takes {
ids: []
id: id
}
returns {}
'''
response = json_response({})
news = get_object_or_404_json(models.News, id=ox.fromAZ(data['id']))
if news.editable(request.user):
add_changelog(request, data)
news.delete()
response = json_response(status=200, text='news removed')
else:
@ -102,6 +105,7 @@ def editNews(request, data):
setattr(n, key, data[key])
n.save()
response['data'] = n.json()
add_changelog(request, data)
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)

View file

@ -14,6 +14,7 @@ from item import utils
import models
import tasks
from user.decorators import capability_required_json
from changelog.models import add_changelog
@capability_required_json('canManageTitlesAndNames')
def editName(request, data):
@ -35,6 +36,7 @@ def editName(request, data):
person.edited = True
person.save()
tasks.update_file_paths.delay(person.id)
add_changelog(request, data)
response['data'] = person.json()
return render_to_json_response(response)
actions.register(editName, cache=False)

View file

@ -155,8 +155,3 @@ class Place(models.Model):
for key in ('south', 'west', 'north', 'east')])) > 0
super(Place, self).save(*args, **kwargs)
def log(self):
c = Changelog(type='place')
c.value = self.json()
c.save()

View file

@ -13,6 +13,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from ox.django.api import actions
from item import utils
from changelog.models import add_changelog
import models
@ -84,6 +85,10 @@ def addPlace(request, data):
place.save()
place.update_matches()
response = json_response(place.json())
# add name/alternativeNames again for changelog
data['name'] = place.name
data['alternativeNames'] = place.alternativeNames
add_changelog(request, data, place.get_id())
else:
response = json_response(status=409,
text='%s exists'%(existing_names and 'Name' or 'Geoname'))
@ -146,6 +151,7 @@ def editPlace(request, data):
if 'name' in data or 'alternativeNames' in data:
place.update_matches()
response = json_response(place.json())
add_changelog(request, data)
else:
response = json_response(status=409,
text='%s exists'%(conflict_names and 'Name' or 'Geoname'))
@ -170,6 +176,7 @@ def removePlace(request, data):
data = data['id']
place = get_object_or_404_json(models.Place, pk=ox.fromAZ(data))
if place.editable(request.user):
add_changelog(request, data)
place.delete()
response = json_response(status=200, text='deleted')
else:

View file

@ -9,6 +9,7 @@ from ox.django.api import actions
from item.models import Item
from item import utils
from changelog.models import add_changelog
import models

View file

@ -19,6 +19,7 @@ from django.template import RequestContext
from item import utils
from archive.chunk import process_chunk
import models
from changelog.models import add_changelog
def get_text_or_404_json(id):
id = id.split(':')
@ -67,6 +68,7 @@ def addText(request, data):
pos.save()
response = json_response(status=200, text='created')
response['data'] = text.json(user=request.user)
add_changelog(request, data, text.get_id())
return render_to_json_response(response)
actions.register(addText, cache=False)
@ -144,6 +146,7 @@ def editText(request, data):
if text.editable(request.user):
text.edit(data, request.user)
response['data'] = text.json(user=request.user)
add_changelog(request, data, text.get_id())
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
@ -256,6 +259,7 @@ def removeText(request, data):
text = get_text_or_404_json(data['id'])
response = json_response()
if text.editable(request.user):
add_changelog(request, data, text.get_id())
text.delete()
else:
response = json_response(status=403, text='not allowed')
@ -281,6 +285,7 @@ def subscribeToText(request, data):
qs = models.Position.objects.filter(user=user, section='public')
pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save()
add_changelog(request, data, text.get_id())
response = json_response()
return render_to_json_response(response)
actions.register(subscribeToText, cache=False)
@ -300,6 +305,7 @@ def unsubscribeFromText(request, data):
text.subscribed_users.remove(user)
models.Position.objects.filter(text=text, user=user, section='public').delete()
response = json_response()
add_changelog(request, data, text.get_id())
return render_to_json_response(response)
actions.register(unsubscribeFromText, cache=False)

View file

@ -12,6 +12,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from ox.django.api import actions
from item import utils
from user.decorators import capability_required_json
from changelog.models import add_changelog
import models
@ -35,6 +36,7 @@ def editTitle(request, data):
title.sorttitle = unicodedata.normalize('NFKD', title.sorttitle)
title.edited = True
title.save()
add_changelog(request, data, title.get_id())
response['data'] = title.json()
return render_to_json_response(response)
actions.register(editTitle, cache=False)

View file

@ -21,6 +21,7 @@ import ox
from ox.django.api import actions
from item.models import Access, Item
from item import utils
from changelog.models import add_changelog
import models
from decorators import capability_required_json
@ -379,6 +380,7 @@ def editUser(request, data):
user.username = data['username']
user.save()
profile.save()
add_changelog(request, data, user.username)
response['data'] = user.data.get().json()
return render_to_json_response(response)
actions.register(editUser, cache=False)
@ -394,6 +396,7 @@ def removeUser(request, data):
'''
response = json_response()
u = get_user_or_404(data)
add_changelog(request, data, u.username)
u.delete()
return render_to_json_response(response)
actions.register(removeUser, cache=False)
@ -929,6 +932,7 @@ def addGroup(request, data):
n += 1
name = u'%s [%d]' % (_name, n)
response['data'] = group_json(g)
add_changelog(request, data, g.name)
return render_to_json_response(response)
actions.register(addGroup, cache=False)
@ -951,6 +955,7 @@ def editGroup(request, data):
g = Group.objects.get(id=ox.fromAZ(data['id']))
g.name = data['name']
g.save()
add_changelog(request, data, g.name)
response['data'] = group_json(g)
return render_to_json_response(response)
actions.register(editGroup, cache=False)
@ -972,6 +977,7 @@ def removeGroup(request, data):
i.groups.remove(g)
for u in g.user_set.all():
u.groups.remove(g)
add_changelog(request, data, g.name)
g.delete()
return render_to_json_response(response)
actions.register(removeGroup, cache=False)