From b21787a590e6438bb5b1133164ede574bb04ba86 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 7 May 2012 01:14:47 -0400 Subject: [PATCH] Revert "Revert "Revert "[#28945859] removed description from edition. Be sure to do data migration before applying this schema migration""" This reverts commit c8be251ffa84dc49f233ab4f6cbd7eb67b8973dd. --- core/bookloader.py | 11 +- ...034_auto__del_field_edition_description.py | 218 ------------------ core/models.py | 10 + core/tests.py | 9 +- frontend/templates/work.html | 2 +- 5 files changed, 21 insertions(+), 229 deletions(-) delete mode 100644 core/migrations/0034_auto__del_field_edition_description.py diff --git a/core/bookloader.py b/core/bookloader.py index e32dc7a0..8254ab9d 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -189,6 +189,7 @@ def update_edition(edition): # update the edition edition.title = title + # edition.description = d.get('description') edition.publisher = d.get('publisher') edition.publication_date = d.get('publishedDate', '') edition.save() @@ -330,6 +331,7 @@ def add_by_googlebooks_id(googlebooks_id, work=None, results=None, isbn=None): # because this is a new google id, we have to create a new edition e = models.Edition(work=work) e.title = title + #e.description = d.get('description') e.publisher = d.get('publisher') e.publication_date = d.get('publishedDate', '') e.save() @@ -474,7 +476,7 @@ def add_openlibrary(work): if e[isbn_key].has_key('details'): if e[isbn_key]['details'].has_key('oclc_numbers'): for oclcnum in e[isbn_key]['details']['oclc_numbers']: - models.Identifier.get_or_add(type='oclc',value=oclcnum,work=work, edition=edition) + models.Identifier.get_or_add(type='oclc',value=oclcnum,work=edition.work, edition=edition) if e[isbn_key]['details'].has_key('identifiers'): ids = e[isbn_key]['details']['identifiers'] if ids.has_key('goodreads'): @@ -488,13 +490,11 @@ def add_openlibrary(work): if e[isbn_key]['details'].has_key('works'): work_key = e[isbn_key]['details']['works'].pop(0)['key'] logger.info("got openlibrary work %s for isbn %s", work_key, isbn_key) - models.Identifier.get_or_add(type='olwk',value=work_key,work=work) try: w = _get_json("http://openlibrary.org" + work_key,type='ol') if w.has_key('description'): - if not work.description or len(w['description']) > len(work.description): - work.description = w['description'] - work.save() + edition.description = w['description'] + edition.save() if w.has_key('subjects') and len(w['subjects']) > len(subjects): subjects = w['subjects'] except LookupFailure: @@ -511,6 +511,7 @@ def add_openlibrary(work): work.save() + models.Identifier.get_or_add(type='olwk',value=w['key'],work=work) # TODO: add authors here once they are moved from Edition to Work diff --git a/core/migrations/0034_auto__del_field_edition_description.py b/core/migrations/0034_auto__del_field_edition_description.py deleted file mode 100644 index d52ff9b6..00000000 --- a/core/migrations/0034_auto__del_field_edition_description.py +++ /dev/null @@ -1,218 +0,0 @@ -# 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): - - # Deleting field 'Edition.description' - db.delete_column('core_edition', 'description') - - - def backwards(self, orm): - - # Adding field 'Edition.description' - db.add_column('core_edition', 'description', self.gf('django.db.models.fields.TextField')(default='', null=True), keep_default=False) - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - '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', [], {'unique': 'True', 'max_length': '30'}) - }, - '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'}) - }, - 'core.author': { - 'Meta': {'object_name': 'Author'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'editions': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'authors'", 'symmetrical': 'False', 'to': "orm['core.Edition']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '500'}) - }, - 'core.campaign': { - 'Meta': {'object_name': 'Campaign'}, - 'activated': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), - 'amazon_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'deadline': ('django.db.models.fields.DateTimeField', [], {}), - 'description': ('django.db.models.fields.TextField', [], {'null': 'True'}), - 'details': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'null': 'True', 'to': "orm['core.Edition']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'left': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '14', 'decimal_places': '2'}), - 'license': ('django.db.models.fields.CharField', [], {'default': "'CC BY-NC-ND'", 'max_length': '255'}), - 'managers': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'campaigns'", 'symmetrical': 'False', 'to': "orm['auth.User']"}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True'}), - 'paypal_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'status': ('django.db.models.fields.CharField', [], {'default': "'INITIALIZED'", 'max_length': '15', 'null': 'True'}), - 'target': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '14', 'decimal_places': '2'}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'to': "orm['core.Work']"}) - }, - 'core.campaignaction': { - 'Meta': {'object_name': 'CampaignAction'}, - 'campaign': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'actions'", 'to': "orm['core.Campaign']"}), - 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'type': ('django.db.models.fields.CharField', [], {'max_length': '15'}) - }, - 'core.celerytask': { - 'Meta': {'object_name': 'CeleryTask'}, - 'active': ('django.db.models.fields.NullBooleanField', [], {'default': 'True', 'null': 'True', 'blank': 'True'}), - 'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 5, 7, 0, 36, 13, 555983)', 'auto_now_add': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'null': 'True'}), - 'function_args': ('django.db.models.fields.IntegerField', [], {'null': 'True'}), - 'function_name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'task_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tasks'", 'null': 'True', 'to': "orm['auth.User']"}) - }, - 'core.claim': { - 'Meta': {'object_name': 'Claim'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'rights_holder': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'claim'", 'to': "orm['core.RightsHolder']"}), - 'status': ('django.db.models.fields.CharField', [], {'default': "'pending'", 'max_length': '7'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'claim'", 'to': "orm['auth.User']"}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'claim'", 'to': "orm['core.Work']"}) - }, - 'core.ebook': { - 'Meta': {'object_name': 'Ebook'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ebooks'", 'to': "orm['core.Edition']"}), - 'format': ('django.db.models.fields.CharField', [], {'max_length': '25'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'provider': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'rights': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), - 'url': ('django.db.models.fields.URLField', [], {'max_length': '1024'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}) - }, - 'core.edition': { - 'Meta': {'object_name': 'Edition'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'public_domain': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), - 'publication_date': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}), - 'publisher': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'editions'", 'null': 'True', 'to': "orm['core.Work']"}) - }, - 'core.identifier': { - 'Meta': {'unique_together': "(('type', 'value'),)", 'object_name': 'Identifier'}, - 'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'identifiers'", 'null': 'True', 'to': "orm['core.Edition']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'type': ('django.db.models.fields.CharField', [], {'max_length': '4'}), - 'value': ('django.db.models.fields.CharField', [], {'max_length': '31'}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'identifiers'", 'to': "orm['core.Work']"}) - }, - 'core.premium': { - 'Meta': {'object_name': 'Premium'}, - 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '0'}), - 'campaign': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'premiums'", 'null': 'True', 'to': "orm['core.Campaign']"}), - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.TextField', [], {'null': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'limit': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'type': ('django.db.models.fields.CharField', [], {'max_length': '2'}) - }, - 'core.rightsholder': { - 'Meta': {'object_name': 'RightsHolder'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'email': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'rights_holder'", 'to': "orm['auth.User']"}), - 'rights_holder_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - 'core.subject': { - 'Meta': {'ordering': "['name']", 'object_name': 'Subject'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'}), - 'works': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'subjects'", 'symmetrical': 'False', 'to': "orm['core.Work']"}) - }, - 'core.userprofile': { - 'Meta': {'object_name': 'UserProfile'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'facebook_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), - 'goodreads_auth_secret': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'goodreads_auth_token': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'goodreads_user_id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}), - 'goodreads_user_link': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - 'goodreads_user_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - 'home_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'librarything_id': ('django.db.models.fields.CharField', [], {'max_length': '31', 'blank': 'True'}), - 'pic_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), - 'tagline': ('django.db.models.fields.CharField', [], {'max_length': '140', 'blank': 'True'}), - 'twitter_id': ('django.db.models.fields.CharField', [], {'max_length': '15', 'blank': 'True'}), - 'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'profile'", 'unique': 'True', 'to': "orm['auth.User']"}) - }, - 'core.waswork': { - 'Meta': {'object_name': 'WasWork'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'moved': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}), - 'was': ('django.db.models.fields.IntegerField', [], {'unique': 'True'}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Work']"}) - }, - 'core.wishes': { - 'Meta': {'object_name': 'Wishes', 'db_table': "'core_wishlist_works'"}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'source': ('django.db.models.fields.CharField', [], {'max_length': '15', 'blank': 'True'}), - 'wishlist': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Wishlist']"}), - 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'wishes'", 'to': "orm['core.Work']"}) - }, - 'core.wishlist': { - 'Meta': {'object_name': 'Wishlist'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'wishlist'", 'unique': 'True', 'to': "orm['auth.User']"}), - 'works': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'wishlists'", 'symmetrical': 'False', 'through': "orm['core.Wishes']", 'to': "orm['core.Work']"}) - }, - 'core.work': { - 'Meta': {'ordering': "['title']", 'object_name': 'Work'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'language': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), - 'num_wishes': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'openlibrary_lookup': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}) - } - } - - complete_apps = ['core'] diff --git a/core/models.py b/core/models.py index ede7643f..cc787dc7 100755 --- a/core/models.py +++ b/core/models.py @@ -451,6 +451,15 @@ class Work(models.Model): self.num_wishes = Wishes.objects.filter(work=self).count() self.save() + def longest_description(self): + """get the longest description from an edition of this work + """ + description = "" + for edition in self.editions.all(): + if len(edition.description) > len(description): + description = edition.description + return description + def first_isbn_13(self): try: return self.identifiers.filter(type='isbn')[0].value @@ -492,6 +501,7 @@ class Subject(models.Model): class Edition(models.Model): created = models.DateTimeField(auto_now_add=True) title = models.CharField(max_length=1000) + description = models.TextField(default='', null=True) publisher = models.CharField(max_length=255, null=True) publication_date = models.CharField(max_length=50, null=True) public_domain = models.NullBooleanField(null=True) diff --git a/core/tests.py b/core/tests.py index 1dee0e09..16c249aa 100755 --- a/core/tests.py +++ b/core/tests.py @@ -102,7 +102,7 @@ class BookLoaderTests(TestCase): self.assertTrue(edition.work.publication_date) edition.publication_date = None self.assertTrue(edition.work.publication_date) - self.assertTrue(len(edition.work.description) > 20) + self.assertTrue(len(edition.work.longest_description()) > 20) self.assertTrue(edition.work.identifiers.filter(type='oclc')[0]) @@ -281,10 +281,9 @@ class BookLoaderTests(TestCase): subjects = [s.name for s in work.subjects.all()] self.assertTrue(len(subjects) > 10) self.assertTrue('Science fiction' in subjects) - self.assertTrue('/works/OL27258W' in work.identifiers.filter(type='olwk').values_list('value',flat=True) ) - self.assertTrue('14770' in work.identifiers.filter(type='gdrd').values_list('value',flat=True)) - self.assertTrue('609' in work.identifiers.filter(type='ltwk').values_list('value',flat=True)) - + self.assertEqual(work.openlibrary_id, '/works/OL27258W') + self.assertEqual(work.goodreads_id, '14770') + self.assertEqual(work.librarything_id, '609') def test_load_gutenberg_edition(self): """Let's try this out for Moby Dick""" diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 5784f791..66ea4244 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -234,7 +234,7 @@ $j(document).ready(function(){ {{ work.last_campaign.description|safe }} {% else %}

{{work.title}}

-

{{ work.description|safe }} +

{{ work.longest_description|safe }} {% endif %}