log page changes too

This commit is contained in:
j 2012-01-31 22:42:03 +05:30
parent cd1f4c93ee
commit a62a992ad2
2 changed files with 10 additions and 0 deletions

View file

@ -4,6 +4,7 @@ from __future__ import division, with_statement
from django.db import models
from changelog.models import Changelog
class Page(models.Model):
created = models.DateTimeField(auto_now_add=True)
@ -14,3 +15,10 @@ class Page(models.Model):
def __unicode__(self):
return self.name
def log(self):
c = Changelog(type='page')
c.value = {
'name': self.name,
'body': self.body,
}
c.save()

View file

@ -137,6 +137,8 @@ def editPage(request):
if request.user.get_profile().capability('canEditSitePages'):
data = json.loads(request.POST['data'])
page, created = models.Page.objects.get_or_create(name=data['name'])
if not created:
page.log()
page.body = data['body']
page.save()
response = json_response({'name': page.name, 'page': page.body})