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.cover import WLCover
14 from librarian.dcparser import BookInfo
16 for book in orm.Book.objects.filter(cover=''):
17 book_info = BookInfo.from_file(book.xml_file.path)
18 cover = WLCover(book_info).image()
20 cover.save(imgstr, 'png')
21 book.cover.save('book/png/%s.png' % book.slug,
22 ContentFile(imgstr.getvalue()))
25 def backwards(self, orm):
26 "Write your backwards methods here."
31 'Meta': {'object_name': 'Group'},
32 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
33 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
34 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
37 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
38 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
39 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
40 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
41 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
44 'Meta': {'object_name': 'User'},
45 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
46 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
47 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
48 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
49 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
50 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
51 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
52 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
53 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
54 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
55 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
56 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
57 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
60 'Meta': {'ordering': "('sort_key',)", 'unique_together': "[['slug', 'language']]", 'object_name': 'Book'},
61 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
62 'cover': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
63 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
64 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
65 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
66 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
67 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
68 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
69 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
70 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}),
71 'mobi_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
72 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}),
73 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
74 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
75 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
76 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
77 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
78 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
79 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
80 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
82 'catalogue.bookmedia': {
83 'Meta': {'ordering': "('type', 'name')", 'object_name': 'BookMedia'},
84 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'media'", 'to': "orm['catalogue.Book']"}),
85 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
86 'file': ('catalogue.fields.OverwritingFileField', [], {'max_length': '100'}),
87 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
88 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
89 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
90 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
91 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
93 'catalogue.fragment': {
94 'Meta': {'ordering': "('book', 'anchor')", 'object_name': 'Fragment'},
95 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
96 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
97 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
98 'short_text': ('django.db.models.fields.TextField', [], {}),
99 'text': ('django.db.models.fields.TextField', [], {})
102 'Meta': {'ordering': "('sort_key',)", 'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'},
103 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
104 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
105 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
106 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
107 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
108 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
109 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
110 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
111 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
112 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
113 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
114 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
116 'catalogue.tagrelation': {
117 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
118 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
119 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
120 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
121 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
123 'contenttypes.contenttype': {
124 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
125 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
126 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
127 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
128 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
132 complete_apps = ['catalogue']