API: get changes since
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 25 Feb 2011 16:15:02 +0000 (17:15 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 25 Feb 2011 16:15:02 +0000 (17:15 +0100)
apps/api/handlers.py
apps/api/helpers.py [new file with mode: 0644]
apps/api/migrations/0001_initial.py [new file with mode: 0644]
apps/api/migrations/__init__.py [new file with mode: 0644]
apps/api/models.py [new file with mode: 0644]
apps/api/tests.py [new file with mode: 0644]
apps/api/urls.py
apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py [new file with mode: 0644]
apps/catalogue/models.py

index 151af2d..cca504f 100644 (file)
@@ -1,14 +1,20 @@
 # -*- coding: utf-8 -*-
 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 # -*- coding: utf-8 -*-
 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+
+from datetime import datetime
 from django.shortcuts import get_object_or_404
 from django.contrib.auth.decorators import login_required, user_passes_test
 from django.shortcuts import get_object_or_404
 from django.contrib.auth.decorators import login_required, user_passes_test
+from django.utils import simplejson as json
 from piston.handler import BaseHandler
 from piston.utils import rc, validate
 from piston.handler import BaseHandler
 from piston.utils import rc, validate
+
+from api.models import Deleted
+from api.helpers import timestamp
 from catalogue.models import Book, Tag
 from catalogue.forms import BookImportForm
 from catalogue.views import tagged_object_list 
 from catalogue.models import Book, Tag
 from catalogue.forms import BookImportForm
 from catalogue.views import tagged_object_list 
-
+"""
 class TagHandler(BaseHandler):
    allowed_methods = ('GET',)
    model = Tag   
 class TagHandler(BaseHandler):
    allowed_methods = ('GET',)
    model = Tag   
@@ -28,6 +34,153 @@ class BookHandler(BaseHandler):
             return get_object_or_404(Book, slug=slug)
         else:
             return Book.objects.all()
             return get_object_or_404(Book, slug=slug)
         else:
             return Book.objects.all()
+"""
+
+
+class WLHandler(BaseHandler):
+
+    @staticmethod
+    def fields(request, name):
+        fields_str = request.GET.get(name) if request is not None else None
+        return fields_str.split(',') if fields_str is not None else None
+
+    @staticmethod
+    def book_dict(book, fields=None, extra_fields=None):
+        obj = {}
+        for field in ('slug', 'title', 'description',
+                      'extra_info', 'gazeta_link', 'wiki_link'):
+            if getattr(book, field):
+                obj[field] = getattr(book, field)
+        for field in ('created_at', 'changed_at'):
+            obj[field] = timestamp(getattr(book, field))
+        for field in ('xml', 'epub', 'txt', 'pdf', 'html'):
+            f = getattr(book, field+'_file') 
+            if f:
+                obj[field] = f.url
+        for media in book.medias.all():
+            obj.setdefault(media.type, []).append(media.file.url)
+        if book.parent:
+            obj['parent'] = book.parent.id
+            obj['parent_number'] = book.parent_number
+        if fields is not None:
+            for key in obj.keys():
+                if key not in fields:
+                    del obj[key]
+
+        # if there's still extra_info, we can parse it
+        if 'extra_info' in obj:
+            extra = json.loads(obj['extra_info'])
+            if extra_fields is not None:
+                for key in extra.keys():
+                    if key not in extra_fields:
+                        del extra[key]
+            obj['extra_info'] = extra
+
+        obj['id'] = book.id
+        return obj
+
+    @classmethod
+    def book_changes(cls, since=0, request=None):
+        since = datetime.fromtimestamp(float(since))
+        book_fields = cls.fields(request, 'book_fields')
+        extra_fields = cls.fields(request, 'extra_fields')
+
+        added = []
+        changed = []
+        deleted = []
+
+        last_change = since
+        for book in Book.objects.filter(changed_at__gt=since):
+            if book.changed_at > last_change:
+                last_change = book.changed_at
+            book_d = cls.book_dict(book, book_fields, extra_fields)
+            if book.created_at > since:
+                added.append(book_d)
+            else:
+                changed.append(book_d)
+
+        for book in Deleted.objects.filter(type='Book', deleted_at__gt=since, created_at__lte=since):
+            if book.deleted_at > last_change:
+                last_change = book.deleted_at
+            deleted.append(book.id)
+        return {'added': added, 'changed': changed, 'deleted': deleted, 'last_change': timestamp(last_change)}
+
+    @staticmethod
+    def tag_dict(tag, fields=None):
+        obj = {}
+        for field in ('name', 'slug', 'sort_key', 'category', 'description', 'main_page', #'created_at', 'changed_at',
+                      'gazeta_link', 'wiki_link'):
+            if getattr(tag, field):
+                obj[field] = getattr(tag, field)
+        if fields is not None:
+            for key in obj.keys():
+                if key not in fields:
+                    del obj[key]
+        obj['id'] = tag.id
+        return obj
+
+    @classmethod
+    def tag_changes(cls, since=0, request=None):
+        since = datetime.fromtimestamp(float(since))
+        tag_fields = cls.fields(request, 'tag_fields')
+
+        added = []
+        changed = []
+        deleted = []
+
+        last_change = since
+        for tag in Tag.objects.filter(changed_at__gt=since):
+            if tag.changed_at > last_change:
+                last_change = tag.changed_at
+            tag_d = cls.tag_dict(tag, tag_fields)
+            if tag.created_at > since:
+                added.append(tag_d)
+            else:
+                changed.append(tag_d)
+
+        for tag in Deleted.objects.filter(type='Tag', deleted_at__gt=since, created_at__lte=since):
+            if tag.deleted_at > last_change:
+                last_change = tag.deleted_at
+            deleted.append(tag.id)
+        return {'added': added, 'changed': changed, 'deleted': deleted, 'last_change': timestamp(last_change)}
+
+
+class BookChangesHandler(WLHandler):
+    allowed_methods = ('GET',)
+
+    def read(self, request, since):
+        return self.book_changes(since, request)
+
+
+class TagChangesHandler(WLHandler):
+    allowed_methods = ('GET',)
+
+    def read(self, request, since):
+        return self.tag_changes(since, request)
+
+
+class ChangesHandler(WLHandler):
+    allowed_methods = ('GET',)
+
+    def read(self, request, since):
+        changes = {
+            'books': self.book_changes(since, request),
+            'tags': self.tag_changes(since, request),
+        }
+
+        last_change = 0
+        changes_rev = {}
+        for model in changes:
+            for field in changes[model]:
+                if field == 'last_change':
+                    if changes[model][field] > last_change:
+                        last_change = changes[model][field]
+                else:
+                    changes_rev.setdefault(field, {})[model] = changes[model][field]
+        changes_rev['last_change'] = last_change
+        return changes_rev
+
+
 
 # old
 """
 
 # old
 """
diff --git a/apps/api/helpers.py b/apps/api/helpers.py
new file mode 100644 (file)
index 0000000..f01522a
--- /dev/null
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+from time import mktime
+
+def timestamp(dtime):
+    "converts a datetime.datetime object to a timestamp with fractional part"
+    return mktime(dtime.timetuple()) + dtime.microsecond / 1000000.0
+
diff --git a/apps/api/migrations/0001_initial.py b/apps/api/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..6ac0f54
--- /dev/null
@@ -0,0 +1,45 @@
+# encoding: utf-8
+import 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 'Deleted'
+        db.create_table('api_deleted', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('object_id', self.gf('django.db.models.fields.IntegerField')()),
+            ('type', self.gf('django.db.models.fields.CharField')(max_length='50')),
+            ('created_at', self.gf('django.db.models.fields.DateTimeField')()),
+            ('deleted_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('api', ['Deleted'])
+
+        # Adding unique constraint on 'Deleted', fields ['type', 'object_id']
+        db.create_unique('api_deleted', ['type', 'object_id'])
+
+
+    def backwards(self, orm):
+        
+        # Removing unique constraint on 'Deleted', fields ['type', 'object_id']
+        db.delete_unique('api_deleted', ['type', 'object_id'])
+
+        # Deleting model 'Deleted'
+        db.delete_table('api_deleted')
+
+
+    models = {
+        'api.deleted': {
+            'Meta': {'unique_together': "(('type', 'object_id'),)", 'object_name': 'Deleted'},
+            'created_at': ('django.db.models.fields.DateTimeField', [], {}),
+            'deleted_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'object_id': ('django.db.models.fields.IntegerField', [], {}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': "'50'"})
+        }
+    }
+
+    complete_apps = ['api']
diff --git a/apps/api/migrations/__init__.py b/apps/api/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/api/models.py b/apps/api/models.py
new file mode 100644 (file)
index 0000000..8858162
--- /dev/null
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.db import models
+from django.db.models.signals import pre_delete
+
+from catalogue.models import Book, Tag
+
+
+class Deleted(models.Model):
+    object_id = models.IntegerField()
+    type = models.CharField(max_length="50", db_index=True)
+    created_at = models.DateTimeField(editable=False, db_index=True)
+    deleted_at = models.DateTimeField(auto_now_add=True, db_index=True)
+
+    class Meta:
+        unique_together = (('type', 'object_id'),)
+
+
+
+def _pre_delete_handler(sender, instance, **kwargs):
+    """ save deleted objects for change history purposes """
+
+    if sender in (Book, Tag):
+        Deleted.objects.create(type=sender.__name__, object_id=instance.id, created_at=instance.created_at)
+pre_delete.connect(_pre_delete_handler)
diff --git a/apps/api/tests.py b/apps/api/tests.py
new file mode 100644 (file)
index 0000000..e3dd71a
--- /dev/null
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+
+from datetime import datetime
+
+from django.test import TestCase
+from django.utils import simplejson as json
+
+from api.helpers import timestamp
+from catalogue.models import Book, Tag
+
+
+class ChangesTests(TestCase):
+
+    def test_basic(self):
+        book = Book.objects.create(slug='a-book', title='A Book')
+        tag = Tag.objects.create(category='author', slug='author', name='Author')
+
+        print self.client.get('/api/changes/0.json?book_fields=slug&tag_fields=slug').content
+        changes = json.loads(self.client.get('/api/changes/0.json?book_fields=slug&tag_fields=slug').content)
+        self.assertEqual(changes['added']['books'], 
+                         [{'id': book.id, 'slug': book.slug}],
+                         'Invalid book format in changes')
+        self.assertEqual(changes['added']['tags'], 
+                         [{'id': tag.id, 'slug': tag.slug}],
+                         'Invalid tag format in changes')
+
+
+class BookChangesTests(TestCase):
+
+    def setUp(self):
+        self.book = Book.objects.create()
+
+    def test_basic(self):
+        # test book in book_changes.added
+        changes = json.loads(self.client.get('/api/book_changes/0.json').content)
+        self.assertEqual(len(changes['added']),
+                         1,
+                         'Added book not in book_changes.added')
+
+        # test changed book in changed
+        self.book.slug = 'a-book'
+        self.book.save()
+        changes = json.loads(self.client.get('/api/book_changes/%f.json' % timestamp(self.book.created_at)).content)
+        self.assertEqual(changes['added'],
+                         [],
+                         'Changed book in book_changes.added instead of book_changes.changed.')
+        self.assertEqual(len(changes['changed']),
+                         1,
+                         'Changed book not in book_changes.changed.')
+
+        # test deleted book in deleted
+        Book.objects.all().delete()
+        changes = json.loads(self.client.get('/api/book_changes/%f.json' % timestamp(self.book.changed_at)).content)
+        self.assertEqual(changes['added'],
+                         [],
+                         'Deleted book still in book_changes.added.')
+        self.assertEqual(changes['changed'],
+                         [],
+                         'Deleted book still in book_changes.changed.')
+        self.assertEqual(len(changes['deleted']),
+                         1,
+                         'Deleted book not in book_changes.deleted.')
+
+    def test_shelf(self):
+        changed_at = self.book.changed_at
+        print changed_at
+
+        # putting on a shelf should not update changed_at
+        shelf = Tag.objects.create(category='set', slug='shelf')
+        self.book.tags = [shelf]
+        self.assertEqual(self.book.changed_at,
+                         changed_at)
+
+class TagChangesTests(TestCase):
+
+    def setUp(self):
+        self.tag = Tag.objects.create()
+
+    def test_basic(self):
+        # test tag in tag_changes.added
+        changes = json.loads(self.client.get('/api/tag_changes/0.json').content)
+        self.assertEqual(len(changes['added']),
+                         1,
+                         'Added tag not in tag_changes.added')
+
+        # test changed tag in changed
+        self.tag.slug = 'a-tag'
+        self.tag.save()
+        changes = json.loads(self.client.get('/api/tag_changes/%f.json' % timestamp(self.tag.created_at)).content)
+        self.assertEqual(changes['added'],
+                         [],
+                         'Changed tag in tag_changes.added instead of tag_changes.changed.')
+        self.assertEqual(len(changes['changed']),
+                         1,
+                         'Changed tag not in tag_changes.changed.')
+
+        # test deleted book in deleted
+        Tag.objects.all().delete()
+        changes = json.loads(self.client.get('/api/tag_changes/%f.json' % timestamp(self.tag.changed_at)).content)
+        self.assertEqual(changes['added'],
+                         [],
+                         'Deleted tag still in tag_changes.added.')
+        self.assertEqual(changes['changed'],
+                         [],
+                         'Deleted tag still in tag_changes.changed.')
+        self.assertEqual(len(changes['deleted']),
+                         1,
+                         'Deleted tag not in tag_changes.deleted.')
index beb4a7b..77fe8cf 100644 (file)
@@ -1,27 +1,36 @@
 # -*- coding: utf-8 -*-
 from django.conf.urls.defaults import *
 from piston.resource import Resource
 # -*- coding: utf-8 -*-
 from django.conf.urls.defaults import *
 from piston.resource import Resource
-from piston.authentication import OAuthAuthentication
+#from piston.authentication import HttpBasicAuthentication
 
 
-from api.handlers import BookHandler, TagHandler
+#from api.handlers import BookHandler, TagHandler
+from api import handlers
 
 
 
 
-auth = OAuthAuthentication(realm='API')
-book_resource = Resource(handler=BookHandler)
-tag_resource = Resource(handler=TagHandler, authentication=auth)
+#auth = OAuthAuthentication(realm='API')
+book_changes_resource = Resource(handler=handlers.BookChangesHandler)
+tag_changes_resource = Resource(handler=handlers.TagChangesHandler)#, authentication=auth)
+changes_resource = Resource(handler=handlers.ChangesHandler)
 
 urlpatterns = patterns('',
 
 urlpatterns = patterns('',
-    url(r'^books/(?P<slug>[^/]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource),
-    url(r'^books\.(?P<emitter_format>xml|json|yaml)$', book_resource),
-    url(r'^tags/(?P<tags>[a-zA-Z0-9-/]*)\.(?P<emitter_format>xml|json|yaml)$', tag_resource),
-    url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource), #detail
-    url(r'^lektura/(?P<book_slug>[a-zA-Z0-9-]+)/motyw/(?P<theme_slug>[a-zA-Z0-9-]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource), #fragments
-    url(r'^oauth/callback/$','oauth_callback'),
+    url(r'^book_changes/(?P<since>\d*(\.\d*)?)\.(?P<emitter_format>xml|json|yaml)$', book_changes_resource),
+    url(r'^tag_changes/(?P<since>\d*(\.\d*)?)\.(?P<emitter_format>xml|json|yaml)$', tag_changes_resource),
+    url(r'^changes/(?P<since>\d*(\.\d*)?)\.(?P<emitter_format>xml|json|yaml)$', changes_resource),
+
+    #url(r'^books/(?P<id>[\d,]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource),
+    #url(r'^books\.(?P<emitter_format>xml|json|yaml)$', book_resource),
+
+    #url(r'^tags/(?P<tags>[a-zA-Z0-9-/]*)\.(?P<emitter_format>xml|json|yaml)$', tag_resource),
+    #url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource), #detail
+    #url(r'^lektura/(?P<book_slug>[a-zA-Z0-9-]+)/motyw/(?P<theme_slug>[a-zA-Z0-9-]+)\.(?P<emitter_format>xml|json|yaml)$', book_resource), #fragments
+    #url(r'^oauth/callback/$','oauth_callback'),
 )
 
 )
 
+"""
 urlpatterns += patterns(
 'piston.authentication',
     url(r'^oauth/request_token/$','oauth_request_token'),
     url(r'^oauth/authorize/$','oauth_user_auth'),
     url(r'^oauth/access_token/$','oauth_access_token'),
 )
 urlpatterns += patterns(
 'piston.authentication',
     url(r'^oauth/request_token/$','oauth_request_token'),
     url(r'^oauth/authorize/$','oauth_user_auth'),
     url(r'^oauth/access_token/$','oauth_access_token'),
 )
+"""
\ No newline at end of file
diff --git a/apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py b/apps/catalogue/migrations/0007_auto__add_field_book_changed_at__add_field_tag_created_at__add_field_t.py
new file mode 100644 (file)
index 0000000..b339c05
--- /dev/null
@@ -0,0 +1,166 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'Book.changed_at'
+        db.add_column('catalogue_book', 'changed_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2011, 2, 25, 15, 19, 36, 525463), db_index=True, blank=True), keep_default=False)
+
+        # Adding index on 'Book', fields ['created_at']
+        db.create_index('catalogue_book', ['created_at'])
+
+        # Adding field 'Tag.created_at'
+        db.add_column('catalogue_tag', 'created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, default=datetime.datetime(2011, 2, 25, 15, 19, 42, 921525), db_index=True, blank=True), keep_default=False)
+
+        # Adding field 'Tag.changed_at'
+        db.add_column('catalogue_tag', 'changed_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2011, 2, 25, 15, 19, 45, 697471), db_index=True, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Removing index on 'Book', fields ['created_at']
+        db.delete_index('catalogue_book', ['created_at'])
+
+        # Deleting field 'Book.changed_at'
+        db.delete_column('catalogue_book', 'changed_at')
+
+        # Deleting field 'Tag.created_at'
+        db.delete_column('catalogue_tag', 'created_at')
+
+        # Deleting field 'Tag.changed_at'
+        db.delete_column('catalogue_tag', 'changed_at')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True'}),
+            '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': '75', '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': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'max_length': '30', 'unique': 'True'})
+        },
+        'catalogue.book': {
+            'Meta': {'ordering': "('title',)", 'object_name': 'Book'},
+            '_short_html': ('django.db.models.fields.TextField', [], {}),
+            '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_tag_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
+            '_theme_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
+            'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
+            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+            'extra_info': ('catalogue.fields.JSONField', [], {}),
+            'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+            'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'medias': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalogue.BookMedia']", 'symmetrical': 'False', 'blank': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'children'", 'blank': 'True', 'null': 'True', 'to': "orm['catalogue.Book']"}),
+            'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
+            'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+            'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
+        },
+        'catalogue.bookmedia': {
+            'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'},
+            'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
+            'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
+            'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+        },
+        'catalogue.filerecord': {
+            'Meta': {'ordering': "('-time', '-slug', '-type')", 'object_name': 'FileRecord'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'sha1': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
+            'time': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_index': 'True'})
+        },
+        'catalogue.fragment': {
+            'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'},
+            '_short_html': ('django.db.models.fields.TextField', [], {}),
+            '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
+            'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'short_text': ('django.db.models.fields.TextField', [], {}),
+            'text': ('django.db.models.fields.TextField', [], {})
+        },
+        'catalogue.tag': {
+            'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'},
+            'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
+            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'main_page': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
+            'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
+        },
+        'catalogue.tagrelation': {
+            'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
+        },
+        '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 = ['catalogue']
index f2be7d1..ef923fa 100644 (file)
@@ -64,6 +64,9 @@ class Tag(TagBase):
     gazeta_link = models.CharField(blank=True, max_length=240)
     wiki_link = models.CharField(blank=True, max_length=240)
 
     gazeta_link = models.CharField(blank=True, max_length=240)
     wiki_link = models.CharField(blank=True, max_length=240)
 
+    created_at    = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+    changed_at    = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
+
     categories_rev = {
         'autor': 'author',
         'epoka': 'epoch',
     categories_rev = {
         'autor': 'author',
         'epoka': 'epoch',
@@ -220,7 +223,8 @@ class Book(models.Model):
     title         = models.CharField(_('title'), max_length=120)
     slug          = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
     description   = models.TextField(_('description'), blank=True)
     title         = models.CharField(_('title'), max_length=120)
     slug          = models.SlugField(_('slug'), max_length=120, unique=True, db_index=True)
     description   = models.TextField(_('description'), blank=True)
-    created_at    = models.DateTimeField(_('creation date'), auto_now_add=True)
+    created_at    = models.DateTimeField(_('creation date'), auto_now_add=True, db_index=True)
+    changed_at    = models.DateTimeField(_('creation date'), auto_now=True, db_index=True)
     _short_html   = models.TextField(_('short HTML'), editable=False)
     parent_number = models.IntegerField(_('parent number'), default=0)
     extra_info    = JSONField(_('extra information'))
     _short_html   = models.TextField(_('short HTML'), editable=False)
     parent_number = models.IntegerField(_('parent number'), default=0)
     extra_info    = JSONField(_('extra information'))