diff --git a/core/models.py b/core/models.py index 71a91f1e..9677ff2b 100755 --- a/core/models.py +++ b/core/models.py @@ -317,10 +317,10 @@ class Acq(models.Model): return hashlib.md5('1c1a56974ef08edc%s:%s:%s'%(self.user.id,self.work.id,self.created)).hexdigest() def expire_in(self, delta): - self.expires = now()+delta + self.expires = now() + delta self.save() if self.lib_acq: - self.lib_acq.refreshes = now()+ (timedelta(days=14)) + self.lib_acq.refreshes = now() + delta self.lib_acq.save() @property @@ -353,19 +353,16 @@ class Acq(models.Model): -def add_acq_nonce(sender, instance, created, **kwargs): +def config_acq(sender, instance, created, **kwargs): if created: instance.nonce=instance._hash() instance.save() -def set_expiration(sender, instance, created, **kwargs): - if created: if instance.license == RESERVE: instance.expire_in(timedelta(hours=2)) if instance.license == BORROWED: instance.expire_in(timedelta(days=14)) -post_save.connect(add_acq_nonce,sender=Acq) -post_save.connect(set_expiration,sender=Acq) +post_save.connect(config_acq,sender=Acq) class Campaign(models.Model): LICENSE_CHOICES = settings.CCCHOICES diff --git a/core/signals.py b/core/signals.py index 6db6ec30..20aba5b8 100644 --- a/core/signals.py +++ b/core/signals.py @@ -191,6 +191,10 @@ def handle_transaction_charged(sender,transaction=None, **kwargs): library = Library.objects.get(id=transaction.extra['library_id']) new_acq = Acq.objects.create(user=library.user,work=transaction.campaign.work,license= LIBRARY) reserve_acq = Acq.objects.create(user=transaction.user,work=transaction.campaign.work,license= RESERVE, lib_acq = new_acq) + copies = int(transaction.extra.get('copies',1)) + while copies > 1: + Acq.objects.create(user=library.user,work=transaction.campaign.work,license= LIBRARY) + copies -= 1 else: new_acq = Acq.objects.create(user=transaction.user,work=transaction.campaign.work,license= transaction.offer.license) transaction.campaign.update_left() diff --git a/frontend/forms.py b/frontend/forms.py index 63ff0807..e41ab84f 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -493,6 +493,7 @@ class CampaignPurchaseForm(forms.Form): offer=None library_id = forms.IntegerField(required=False) library = None + copies = forms.IntegerField(required=False,min_value=1) def clean_offer_id(self): offer_id = self.cleaned_data['offer_id'] @@ -516,7 +517,8 @@ class CampaignPurchaseForm(forms.Form): return self.cleaned_data def amount(self): - return self.offer.price if self.offer else None + + return self.offer.price * self.cleaned_data.get('copies',1) if self.offer else None @property def trans_extra(self): @@ -524,6 +526,7 @@ class CampaignPurchaseForm(forms.Form): offer = self.offer ) if self.library: pe.extra['library_id']=self.library.id + pe.extra['copies']=self.cleaned_data.get('copies',1) return pe class CampaignPledgeForm(forms.Form): diff --git a/frontend/templates/purchase.html b/frontend/templates/purchase.html index 0f218a7d..160eb933 100644 --- a/frontend/templates/purchase.html +++ b/frontend/templates/purchase.html @@ -91,6 +91,7 @@ Individual license already purchased! {% else %} {% else %} @@ -130,6 +132,7 @@ {% else %}
+ {% endif %}