user can buy multiple library licenses [#59827932]

also, some logic needed cleaning for setting expires on reserves
pull/1/head
eric 2013-11-01 16:15:01 -04:00
parent 143b24c368
commit 6bdbe1d046
4 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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):

View File

@ -91,6 +91,7 @@
<span class="menu-item-desc">Individual license already purchased!</span>
{% else %}
<label for="offer_{{offer.id}}">
<input type="hidden" name="copies" value="1" />
<input type="radio" name="offer_id" id="offer_{{offer.id}}" value="{{offer.id}}" {% ifequal request.REQUEST.offer_id offer.id|stringformat:"s" %}checked="checked"{% else %} {% ifequal offer_id offer.id %}checked="checked"{% endifequal %}{% endifequal %} />
<span class="menu-item-price">
${{ offer.price|intcomma }}
@ -111,12 +112,13 @@
${{ offer.price|intcomma }}
</span>
<span class="menu-item-desc">
<input type="text" name="copies" value="1" size="2" />
{{ offer.get_license_display }} for
<select name="library_id" class="std_form">
{% for library in request.user.profile.libraries %}
<option value="{{library.id}}">{{ library }}</option>
{% endfor %}
</select>
</select>{{ form.copies.errors }}{{ form.library_id.errors }}
</span>
</label>
{% else %}
@ -130,6 +132,7 @@
{% else %}
<div style="height:10px;"></div>
<input type="hidden" name="offer_id" id="offer_{{ offers.0.id }}" value="{{ offers.0.id }}" checked="checked" />
<input type="hidden" name="copies" value="1" />
{% endif %}