add acq handling to download

needs migration. should migrate core back to 0052 to refresh acq table

download page no longer passes ebook ids to send_to_kindle, url
calculations are now done in view
pull/1/head
eric 2013-09-05 22:54:11 -04:00
parent 5bb359fb1e
commit b801eb4927
11 changed files with 541 additions and 144 deletions

View File

@ -0,0 +1,320 @@
# -*- coding: 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 'Acq.nonce'
db.add_column('core_acq', 'nonce',
self.gf('django.db.models.fields.CharField')(max_length=32, null=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Acq.nonce'
db.delete_column('core_acq', 'nonce')
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'})
},
'booxtream.boox': {
'Meta': {'object_name': 'Boox'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'download_link_epub': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True'}),
'download_link_mobi': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True'}),
'downloads_remaining': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
'expirydays': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'referenceid': ('django.db.models.fields.CharField', [], {'max_length': '32'})
},
'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.acq': {
'Meta': {'object_name': 'Acq'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'license': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1'}),
'nonce': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'acqs'", 'to': "orm['auth.User']"}),
'watermarked': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['booxtream.Boox']", 'null': 'True'}),
'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'acqs'", 'to': "orm['core.Work']"})
},
'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.badge': {
'Meta': {'object_name': 'Badge'},
'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '72', 'blank': 'True'})
},
'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'}),
'cc_date_initial': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'deadline': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True'}),
'description': ('ckeditor.fields.RichTextField', [], {'null': 'True'}),
'details': ('ckeditor.fields.RichTextField', [], {'null': 'True', 'blank': 'True'}),
'dollar_per_day': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'null': 'True', 'to': "orm['core.Edition']"}),
'email': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'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'}),
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'null': 'True', 'to': "orm['core.Publisher']"}),
'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'}),
'type': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1'}),
'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(2013, 8, 29, 0, 0)', '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'}),
'download_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'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', 'db_index': 'True'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '1024'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'})
},
'core.ebookfile': {
'Meta': {'object_name': 'EbookFile'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'ebook_files'", 'to': "orm['core.Edition']"}),
'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'format': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'core.edition': {
'Meta': {'object_name': 'Edition'},
'cover_image': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'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', 'blank': 'True'}),
'publisher_name': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'editions'", 'null': 'True', 'to': "orm['core.PublisherName']"}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'unglued': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'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.key': {
'Meta': {'object_name': 'Key'},
'encrypted_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'core.libpref': {
'Meta': {'object_name': 'Libpref'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'marc_link_target': ('django.db.models.fields.CharField', [], {'default': "'UNGLUE'", 'max_length': '6'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'libpref'", 'unique': 'True', 'to': "orm['auth.User']"})
},
'core.marcrecord': {
'Meta': {'object_name': 'MARCRecord'},
'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'MARCrecords'", 'null': 'True', 'to': "orm['core.Edition']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'link_target': ('django.db.models.fields.CharField', [], {'default': "'DIRECT'", 'max_length': '6'}),
'mrc_record': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'xml_record': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
},
'core.offer': {
'Meta': {'object_name': 'Offer'},
'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'license': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1'}),
'price': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '6', 'decimal_places': '2'}),
'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'offers'", '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.press': {
'Meta': {'object_name': 'Press'},
'date': ('django.db.models.fields.DateField', [], {}),
'highlight': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
'note': ('django.db.models.fields.CharField', [], {'max_length': '140', 'blank': 'True'}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '140'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '140'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'core.publisher': {
'Meta': {'object_name': 'Publisher'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'logo_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'key_publisher'", 'to': "orm['core.PublisherName']"}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'})
},
'core.publishername': {
'Meta': {'object_name': 'PublisherName'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'publisher': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'alternate_names'", 'null': 'True', 'to': "orm['core.Publisher']"})
},
'core.rightsholder': {
'Meta': {'object_name': 'RightsHolder'},
'can_sell': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'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'},
'avatar_source': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1', 'null': 'True'}),
'badges': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'holders'", 'symmetrical': 'False', 'to': "orm['core.Badge']"}),
'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'}),
'kindle_email': ('django.db.models.fields.EmailField', [], {'max_length': '254', 'blank': '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', 'blank': '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', 'db_index': 'True'}),
'openlibrary_lookup': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'})
}
}
complete_apps = ['core']

View File

@ -23,6 +23,7 @@ from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import F, Q, get_model
from django.db.models.signals import post_save
from django.utils.translation import ugettext_lazy as _
'''
@ -254,8 +255,22 @@ class Acq(models.Model):
license = models.PositiveSmallIntegerField(null = False, default = INDIVIDUAL,
choices=CHOICES)
watermarked = models.ForeignKey("booxtream.Boox", null=True)
nonce = models.CharField(max_length=32, null=True)
@property
def expired(self):
if self.expires is None:
return False
else:
return self.expires < datetime.now()
def get_mobi_url(self):
return self.get_watermarked().download_link_mobi
def get_epub_url(self):
return self.get_watermarked().download_link_epub
def get_watermarked(self):
if self.watermarked == None or self.watermarked.expired:
params={
'customeremailaddress': self.user.email,
@ -272,7 +287,17 @@ class Acq(models.Model):
}
self.watermarked = watermarker.platform(epubfile= self.work.ebookfiles()[0].file, **params)
self.save()
return self.watermarked.download_link_epub
return self.watermarked
def _hash(self):
return hashlib.md5('%s:%s:%s'%(self.user.id,self.work.id,self.created)).hexdigest()
def add_acq_nonce(sender, instance, created, **kwargs):
if created:
instance.nonce=instance._hash()
instance.save()
post_save.connect(add_acq_nonce,sender=Acq)
class Campaign(models.Model):
LICENSE_CHOICES = settings.CCCHOICES

View File

@ -188,7 +188,7 @@ def handle_transaction_charged(sender,transaction=None, **kwargs):
transaction.campaign.update_left()
notification.send([transaction.user], "purchase_complete", {'transaction':transaction}, True)
from regluit.core.tasks import emit_notifications, watermark_acq
watermark_acq(new_acq).delay()
watermark_acq.delay(new_acq)
emit_notifications.delay()
transaction_charged.connect(handle_transaction_charged)

View File

@ -123,5 +123,5 @@ def notify_ending_soon():
@task
def watermark_acq(acq):
acq.get_epub_url()
acq.get_watermarked()

View File

@ -828,7 +828,9 @@ class EbookFileTests(TestCase):
ebf.save()
acq=Acq.objects.create(user=u,work=w,license=TESTING)
url= acq.get_epub_url()
self.assertIsNot(acq.nonce, None)
url= acq.get_watermarked().download_link_epub
self.assertRegexpMatches(url,'download.booxtream.com/')

View File

@ -1,5 +1,4 @@
{% extends "base.html" %}
{% load purchased %}
{% with work.title as title %}
{% block title %}
@ -24,7 +23,6 @@ $j(document).ready(function() {
<div id="lightbox_content">
<div class="border">
<h2>Downloads for <I><a href="{% url work work.id %}">{{ work.title }}</a></i></h2>
{% purchased %}
<div class="sharing ebook_download_container">
<h3 class="jsmod-title"><span>Share</span></h3>
<ul class="social menu">
@ -37,25 +35,25 @@ $j(document).ready(function() {
<div id="widgetcode2">Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;iframe src="https://{{ request.META.HTTP_HOST }}/api/widget/{{ work.first_isbn_13 }}/" width="152" height="325" frameborder="0"&gt;&lt;/iframe&gt;</textarea></div>
</ul>
</div>
{% if readmill_epub_url or kindle_ebook_id %}
{% if readmill_epub_url or can_kindle %}
<div class="one_click clearfix">
<h3>One-click options</h3>
{% if kindle_ebook_id %}
{% if can_kindle %}
<div id="kindle_div">
{% if request.user.is_authenticated and request.user.profile.kindle_email %}
<div class="yes_js">
<div id="kindle" class="btn_support authenticated" title="{{ kindle_ebook_id }}" >
<div id="kindle" class="btn_support authenticated" title="{{ work.id }}" >
<a>Send to Kindle</a>
</div>
</div>
<div class="no_js">
<form method="POST" class="btn_support" action="{% url send_to_kindle kindle_ebook_id 0 %}">
<form method="POST" class="btn_support" action="{% url send_to_kindle work.id 0 %}">
<input type="submit" value="Send to Kindle">
</form>
</div>
{% else %}
<div class="btn_support kindle">
<a href="{% url kindle_config_download kindle_ebook_id %}">Set up Kindle </a>
<a href="{% url kindle_config_download work.id %}">Set up Kindle </a>
</div>
{% endif %}
</div>
@ -70,43 +68,58 @@ $j(document).ready(function() {
{% endif %}
</div>
{% endif %}
{% if unglued_ebooks or other_ebooks %}
<div class="ebook_download_container">
{% endif %}
{% if unglued_ebooks %}
<h3>Download the unglued edition</h3>
<div class="ebook_download">
{% for ebook in unglued_ebooks %}
<a href="{% url download_ebook ebook.id %}">
<img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{% url download_ebook ebook.id %}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.format }}" title="{{ ebook.format }}" /></a>
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }}</a>
{% if not forloop.last %}<br /><br />{% endif %}
{% endfor %}
</div>
{% endif %}
{% if other_ebooks %}
{% if unglued_ebook %}
<h4>Download other freely available editions</h4>
{% else %}
<h4>Download freely available editions</h4>
<div class="ebook_download_container">
{% if unglued_ebooks or other_ebooks or acq %}
{% if unglued_ebooks %}
<h3>Download the unglued edition</h3>
<div class="ebook_download">
{% for ebook in unglued_ebooks %}
<a href="{% url download_ebook ebook.id %}">
<img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{% url download_ebook ebook.id %}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.format }}" title="{{ ebook.format }}" /></a>
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }}</a>
{% if not forloop.last %}<br /><br />{% endif %}
{% endfor %}
</div>
{% endif %}
<div class="ebook_download">
{% for ebook in other_ebooks %}
<a href="{% url download_ebook ebook.id %}">
<img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{% url download_ebook ebook.id %}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.format }} at {{ebook.provider}}" title="{{ ebook.format }} at {{ebook.provider}}" /></a>
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }} at {{ ebook.provider }}</a>
{% if not forloop.last %}<br /><br />{% endif %}
{% endfor %}
</div>
{% endif %}
{% if unglued_ebooks or other_ebooks %}
{% if other_ebooks %}
{% if unglued_ebook %}
<h4>Download other freely available editions</h4>
{% else %}
<h4>Download freely available editions</h4>
{% endif %}
<div class="ebook_download">
{% for ebook in other_ebooks %}
<a href="{% url download_ebook ebook.id %}">
<img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{% url download_ebook ebook.id %}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.format }} at {{ebook.provider}}" title="{{ ebook.format }} at {{ebook.provider}}" /></a>
<a href="{% url download_ebook ebook.id %}">{{ ebook.format }} at {{ ebook.provider }}</a>
{% if not forloop.last %}<br /><br />{% endif %}
{% endfor %}
</div>
{% endif %}
{% if acq %}
<h3>Download your ebook!</h3>
<div class="ebook_download">
<a href="{{ formats.epub }}"><img src="/static/images/epub32.png" height="32" alt="epub" title="epub" /></a>
<a href="{{ formats.epub }}">EPUB</a> (for iBooks, Nook, Kobo)
<br /><br />
<a href="{{ formats.mobi }}"><img src="/static/images/mobi32.png" height="32" alt="mobi" title="mobi" /></a>
<a href="{{ formats.mobi }}">MOBI</a> (for Kindle)
</div>
{% endif %}
{% else %}
<div class="border">
<p id="content-block">There are no freely available downloads of <I>{{ work.title }}</I> right now. {% if not work in request.user.wishlist.works.all %}Would you like there to be? <a class="add-wishlist"><span class="work_id" id="w{{ work.id }}">Add this book to your wishlist.</span></a>{% else %}Ask your friends to add it to their wishlists!{% endif %}</p>
<p>If you know of a Creative-Commons-licensed or US public domain edition of this book, you can add it through the <a href="{% url work work.id %}?tab=4">More... tab of the book page</a>.</p>
</div>
</div>
{% endif %}
<div class="clearfix"></div>
</div>
{% if unglued_ebooks or other_ebooks %}
{% if unglued_ebooks or other_ebooks or acq %}
<div class="border">
<h3>Need instructions?</h3>
<div class="instructions">
@ -119,11 +132,11 @@ $j(document).ready(function() {
To read this ebook you should open this page in safari. <img width="500" height="403" src="/static/images/open_safari.png" alt="how to open in safari" /><br clear="left" />
{% endif %}
{% if formats.pdf %}
You should also be able to use the <a href="{% url download_ebook formats.pdf.id %}">pdf</a> file.
You should also be able to use the <a href="{{ formats.pdf }}">pdf</a> file.
{% else %}{% if formats.html %}
You can read the <a href="{% url download_ebook formats.html.id %}">HTML version</a> of this book right here in this browser.
You can read the <a href="{{ formats.html }}">HTML version</a> of this book right here in this browser.
{% else %}{% if formats.text %}
You can read the <a href="{% url download_ebook formats.text.id %}">text version</a> of this book right here in this browser.
You can read the <a href="{{ formats.text }}">text version</a> of this book right here in this browser.
{% endif %}{% endif %}{% endif %}
</p>
<p class="other_instructions_paragraph">
@ -135,12 +148,12 @@ $j(document).ready(function() {
<h4>iOS devices</h4>
{% if formats.epub %}
<p>
You may already have an app which reads ebooks. Download the <a href="{% url download_ebook formats.epub.id %}">epub file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
You may already have an app which reads ebooks. Download the <a href="{{ formats.epub }}">epub file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
</p>
<p class="ebook_download logo"><img src="/static/images/ibooks_logo.jpeg" alt="iBooks Logo" />iBooks</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/ibooks/id364709193?mt=8">Download the free iBooks app</a> from the App Store.</li>
<li>Download the <a href="{% url download_ebook formats.epub.id %}">epub file</a>.</li>
<li>Download the <a href="{{ formats.epub }}">epub file</a>.</li>
<li>You will be given the option of opening the file in iBooks.</li>
</ul>
<p class="ebook_download logo"><img src="/static/images/readmill_logo.jpg" alt="iBooks Logo" />Readmill is another great option. </p>
@ -151,21 +164,21 @@ $j(document).ready(function() {
</ul>
{% else %}{% if formats.pdf %}
<p>
You may already have an app which reads ebooks. Download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
You may already have an app which reads ebooks. Download the <a href="{{ formats.pdf }}">pdf file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
</p>
<p class="ebook_download logo"><img src="/static/images/ibooks_logo.jpeg" alt="iBooks Logo" />iBooks</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/ibooks/id364709193?mt=8">Download the free iBooks app</a> from the App Store.</li>
<li>Download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a>.</li>
<li>Download the <a href="{{ formats.pdf }}">pdf file</a>.</li>
<li>You will be given the option of opening the file in iBooks.</li>
</ul>
{% else %}{% if formats.html %}
<p>
Download the <a href="{% url download_ebook formats.html.id %}">HTML version</a>.
Download the <a href="{{ formats.html }}">HTML version</a>.
</p>
{% else %}{% if formats.text %}
<p>
Download the <a href="{% url download_ebook formats.text.id %}">text version</a>.
Download the <a href="{{ formats.text }}">text version</a>.
</p>
{% else %}
<p>
@ -181,33 +194,33 @@ $j(document).ready(function() {
<h4>Android devices</h4>
{% if formats.epub %}
<p>
You may already have an app which reads ebooks. Download the <a href="{% url download_ebook formats.epub.id %}">epub file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
You may already have an app which reads ebooks. Download the <a href="{{ formats.epub }}">epub file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
</p>
<p class="ebook_download logo"><img src="/static/images/aldiko_logo.png" alt="Aldiko Logo" />Aldiko</p>
<ul>
<li><a href="http://www.aldiko.com/download.html">Download the free Aldiko app.</a></li>
<li>Download the <a href="{% url download_ebook formats.epub.id %}">epub file</a>.</li>
<li>Download the <a href="{{ formats.epub }}">epub file</a>.</li>
<li>When the download is complete, tap it in your notifications menu. It will be added to Aldiko, ready to read next time you open the app.</li>
</ul>
{% else %}{% if formats.pdf %}
<p>
You may already have an app which reads ebooks. Download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
You may already have an app which reads ebooks. Download the <a href="{{ formats.pdf }}">pdf file</a> and see if you're offered an option for opening the file. If so, you're done! If not...
</p>
<p class="ebook_download logo"><img src="/static/images/aldiko_logo.png" alt="Aldiko Logo" />Aldiko</p>
<ul>
<li><a href="http://www.aldiko.com/download.html">Download the free Aldiko app.</a></li>
<li>Download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a>.</li>
<li>Download the <a href="{{ formats.pdf }}">pdf file</a>.</li>
<li>When the download is complete, tap it in your notifications menu. It will be added to Aldiko, ready to read next time you open the app.</li>
</ul>
{% else %}{% if formats.html %}
<p>
Download the <a href="{% url download_ebook formats.html.id %}">HTML version</a>.
Download the <a href="{{ formats.html }}">HTML version</a>.
</p>
{% else %}{% if formats.text %}
<p>
Download the <a href="{% url download_ebook formats.text.id %}">text version</a>.
Download the <a href="{{ formats.text }}">text version</a>.
</p>
{% else %}
<p>
@ -223,29 +236,33 @@ $j(document).ready(function() {
<h4>Reading on a PC, Mac, or Linux</h4>
{% if formats.pdf %}
<p>
You probably already have an app which reads PDFs. Download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a> and open it.
You probably already have an app which reads PDFs. Download the <a href="{{ formats.pdf }}">pdf file</a> and open it.
</p>
{% else %}{% if formats.epub %}
<p class="ebook_download logo"><img src="/static/images/calibre_logo.png" alt="Calibre Logo" />Calibre</p>
<ul>
<li><a href="http://calibre-ebook.com/download">Download the free Calibre app.</a></li>
<li>Download the <a href="{% url download_ebook formats.epub.id %}">epub file</a>.</li>
<li>Download the <a href="{{ formats.epub }}">epub file</a>.</li>
<li>Open the file in Calibre.</li>
</ul>
{% else %}{% if formats.mobi %}
<p class="ebook_download logo"><img src="/static/images/calibre_logo.png" alt="Calibre Logo" />Calibre</p>
<ul>
<li><a href="http://calibre-ebook.com/download">Download the free Calibre app.</a></li>
<li>Download the <a href="{% url download_ebook formats.mobi.id %}">mobi file</a>.</li>
{% if acq %}
<li>Download the <a href="{{ formats.mobi }}">mobi file</a>.</li>
{% else %}
<li>Download the <a href="{{ formats.mobi }}">mobi file</a>.</li>
{% endif %}
<li>Open the file in Calibre.</li>
</ul>
{% else %}{% if formats.html %}
<p>
You can read the <a href="{% url download_ebook formats.html.id %}">HTML version</a> right here in your browser.
You can read the <a href="{{ formats.html }}">HTML version</a> right here in your browser.
</p>
{% else %}
<p>
You can read the <a href="{% url download_ebook formats.text.id %}">text version</a> right here in your browser.
You can read the <a href="{{ formats.text }}">text version</a> right here in your browser.
</p>
{% endif %}{% endif %}{% endif %}{% endif %}
<p class="other_instructions_paragraph">
@ -260,16 +277,16 @@ $j(document).ready(function() {
<ul>
<li>
{% if formats.mobi %}
<b>Kindle</b>: download the <a href="{% url download_ebook formats.mobi.id %}">mobi file</a> to your computer, or use the <i>Send To Kindle</i> button above.
<b>Kindle</b>: download the <a href="{{ formats.mobi }}">mobi file</a> to your computer, or use the <i>Send To Kindle</i> button above.
{% else %}{% if formats.pdf %}
<b>Kindle</b>: download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a> to your computer, or use the <i>Send To Kindle</i> button above.
<b>Kindle</b>: download the <a href="{{ formats.pdf }}">pdf file</a> to your computer, or use the <i>Send To Kindle</i> button above.
{% else %}
<b>Kindle</b>: We're sorry; we don't have a version suitable for Kindle.
{% endif %}{% endif %}
{% if formats.epub %}
<b>All other ereaders</b>: download the <a href="{% url download_ebook formats.epub.id %}">epub file</a> to your computer.
<b>All other ereaders</b>: download the <a href="{{ formats.epub }}">epub file</a> to your computer.
{% else %}{% if formats.pdf %}
<b>All other ereaders</b>: download the <a href="{% url download_ebook formats.pdf.id %}">pdf file</a> to your computer.
<b>All other ereaders</b>: download the <a href="{{ formats.pdf }}">pdf file</a> to your computer.
{% else %}
<b>All other ereaders</b>: We're sorry; we don't have a version suitable for your device.
{% endif %}{% endif %}
@ -314,11 +331,6 @@ $j(document).ready(function() {
</div>
</div>
{% else %}
<div class="border">
<p id="content-block">There are no freely available downloads of <I>{{ work.title }}</I> right now. {% if not work in request.user.wishlist.works.all %}Would you like there to be? <a class="add-wishlist"><span class="work_id" id="w{{ work.id }}">Add this book to your wishlist.</span></a>{% else %}Ask your friends to add it to their wishlists!{% endif %}</p>
<p>If you know of a Creative-Commons-licensed or US public domain edition of this book, you can add it through the <a href="{% url work work.id %}?tab=4">More... tab of the book page</a>.</p>
</div>
{% endif %}
</div>
</div>

View File

@ -9,9 +9,9 @@
var $j = jQuery.noConflict();
$j(document).ready(function() {
var kindle_ebook_id = {{ kindle_ebook_id }};
if(kindle_ebook_id) {
$j.post('/send_to_kindle/' + kindle_ebook_id + '/1/', function(data) {
var work_id = {{ work.id }};
if(work_id) {
$j.post('/send_to_kindle/' + work_id + '/1/', function(data) {
$j('#replace_me').html(data);
return false;
});
@ -24,7 +24,7 @@
<h2>Kindle email change successful</h2>
<div id="content-main">
<p>Hooray! We can now send unglued ebooks to you at {{ request.user.profile.kindle_email }}.</p>
{% if kindle_ebook_id %}
{% if work %}
<p>
We're emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>...
</p>

View File

@ -8,9 +8,9 @@
var $j = jQuery.noConflict();
$j(document).ready(function() {
var kindle_ebook_id = {{ kindle_ebook_id }};
if(kindle_ebook_id) {
$j.post('/send_to_kindle/' + kindle_ebook_id + '/1/', function(data) {
var work_id = {{ work.id }};
if(work_id) {
$j.post('/send_to_kindle/' + work_id + '/1/', function(data) {
$j('#replace_me').html(data);
return false;
});
@ -24,7 +24,7 @@
<h2>Add or change your Kindle email</h2>
<div id="content-main">
{% if kindle_email %}
{% if kindle_ebook_id %}
{% if work %}
<p>
Welcome back, {{ user.username }}! We're sending <I><a href="{% url work work.id %}">{{ work.title }}</a></I> to {{ kindle_email }}.
</p>
@ -45,8 +45,8 @@
</p>
<p>Then, enter your Kindle email address below:</p>
{% endif %}
{% if kindle_ebook_id %}
<form method="post" action="{% url kindle_config_download kindle_ebook_id %}">{% csrf_token %}
{% if work %}
<form method="post" action="{% url kindle_config_download work.id %}">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% if kindle_email %}Change{% else %}Add{% endif %}" />
</form>

View File

@ -94,7 +94,8 @@ urlpatterns = patterns(
url(r"^new_edition/(?P<work_id>)(?P<edition_id>)$", "new_edition", name="new_edition"),
url(r"^new_edition/(?P<work_id>\d*)/(?P<edition_id>\d*)$", "new_edition", name="new_edition"),
url(r"^googlebooks/(?P<googlebooks_id>.+)/$", "googlebooks", name="googlebooks"),
url(r"^download_ebook/(?P<ebook_id>\d+)/$", "download_ebook", name="download_ebook"),
url(r"^download_ebook/(?P<ebook_id>\w+)/$", "download_ebook", name="download_ebook"),
url(r"^download_ebook/acq/(?P<format>\w+)/(?P<nonce>\w+)/$", "download_acq", name="download_acq"),
url(r"^donation/$", login_required(DonationView.as_view()), name="donation"),
url(r"^donation/credit/(?P<token>.+)/$", login_required(DonationCredit.as_view()), name="donation_credit"),
url(r"^pledge/(?P<work_id>\d+)/$", login_required(PledgeView.as_view(),login_url='/accounts/login/pledge/'), name="pledge"),
@ -136,8 +137,8 @@ urlpatterns = patterns(
url(r"^press/$","press", name="press"),
url(r"^press_submitterator/$","press_submitterator", name="press_submitterator"),
url(r"^accounts/edit/kindle_config/$", "kindle_config", name="kindle_config"),
url(r"^accounts/edit/kindle_config/(?P<kindle_ebook_id>\d+)/$", "kindle_config", name="kindle_config_download"),
url(r"^send_to_kindle/(?P<kindle_ebook_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"),
url(r"^accounts/edit/kindle_config/(?P<work_id>\d+)/$", "kindle_config", name="kindle_config_download"),
url(r"^send_to_kindle/(?P<work_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"),
url(r"^send_to_kindle/result/(?P<message>\d)/$", "send_to_kindle_graceful", name="send_to_kindle_graceful"),
url(r"^marc/$", "marc", name="marc"),
url(r"^marc/ungluify/$", staff_member_required(MARCUngluifyView.as_view()), name="MARCUngluify"),

View File

@ -75,7 +75,7 @@ from regluit.core.bookloader import merge_works, detach_edition
from regluit.core.goodreads import GoodreadsClient
from regluit.core.search import gluejar_search
from regluit.core.signals import supporter_message
from regluit.core.tasks import send_mail_task, emit_notifications
from regluit.core.tasks import send_mail_task, emit_notifications, watermark_acq
from regluit.core.parameters import *
from regluit.frontend.forms import (
@ -443,7 +443,7 @@ def edition_uploads(request, edition_id):
# campaign mangager gets a copy
test_acq = models.Acq.objects.create(user=request.user,work=edition.work,license= TESTING)
try:
test_acq.get_epub_url()
test_acq.get_watermarked()
context['watermarked']= test_acq.watermarked
except (BooXtreamError, ET.ParseError) as e:
context['upload_error']= e
@ -684,12 +684,6 @@ def googlebooks(request, googlebooks_id):
return HttpResponseRedirect(work_url)
def download_ebook(request, ebook_id):
ebook = get_object_or_404(models.Ebook,id=ebook_id)
ebook.increment()
logger.info("ebook: {0}, user_ip: {1}".format(ebook_id, request.META['REMOTE_ADDR']))
return HttpResponseRedirect(ebook.url)
def subjects(request):
order = request.GET.get('order')
subjects = models.Subject.objects.all()
@ -2552,28 +2546,49 @@ def download(request, work_id):
unglued_ebooks = work.ebooks().filter(edition__unglued=True)
other_ebooks = work.ebooks().filter(edition__unglued=False)
formats = {}
acq=None
formats = {} # a dict of format name and url
for ebook in work.ebooks().all():
formats[ebook.format] = ebook
formats[ebook.format] = reverse('download_ebook', ebook.id )
# google ebooks have a captcha which breaks some of our services
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
try:
kindle_ebook_id = non_google_ebooks.filter(format='mobi')[0].id
except IndexError:
if request.user.is_authenticated():
all_acqs=request.user.acqs.filter(work=work).order_by('-created')
for an_acq in all_acqs:
if not an_acq.expired:
# prepare this acq for download
if not an_acq.watermarked or an_acq.watermarked.expired:
watermark_acq.delay(an_acq)
acq = an_acq
formats['epub']= reverse('download_acq', kwargs={'nonce':acq.nonce, 'format':'epub'})
formats['mobi']= reverse('download_acq', kwargs={'nonce':acq.nonce, 'format':'mobi'})
readmill_epub_url = settings.BASE_URL_SECURE + formats['epub']
can_kindle = True
break
if not acq:
# google ebooks have a captcha which breaks some of our services
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
#send to kindle
try:
kindle_ebook_id = non_google_ebooks.filter(format='pdf')[0].id
non_google_ebooks.filter(format='mobi')[0]
can_kindle = True
except IndexError:
kindle_ebook_id = None
try:
readmill_epub_ebook = non_google_ebooks.filter(format='epub')[0]
#readmill_epub_url = settings.BASE_URL_SECURE + reverse('download_ebook',args=[readmill_epub_ebook.id])
readmill_epub_url = readmill_epub_ebook.url
except:
readmill_epub_url = None
try:
non_google_ebooks.filter(format='pdf')[0]
can_kindle = True
except IndexError:
can_kindle = False
# configure the readmillurl
try:
readmill_epub_ebook = non_google_ebooks.filter(format='epub')[0]
readmill_epub_url = settings.BASE_URL_SECURE + reverse('download_ebook',args=[readmill_epub_ebook.id])
#readmill_epub_url = readmill_epub_ebook.url
except:
readmill_epub_url = None
agent = request.META.get('HTTP_USER_AGENT','')
iOS = 'iPad' in agent or 'iPhone' in agent or 'iPod' in agent
iOS_app = iOS and not 'Safari' in agent
@ -2583,21 +2598,35 @@ def download(request, work_id):
'unglued_ebooks': unglued_ebooks,
'other_ebooks': other_ebooks,
'formats': formats,
'kindle_ebook_id': kindle_ebook_id,
'readmill_epub_url': readmill_epub_url,
'can_kindle': can_kindle,
'base_url': settings.BASE_URL_SECURE,
'iOS': iOS,
'iOS_app': iOS_app,
'android': android,
'desktop': desktop
'desktop': desktop,
'acq':acq,
})
return render(request, "download.html", context)
def download_ebook(request, ebook_id):
ebook = get_object_or_404(models.Ebook,id=ebook_id)
ebook.increment()
logger.info("ebook: {0}, user_ip: {1}".format(ebook_id, request.META['REMOTE_ADDR']))
return HttpResponseRedirect(ebook.url)
def download_purchased(request, work_id):
if request.user.is_anonymous:
HttpResponseRedirect('/accounts/login/download/')
return download(request, work_id)
def download_acq(request, nonce, format):
acq = get_object_or_404(models.Acq,nonce=nonce)
if format == 'epub':
return HttpResponseRedirect( acq.get_epub_url() )
else:
return HttpResponseRedirect( acq.get_mobi_url() )
def about(request, facet):
template = "about_" + facet + ".html"
@ -2652,19 +2681,8 @@ def press_submitterator(request):
})
@login_required
def kindle_config(request, kindle_ebook_id=None):
def get_title_from_kindle_id(kindle_ebook_id):
# protect against user URL manipulation
work = None
if kindle_ebook_id:
try:
ebook = models.Ebook.objects.get(pk=kindle_ebook_id)
work = ebook.edition.work
except:
kindle_ebook_id = None
return work, kindle_ebook_id
(work, kindle_ebook_id) = get_title_from_kindle_id(kindle_ebook_id)
def kindle_config(request, work_id=None):
work = safe_get_work(work_id)
template = "kindle_config.html"
if request.method == 'POST':
form = KindleEmailForm(request.POST)
@ -2674,15 +2692,12 @@ def kindle_config(request, kindle_ebook_id=None):
template = "kindle_change_successful.html"
else:
form = KindleEmailForm()
return render(
request,
template,
{'form': form, 'kindle_ebook_id': kindle_ebook_id, 'work': work}
)
return render(request, template, {'form': form, 'work': work})
@require_POST
@csrf_exempt
def send_to_kindle(request, kindle_ebook_id, javascript='0'):
def send_to_kindle(request, work_id, javascript='0'):
# make sure to gracefully communicate with both js and non-js (kindle!) users
def local_response(request, javascript, message):
if javascript == '1':
@ -2691,8 +2706,36 @@ def send_to_kindle(request, kindle_ebook_id, javascript='0'):
# can't pass context with HttpResponseRedirect
# must use an HttpResponse, not a render(), after POST
return HttpResponseRedirect(reverse('send_to_kindle_graceful', args=(message,)))
work=safe_get_work(work_id)
acq = None
if request.user.is_authenticated():
try:
acq = request.user.acqs.filter(work=work).order_by('-created')[0]
except IndexError:
acq = None
if acq:
eboook_url = acq.get_mobi_url()
ebook_format = 'mobi'
title = acq.work.title
else:
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
try:
ebook = non_google_ebooks.filter(format='mobi')[0]
except IndexError:
try:
ebook = non_google_ebooks.filter(format='pdf')[0]
except IndexError:
raise Http404
ebook = models.Ebook.objects.get(pk=kindle_ebook_id)
# don't forget to increment the download counter!
ebook.increment()
eboook_url = ebook.url
ebook_format = ebook.format
logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR']))
title = ebook.edition.title
title = title.replace(' ', '_')
if request.POST.has_key('kindle_email'):
kindle_email = request.POST['kindle_email']
@ -2704,13 +2747,7 @@ def send_to_kindle(request, kindle_ebook_id, javascript='0'):
elif request.user.is_authenticated():
kindle_email = request.user.profile.kindle_email
# don't forget to increment the download counter!
assert ebook.format == 'mobi' or ebook.format == 'pdf'
ebook.increment()
logger.info('ebook: {0}, user_ip: {1}'.format(kindle_ebook_id, request.META['REMOTE_ADDR']))
title = ebook.edition.title
title = title.replace(' ', '_')
"""
TO FIX rigorously:
@ -2725,16 +2762,16 @@ def send_to_kindle(request, kindle_ebook_id, javascript='0'):
* mime encoding will add 33% to filesize
This won't perfectly measure size of email, but should be safe, and is much faster than doing the check after download.
"""
filehandle = urllib.urlopen(ebook.url)
filehandle = urllib.urlopen(ebook_url)
filesize = int(filehandle.info().getheaders("Content-Length")[0])
if filesize > 7492232:
logger.info('ebook %s is too large to be emailed' % kindle_ebook_id)
logger.info('ebook %s is too large to be emailed' % work.id)
return local_response(request, javascript, 0)
try:
email = EmailMessage(from_email='notices@gluejar.com',
to=[kindle_email])
email.attach(title + '.' + ebook.format, filehandle.read())
email.attach(title + '.' + ebook_format, filehandle.read())
email.send()
except:
logger.warning('Unexpected error: %s', sys.exc_info())

View File

@ -24,9 +24,9 @@ $j(document).on('click', '.other_instructions', function(e) {
$j(document).on('click', '#kindle.authenticated', function() {
var myDiv = $j(this);
kindle_ebook_id = myDiv.attr('title');
work_id = myDiv.attr('title');
myDiv.html('<img src="/static/images/loading.gif">')
$j.post('/send_to_kindle/' + kindle_ebook_id + '/1/', function(data) {
$j.post('/send_to_kindle/' + work_id + '/1/', function(data) {
myDiv.removeClass('btn_support');
myDiv.html(data);
myDiv.removeAttr('id');