radio_fields = {'category': admin.HORIZONTAL}
+class MediaInline(admin.TabularInline):
+ model = BookMedia
+ extra = 0
+
+
class BookAdmin(TaggableModelAdmin):
tag_model = Tag
search_fields = ('title',)
ordering = ('title',)
- filter_horizontal = ('medias',)
+ inlines = [MediaInline]
def change_view(self, request, object_id, extra_context=None):
if not request.GET.has_key('advanced'):
self.form = forms.ModelForm
- self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file', 'medias',)
+ self.fields = ('title', 'description', 'gazeta_link', 'wiki_link', 'pdf_file',)
self.readonly_fields = ('title',)
else:
self.form = TaggableModelForm
extra_context=extra_context)
-
class FragmentAdmin(TaggableModelAdmin):
tag_model = Tag
ordering = ('book', 'anchor',)
-
-class BookMediaAdminForm(forms.ModelForm):
- books = forms.CharField(required=False)
-
- class Meta:
- model = BookMedia
-
-
-class MediaAdmin(admin.ModelAdmin):
- form = BookMediaAdminForm
-
- list_display = ('name', 'type', 'book_count', 'uploaded_at')
- ordering = ('name', 'type')
- search_fields = ('name',)
- fields = ('type', 'name', 'file', 'books')
- readonly_fields = ('books',)
-
-
-
admin.site.register(Tag, TagAdmin)
admin.site.register(Book, BookAdmin)
admin.site.register(Fragment, FragmentAdmin)
-admin.site.register(BookMedia, MediaAdmin)
return item.name
def item_categories(self, item):
- authors = set()
- for book in item.book_set.all():
- for author in book.tags.filter(category='author'):
- authors.add(author.name)
- return sorted(authors)
+ return sorted(set(author.name for author in
+ item.book.tags.filter(category='author')))
def item_description(self, item):
lines = []
return u'<br/>\n'.join(lines)
def item_link(self, item):
- if item.book_set.exists():
- return item.book_set.all()[0].get_absolute_url()
- else:
- return item.file.url
+ return item.book.get_absolute_url()
def item_guid(self, item):
return absolute_url(item.file.url)
book.epub_file.save('%s.epub' % book.slug, File(file(file_base + '.epub')))
if verbose:
print "Importing %s.epub" % file_base
- if os.path.isfile(file_base + '.odt'):
- book.odt_file.save('%s.odt' % book.slug, File(file(file_base + '.odt')))
- if verbose:
- print "Importing %s.odt" % file_base
if os.path.isfile(file_base + '.txt'):
book.txt_file.save('%s.txt' % book.slug, File(file(file_base + '.txt')))
if verbose:
print "Importing %s.txt" % file_base
- if os.path.isfile(os.path.join(dir_name, book.slug + '.mp3')):
- book.mp3_file.save('%s.mp3' % book.slug, File(file(os.path.join(dir_name, book.slug + '.mp3'))))
- if verbose:
- print "Importing %s.mp3" % book.slug
- if os.path.isfile(os.path.join(dir_name, book.slug + '.ogg')):
- book.ogg_file.save('%s.ogg' % book.slug, File(file(os.path.join(dir_name, book.slug + '.ogg'))))
- if verbose:
- print "Importing %s.ogg" % book.slug
- if os.path.isfile(os.path.join(dir_name, book.slug + '.daisy.zip')):
- book.ogg_file.save('%s.daisy.zip' % book.slug, File(file(os.path.join(dir_name, book.slug + '.daisy.zip'))))
- if verbose:
- print "Importing %s.daisy.zip" % book.slug
book.save()
--- /dev/null
+# -*- 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.
+#
+import os.path
+
+from django.core.management.base import BaseCommand
+from django.core.files import File
+from slughifi import slughifi
+
+from catalogue.models import Book, BookMedia
+from catalogue.utils import ExistingFile
+
+
+class Command(BaseCommand):
+ help = "Saves uploaded media with a given book and a given name. If media has a source SHA1 info - matching media is replaced."
+ args = 'path slug name'
+
+ def handle(self, *args, **options):
+ from django.db import transaction
+
+ path, slug, name = args
+
+ # Start transaction management.
+ transaction.commit_unless_managed()
+ transaction.enter_transaction_management()
+ transaction.managed(True)
+
+ book = Book.objects.get(slug=slug)
+
+ root, ext = os.path.splitext(path)
+ ext = ext.lower()
+ if ext:
+ ext = ext[1:]
+ if ext == 'zip':
+ ext = 'daisy'
+
+ source_sha1 = BookMedia.read_source_sha1(path, ext)
+ print "Source file SHA1:", source_sha1
+ try:
+ assert source_sha1
+ bm = book.media.get(type=ext, source_sha1=source_sha1)
+ print "Replacing media: %s (%s)" % (bm.name, ext)
+ except (AssertionError, BookMedia.DoesNotExist):
+ bm = BookMedia(book=book, type=ext, name=name)
+ print "Creating new media"
+ bm.file.save(slughifi(name), ExistingFile(path))
+ bm.save()
+ transaction.commit()
+ transaction.leave_transaction_management()
--- /dev/null
+# 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 'BookMedia.book'
+ db.add_column('catalogue_bookmedia', 'book', self.gf('django.db.models.fields.related.ForeignKey')(default=0, related_name='media', to=orm['catalogue.Book']), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'BookMedia.book'
+ db.delete_column('catalogue_bookmedia', 'book_id')
+
+
+ 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'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': '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', [], {'symmetrical': 'False', 'related_name': "'book_set'", 'blank': 'True', 'to': "orm['catalogue.BookMedia']"}),
+ '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'},
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
+ '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'}),
+ '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']
--- /dev/null
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ for media in orm.BookMedia.objects.all():
+ try:
+ media.book = media.book_set.all()[0]
+ media.save()
+ except IndexError, e:
+ media.delete()
+
+
+ def backwards(self, orm):
+ for media in orm.BookMedia.objects.all():
+ media.book_set = [media.book]
+
+
+ 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'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': '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', [], {'symmetrical': 'False', 'related_name': "'book_set'", 'blank': 'True', 'to': "orm['catalogue.BookMedia']"}),
+ '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'},
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
+ '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'}),
+ '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']
--- /dev/null
+# 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):
+
+ # Removing M2M table for field medias on 'Book'
+ db.delete_table('catalogue_book_medias')
+
+
+ def backwards(self, orm):
+
+ # Adding M2M table for field medias on 'Book'
+ db.create_table('catalogue_book_medias', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('book', models.ForeignKey(orm['catalogue.book'], null=False)),
+ ('bookmedia', models.ForeignKey(orm['catalogue.bookmedia'], null=False))
+ ))
+ db.create_unique('catalogue_book_medias', ['book_id', 'bookmedia_id'])
+
+
+ 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'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': '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'}),
+ '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'},
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
+ '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'}),
+ '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']
--- /dev/null
+# 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 'BookMedia.source_sha1'
+ db.add_column('catalogue_bookmedia', 'source_sha1', self.gf('django.db.models.fields.CharField')(max_length=40, null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'BookMedia.source_sha1'
+ db.delete_column('catalogue_bookmedia', 'source_sha1')
+
+
+ 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'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': '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'}),
+ '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'},
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
+ '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'"}),
+ 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+ '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'}),
+ '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']
from catalogue.fields import JSONField
from librarian import dcparser, html, epub, NoDublinCore
+import mutagen
from mutagen import id3
from slughifi import slughifi
name = models.CharField(_('name'), max_length="100")
file = models.FileField(_('file'), upload_to=book_upload_path())
uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
- extra_info = JSONField(_('extra information'), default='{}')
-
- def book_count(self):
- return self.book_set.count()
- book_count.short_description = _('book count')
-
- def books(self):
- return mark_safe('<br/>'.join("<a href='%s'>%s</a>" % (reverse('admin:catalogue_book_change', args=[b.id]), b.title) for b in self.book_set.all()))
- books.short_description = _('books')
+ extra_info = JSONField(_('extra information'), default='{}', editable=False)
+ book = models.ForeignKey('Book', related_name='media')
+ source_sha1 = models.CharField(null=True, blank=True, max_length=40, editable=False)
def __unicode__(self):
return "%s (%s)" % (self.name, self.file.name.split("/")[-1])
verbose_name = _('book media')
verbose_name_plural = _('book media')
- def save(self, force_insert=False, force_update=False, **kwargs):
- media = super(BookMedia, self).save(force_insert, force_update, **kwargs)
+ def save(self, *args, **kwargs):
+ super(BookMedia, self).save(*args, **kwargs)
+ extra_info = self.get_extra_info_value()
+ extra_info.update(self.read_meta())
+ self.set_extra_info_value(extra_info)
+ self.source_sha1 = self.read_source_sha1(self.file.path, self.type)
+ print self.extra_info, self.source_sha1
+ return super(BookMedia, self).save(*args, **kwargs)
+
+ def read_meta(self):
+ """
+ Reads some metadata from the audiobook.
+ """
+
+ artist_name = director_name = ''
if self.type == 'mp3':
- file = self.file
- extra_info = self.get_extra_info_value()
- extra_info.update(self.get_mp3_info())
- self.set_extra_info_value(extra_info)
- media = super(BookMedia, self).save(force_insert, force_update, **kwargs)
- return media
-
- def get_mp3_info(self):
- """Retrieves artist and director names from audio ID3 tags."""
- try:
- audio = id3.ID3(self.file.path)
- artist_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE1'))
- director_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE3'))
- except:
- artist_name = director_name = ''
+ try:
+ audio = id3.ID3(self.file.path)
+ artist_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE1'))
+ director_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE3'))
+ except:
+ pass
+ elif self.type == 'ogg':
+ try:
+ audio = mutagen.File(self.file.path)
+ artist_name = ', '.join(audio.get('artist', []))
+ director_name = ', '.join(audio.get('conductor', []))
+ except:
+ pass
+ else:
+ return {}
return {'artist_name': artist_name, 'director_name': director_name}
+ @staticmethod
+ def read_source_sha1(filepath, filetype):
+ """
+ Reads source file SHA1 from audiobok metadata.
+ """
+
+ if filetype == 'mp3':
+ try:
+ audio = id3.ID3(filepath)
+ return [t.data for t in audio.getall('PRIV')
+ if t.owner=='http://wolnelektury.pl?flac_sha1'][0]
+ except:
+ return None
+ elif filetype == 'ogg':
+ try:
+ audio = mutagen.File(filepath)
+ return audio.get('flac_sha1', [None])[0]
+ except:
+ return None
+ else:
+ return None
+
class Book(models.Model):
title = models.CharField(_('title'), max_length=120)
pdf_file = models.FileField(_('PDF file'), upload_to=book_upload_path('pdf'), blank=True)
epub_file = models.FileField(_('EPUB file'), upload_to=book_upload_path('epub'), blank=True)
txt_file = models.FileField(_('TXT file'), upload_to=book_upload_path('txt'), blank=True)
- # other files
- medias = models.ManyToManyField(BookMedia, blank=True)
-
+
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
objects = models.Manager()
tagged = managers.ModelTaggedItemManager(Tag)
else:
return False
else:
- if self.medias.filter(book=self, type=type).count() > 0:
+ if self.media.filter(type=type).exists():
return True
else:
return False
elif type == "pdf":
return self.pdf_file
else:
- return self.medias.filter(book=self, type=type)
+ return self.media.filter(type=type)
else:
return None
if self.has_media("txt"):
formats.append(u'<a href="%s">TXT</a>' % self.get_media('txt').url)
# other files
- for m in self.medias.order_by('type'):
+ for m in self.media.order_by('type'):
formats.append(u'<a href="%s">%s</a>' % (m.file.url, m.type.upper()))
formats = [mark_safe(format) for format in formats]
tags_updated.connect(_tags_updated_handler)
-def _m2m_changed_handler(sender, instance, action, reverse, pk_set, **kwargs):
- """ refresh all the short_html stuff on BookMedia delete """
- if sender == Book.medias.through and reverse and action == 'pre_clear':
- for book in instance.book_set.all():
- book.save()
-m2m_changed.connect(_m2m_changed_handler)
-
def _pre_delete_handler(sender, instance, **kwargs):
- """ explicitly clear m2m, so that Books can be refreshed """
+ """ refresh Book on BookMedia delete """
if sender == BookMedia:
- instance.book_set.clear()
+ instance.book.save()
pre_delete.connect(_pre_delete_handler)
def _post_save_handler(sender, instance, **kwargs):
""" refresh all the short_html stuff on BookMedia update """
if sender == BookMedia:
- for book in instance.book_set.all():
- book.save()
+ instance.book.save()
post_save.connect(_post_save_handler)
-
import time
from base64 import urlsafe_b64encode
+from django.core.files.uploadedfile import UploadedFile
from django.utils.hashcompat import sha_constructor
from django.conf import settings
result.setdefault(tag.category, []).append(tag)
return result
+
+class ExistingFile(UploadedFile):
+
+ def __init__(self, path, *args, **kwargs):
+ self.path = path
+ return super(ExistingFile, self).__init__(*args, **kwargs)
+
+ def temporary_file_path(self):
+ return self.path
+
+ def close(self):
+ pass
def audiobook_list(request):
- return book_list(request, Q(medias__type='mp3') | Q(medias__type='ogg'),
+ return book_list(request, Q(media__type='mp3') | Q(media__type='ogg'),
template_name='catalogue/audiobook_list.html')
def daisy_list(request):
- return book_list(request, Q(medias__type='daisy'),
+ return book_list(request, Q(media__type='daisy'),
template_name='catalogue/daisy_list.html')