3 from south.db import db
4 from south.v2 import DataMigration
5 from django.db import models
7 class Migration(DataMigration):
9 def forwards(self, orm):
10 "Write your forwards methods here."
11 from StringIO import StringIO
12 from django.core.files.base import ContentFile
13 from librarian import ValidationError
14 from librarian.cover import WLCover
15 from librarian.dcparser import BookInfo
17 for book in orm.Book.objects.filter(cover=None):
19 book_info = BookInfo.from_file(book.xml_file.path)
20 except ValidationError:
23 cover = WLCover(book_info).image()
25 cover.save(imgstr, 'png')
26 book.cover.save('book/png/%s.png' % book.slug,
27 ContentFile(imgstr.getvalue()))
30 def backwards(self, orm):
31 "Write your backwards methods here."
36 'Meta': {'object_name': 'Group'},
37 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
38 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
39 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
42 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
43 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
44 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
45 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
46 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
49 'Meta': {'object_name': 'User'},
50 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
51 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
52 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
53 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
54 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
55 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
56 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
57 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
58 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
59 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
60 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
61 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
62 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
65 'Meta': {'ordering': "('sort_key',)", 'unique_together': "[['slug', 'language']]", 'object_name': 'Book'},
66 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
67 'cover': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
68 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
69 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
70 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
71 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
72 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
73 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
74 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
75 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}),
76 'mobi_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
77 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}),
78 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
79 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
80 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
81 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
82 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
83 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
84 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
85 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
87 'catalogue.bookmedia': {
88 'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'},
89 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
90 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
91 'file': ('catalogue.fields.OverwritingFileField', [], {'max_length': '100'}),
92 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
93 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
94 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
95 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
96 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
98 'catalogue.fragment': {
99 'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'},
100 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
101 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
102 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
103 'short_text': ('django.db.models.fields.TextField', [], {}),
104 'text': ('django.db.models.fields.TextField', [], {})
107 'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'},
108 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
109 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
110 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
111 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
112 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
113 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
114 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
115 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
116 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
117 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
118 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
119 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
121 'catalogue.tagrelation': {
122 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
123 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
124 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
125 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
126 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
128 'contenttypes.contenttype': {
129 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
130 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
131 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
132 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
133 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
137 complete_apps = ['catalogue']