added edition to campaign model to allow selection of a preferred edition [finish #28736373]
parent
c0625d78b8
commit
1c2e48bc87
|
@ -0,0 +1,218 @@
|
|||
# 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 'Campaign.edition'
|
||||
db.add_column('core_campaign', 'edition', self.gf('django.db.models.fields.related.ForeignKey')(related_name='campaigns', null=True, to=orm['core.Edition']), keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Deleting field 'Campaign.edition'
|
||||
db.delete_column('core_campaign', 'edition_id')
|
||||
|
||||
|
||||
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, 4, 30, 16, 55, 2, 205843)', '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'}),
|
||||
'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': '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'}),
|
||||
'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']
|
|
@ -115,6 +115,7 @@ class Campaign(models.Model):
|
|||
managers = models.ManyToManyField(User, related_name="campaigns", null=False)
|
||||
# status: INITIALIZED, ACTIVE, SUSPENDED, WITHDRAWN, SUCCESSFUL, UNSUCCESSFUL
|
||||
status = models.CharField(max_length=15, null=True, blank=False, default="INITIALIZED")
|
||||
edition = models.ForeignKey("Edition", related_name="campaigns", null=True)
|
||||
problems = []
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -323,13 +324,13 @@ class Work(models.Model):
|
|||
|
||||
def cover_image_small(self):
|
||||
try:
|
||||
return self.editions.all()[0].cover_image_small()
|
||||
return self.preferred_edition.cover_image_small()
|
||||
except IndexError:
|
||||
return "/static/images/generic_cover_larger.png"
|
||||
|
||||
def cover_image_thumbnail(self):
|
||||
try:
|
||||
return self.editions.all()[0].cover_image_thumbnail()
|
||||
return self.preferred_edition.cover_image_thumbnail()
|
||||
except IndexError:
|
||||
return "/static/images/generic_cover_larger.png"
|
||||
|
||||
|
@ -352,6 +353,13 @@ class Work(models.Model):
|
|||
self._last_campaign_ = None
|
||||
return self._last_campaign_
|
||||
|
||||
@property
|
||||
def preferred_edition(self):
|
||||
if self.last_campaign():
|
||||
if self.last_campaign().edition:
|
||||
return self.last_campaign().edition
|
||||
return self.editions.all()[0]
|
||||
|
||||
def last_campaign_status(self):
|
||||
campaign = self.last_campaign()
|
||||
if campaign:
|
||||
|
@ -494,7 +502,14 @@ class Edition(models.Model):
|
|||
work = models.ForeignKey("Work", related_name="editions", null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s (%s)" % (self.title, self.isbn_13)
|
||||
if self.isbn_13:
|
||||
return "%s (ISBN %s) %s" % (self.title, self.isbn_13, self.publisher)
|
||||
if self.oclc:
|
||||
return "%s (OCLC %s) %s" % (self.title, self.oclc, self.publisher)
|
||||
if self.googlebooks_id:
|
||||
return "%s (GOOG %s) %s" % (self.title, self.googlebooks_id, self.publisher)
|
||||
else:
|
||||
return "%s (GLUE %s) %s" % (self.title, self.id, self.publisher)
|
||||
|
||||
def cover_image_small(self):
|
||||
if self.googlebooks_id:
|
||||
|
|
|
@ -5,13 +5,14 @@ from django.contrib.auth.models import User
|
|||
from django.conf import settings
|
||||
from django.core.validators import validate_email
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.forms.widgets import RadioSelect
|
||||
from django.forms.extras.widgets import SelectDateWidget
|
||||
|
||||
from decimal import Decimal as D
|
||||
from selectable.forms import AutoCompleteSelectMultipleWidget,AutoCompleteSelectMultipleField
|
||||
from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField
|
||||
|
||||
from regluit.core.models import UserProfile, RightsHolder, Claim, Campaign, Premium, Ebook
|
||||
from regluit.core.models import UserProfile, RightsHolder, Claim, Campaign, Premium, Ebook, Edition
|
||||
from regluit.core.lookups import OwnerLookup
|
||||
|
||||
from regluit.utils.localdatetime import now
|
||||
|
@ -165,50 +166,56 @@ class CustomPremiumForm(forms.ModelForm):
|
|||
'type': forms.HiddenInput(attrs={'value':'XX'}),
|
||||
'limit': forms.TextInput(attrs={'value':'0'}),
|
||||
}
|
||||
|
||||
class ManageCampaignForm(forms.ModelForm):
|
||||
paypal_receiver = forms.EmailField(
|
||||
label=_("email address to collect Paypal funds"),
|
||||
max_length=100,
|
||||
error_messages={'required': 'You must enter the email associated with your Paypal account.'},
|
||||
)
|
||||
target = forms.DecimalField( min_value= D('0.00'), error_messages={'required': 'Please specify a target price.'} )
|
||||
class Meta:
|
||||
model = Campaign
|
||||
fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver'
|
||||
widgets = {
|
||||
'description': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
|
||||
'details': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
|
||||
'deadline': SelectDateWidget
|
||||
}
|
||||
|
||||
def clean_target(self):
|
||||
new_target = self.cleaned_data['target']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.target < new_target:
|
||||
raise forms.ValidationError(_('The fundraising target for an ACTIVE campaign cannot be increased.'))
|
||||
if new_target < D(settings.UNGLUEIT_MINIMUM_TARGET):
|
||||
raise forms.ValidationError(_('A campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
|
||||
return new_target
|
||||
|
||||
def clean_deadline(self):
|
||||
new_deadline = self.cleaned_data['deadline']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.deadline != new_deadline:
|
||||
raise forms.ValidationError(_('The closing date for an ACTIVE campaign cannot be changed.'))
|
||||
if new_deadline - now() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
|
||||
raise forms.ValidationError(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
|
||||
elif new_deadline - now() < timedelta(days=int(settings.UNGLUEIT_SHORTEST_DEADLINE)):
|
||||
raise forms.ValidationError(_('The chosen closing date is less than %s days from now' % settings.UNGLUEIT_SHORTEST_DEADLINE))
|
||||
return new_deadline
|
||||
|
||||
def clean_license(self):
|
||||
new_license = self.cleaned_data['license']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.license != new_license:
|
||||
raise forms.ValidationError(_('The license for an ACTIVE campaign cannot be changed.'))
|
||||
return new_license
|
||||
|
||||
def getManageCampaignForm ( instance, data=None, *args, **kwargs ):
|
||||
def get_queryset():
|
||||
work=instance.work
|
||||
return Edition.objects.filter(work = work)
|
||||
|
||||
class ManageCampaignForm(forms.ModelForm):
|
||||
paypal_receiver = forms.EmailField(
|
||||
label=_("email address to collect Paypal funds"),
|
||||
max_length=100,
|
||||
error_messages={'required': 'You must enter the email associated with your Paypal account.'},
|
||||
)
|
||||
target = forms.DecimalField( min_value= D('0.00'), error_messages={'required': 'Please specify a target price.'} )
|
||||
edition = forms.ModelChoiceField(get_queryset(), widget=RadioSelect(),empty_label='no edition selected')
|
||||
|
||||
class Meta:
|
||||
model = Campaign
|
||||
fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver', 'edition'
|
||||
widgets = {
|
||||
'description': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
|
||||
'details': forms.Textarea(attrs={'cols': 80, 'rows': 20}),
|
||||
'deadline': SelectDateWidget,
|
||||
}
|
||||
|
||||
def clean_target(self):
|
||||
new_target = self.cleaned_data['target']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.target < new_target:
|
||||
raise forms.ValidationError(_('The fundraising target for an ACTIVE campaign cannot be increased.'))
|
||||
if new_target < D(settings.UNGLUEIT_MINIMUM_TARGET):
|
||||
raise forms.ValidationError(_('A campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
|
||||
return new_target
|
||||
|
||||
def clean_deadline(self):
|
||||
new_deadline = self.cleaned_data['deadline']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.deadline != new_deadline:
|
||||
raise forms.ValidationError(_('The closing date for an ACTIVE campaign cannot be changed.'))
|
||||
if new_deadline - now() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
|
||||
raise forms.ValidationError(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
|
||||
elif new_deadline - now() < timedelta(days=int(settings.UNGLUEIT_SHORTEST_DEADLINE)):
|
||||
raise forms.ValidationError(_('The chosen closing date is less than %s days from now' % settings.UNGLUEIT_SHORTEST_DEADLINE))
|
||||
return new_deadline
|
||||
|
||||
def clean_license(self):
|
||||
new_license = self.cleaned_data['license']
|
||||
if self.instance:
|
||||
if self.instance.status == 'ACTIVE' and self.instance.license != new_license:
|
||||
raise forms.ValidationError(_('The license for an ACTIVE campaign cannot be changed.'))
|
||||
return new_license
|
||||
return ManageCampaignForm(instance = instance, data=data)
|
||||
|
||||
class CampaignPledgeForm(forms.Form):
|
||||
preapproval_amount = forms.DecimalField(
|
||||
|
|
|
@ -47,7 +47,7 @@ Or, <a href="{% url rightsholders %}">go back</a> to rights holder tools page.<b
|
|||
<h2 class="book-name">Title: <a href="{% url work campaign.work.id %}">{{ campaign.work.title }}</a></h2>
|
||||
<h3 class="book-author">Authors: {{ campaign.work.author }}</h3>
|
||||
<h3 class="book-year">Published: {{ campaign.work.publication_date }}</h3>
|
||||
<h3 class="book-author">Language: {{ campaign.work.editions.all.0.language }}</h3>
|
||||
<h3 class="book-author">Language: {{ campaign.work.language }}</h3>
|
||||
<p>Target Price: ${{ campaign.target }}</p>
|
||||
<p>End Date: {{ campaign.deadline|date:"M d, Y" }}</p>
|
||||
<p>Campaign status: {{ campaign.status }}</p>
|
||||
|
@ -58,6 +58,8 @@ Or, <a href="{% url rightsholders %}">go back</a> to rights holder tools page.<b
|
|||
<h3>Description of the work offered for ungluing</h3>
|
||||
<form action="#" method="POST">
|
||||
{% csrf_token %}
|
||||
<p> Please choose the edition that most closely matches the edition to be unglued:
|
||||
{{ form.edition.errors }}{{ form.edition }}
|
||||
<p>This will be displayed in the Campaign tab for your work. It's your main pitch to supporters. It should include:</p>
|
||||
<ul class="terms">
|
||||
<li>A synopsis of the work.</li>
|
||||
|
|
|
@ -44,7 +44,7 @@ from regluit.core.search import gluejar_search
|
|||
from regluit.core.goodreads import GoodreadsClient
|
||||
from regluit.frontend.forms import UserData, UserEmail, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm
|
||||
from regluit.frontend.forms import RightsHolderForm, UserClaimForm, LibraryThingForm, OpenCampaignForm
|
||||
from regluit.frontend.forms import ManageCampaignForm, DonateForm, CampaignAdminForm, EmailShareForm, FeedbackForm
|
||||
from regluit.frontend.forms import getManageCampaignForm, DonateForm, CampaignAdminForm, EmailShareForm, FeedbackForm
|
||||
from regluit.frontend.forms import EbookForm, CustomPremiumForm, EditManagersForm
|
||||
from regluit.payment.manager import PaymentManager
|
||||
from regluit.payment.models import Transaction
|
||||
|
@ -129,8 +129,11 @@ def work(request, work_id, action='display'):
|
|||
activetab = '1';
|
||||
except:
|
||||
activetab = '1';
|
||||
editions = work.editions.all().order_by('-publication_date')
|
||||
campaign = work.last_campaign()
|
||||
if campaign and campaign.edition:
|
||||
editions = [campaign.edition]
|
||||
else:
|
||||
editions = work.editions.all().order_by('-publication_date')
|
||||
if action == 'preview':
|
||||
work.last_campaign_status = 'ACTIVE'
|
||||
try:
|
||||
|
@ -220,9 +223,9 @@ def manage_campaign(request, id):
|
|||
new_premium_form = CustomPremiumForm(data={'campaign': campaign})
|
||||
else:
|
||||
alerts.append(_('New premium has not been added'))
|
||||
form = ManageCampaignForm(instance=campaign)
|
||||
form = getManageCampaignForm(instance=campaign)
|
||||
elif request.POST.has_key('save') or request.POST.has_key('launch') :
|
||||
form= ManageCampaignForm(instance=campaign, data=request.POST)
|
||||
form= getManageCampaignForm(instance=campaign, data=request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
alerts.append(_('Campaign data has been saved'))
|
||||
|
@ -244,10 +247,10 @@ def manage_campaign(request, id):
|
|||
selected_premium.type = 'XX'
|
||||
selected_premium.save()
|
||||
alerts.append(_('Premium %s has been inactivated'% premium_to_stop))
|
||||
form = ManageCampaignForm(instance=campaign)
|
||||
form = getManageCampaignForm(instance=campaign)
|
||||
new_premium_form = CustomPremiumForm(data={'campaign': campaign})
|
||||
else:
|
||||
form = ManageCampaignForm(instance=campaign)
|
||||
form = getManageCampaignForm(instance=campaign)
|
||||
new_premium_form = CustomPremiumForm(data={'campaign': campaign})
|
||||
|
||||
return render(request, 'manage_campaign.html', {
|
||||
|
|
Loading…
Reference in New Issue