made the cc_date and test consistent whether its a date or a datetime

pull/1/head
eric 2013-08-19 16:01:32 -04:00
parent 4a3cfc6840
commit 26c4d522b4
3 changed files with 35 additions and 27 deletions

View File

@ -315,30 +315,34 @@ class Campaign(models.Model):
@property
def launchable(self):
may_launch=True
if self.status != 'INITIALIZED':
if self.status == 'ACTIVE':
self.problems.append(_('The campaign is already launched'))
else:
self.problems.append(_('A campaign must initialized properly before it can be launched'))
try:
if self.status != 'INITIALIZED':
if self.status == 'ACTIVE':
self.problems.append(_('The campaign is already launched'))
else:
self.problems.append(_('A campaign must initialized properly before it can be launched'))
may_launch = False
if self.target < Decimal(settings.UNGLUEIT_MINIMUM_TARGET):
self.problems.append(_('A campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
may_launch = False
if self.type==REWARDS and self.deadline.date()- date_today() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
self.problems.append(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
may_launch = False
elif self.deadline.date()- date_today() < timedelta(days=0):
self.problems.append(_('The chosen closing date is in the past'))
may_launch = False
if self.type==BUY2UNGLUE and self.work.offers.filter(price__gt=0,active=True).count()==0:
self.problems.append(_('You can\'t launch a buy-to-unglue campaign before setting a price for your ebooks' ))
may_launch = False
if self.type==BUY2UNGLUE and EbookFile.objects.filter(edition__work=self.work).count()==0:
self.problems.append(_('You can\'t launch a buy-to-unglue campaign if you don\'t have any ebook files uploaded' ))
may_launch = False
if self.type==BUY2UNGLUE and ((self.cc_date_initial is None) or (self.cc_date_initial > datetime.combine(settings.MAX_CC_DATE, datetime.min.time())) or (self.cc_date_initial < now())):
self.problems.append(_('You must set an initial CC Date that is in the future and not after %s' % settings.MAX_CC_DATE ))
may_launch = False
except Exception as e :
self.problems.append('Exception checking launchability ' + str(e))
may_launch = False
if self.target < Decimal(settings.UNGLUEIT_MINIMUM_TARGET):
self.problems.append(_('A campaign may not be launched with a target less than $%s' % settings.UNGLUEIT_MINIMUM_TARGET))
may_launch = False
if self.type==REWARDS and self.deadline.date()- date_today() > timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)):
self.problems.append(_('The chosen closing date is more than %s days from now' % settings.UNGLUEIT_LONGEST_DEADLINE))
may_launch = False
elif self.deadline.date()- date_today() < timedelta(days=0):
self.problems.append(_('The chosen closing date is in the past'))
may_launch = False
if self.type==BUY2UNGLUE and self.work.offers.filter(price__gt=0,active=True).count()==0:
self.problems.append(_('You can\'t launch a buy-to-unglue campaign before setting a price for your ebooks' ))
may_launch = False
if self.type==BUY2UNGLUE and EbookFile.objects.filter(edition__work=self.work).count()==0:
self.problems.append(_('You can\'t launch a buy-to-unglue campaign if you don\'t have any ebook files uploaded' ))
may_launch = False
if self.type==BUY2UNGLUE and ((self.cc_date_initial is None) or (self.cc_date_initial > settings.MAX_CC_DATE) or (self.cc_date_initial < date_today())):
self.problems.append(_('You must set an initial CC Date that is in the future and not after %s' % settings.MAX_CC_DATE ))
may_launch = False
return may_launch
@ -402,11 +406,14 @@ class Campaign(models.Model):
self.dollar_per_day = float(self.target)/float(time_to_cc.days)
self.save()
return self.dollar_per_day
def set_cc_date_initial(self, a_date=settings.MAX_CC_DATE):
self.cc_date_initial = datetime.combine(a_date, datetime.min.time())
@property
def cc_date(self):
if self.dollar_per_day is None:
return self.cc_date_initial
return self.cc_date_initial.date()
cc_advance_days = float(self.current_total) / self.dollar_per_day
return (self.cc_date_initial-timedelta(days=cc_advance_days)).date()

View File

@ -574,7 +574,8 @@ class CampaignTests(TestCase):
e1.save()
ebf1= models.EbookFile(edition=e1, format=1)
ebf1.save()
c1.cc_date_initial = settings.MAX_CC_DATE
c1.set_cc_date_initial()
self.assertEqual(c1.cc_date, settings.MAX_CC_DATE)
c1.target = D(settings.UNGLUEIT_MAXIMUM_TARGET)
c1.save()
self.assertEqual(c1.launchable, True)

View File

@ -1542,7 +1542,7 @@ def rh_tools(request):
if new_campaign.type==models.BUY2UNGLUE:
new_campaign.deadline = date_today() + settings.B2U_TERM
new_campaign.target = D(settings.UNGLUEIT_MAXIMUM_TARGET)
new_campaign.cc_date_initial = settings.MAX_CC_DATE
new_campaign.set_cc_date_initial()
else:
new_campaign.deadline = date_today() + timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE))
new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET)