move latest ending logic from form to model/settings

pull/1/head
eric 2013-06-17 17:12:58 -04:00
parent 3ea697c768
commit 1ea77acf09
5 changed files with 8 additions and 4 deletions

View File

@ -589,6 +589,10 @@ class Campaign(models.Model):
return countdown
@classmethod
def latest_ending(cls):
return (timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)) + now())
class Identifier(models.Model):
# olib, ltwk, goog, gdrd, thng, isbn, oclc, olwk, olib, gute, glue
type = models.CharField(max_length=4, null=False)

View File

@ -438,7 +438,7 @@ class CampaignTests(TestCase):
w2 = Work()
w2.save()
# INITIALIZED
c1 = Campaign(target=D('1000.00'),deadline=datetime(2013,1,1),work=w)
c1 = Campaign(target=D('1000.00'),deadline=Campaign.latest_ending(),work=w)
c1.save()
self.assertEqual(c1.status, 'INITIALIZED')
# ACTIVATED

View File

@ -3,7 +3,7 @@ external library imports
"""
import logging
from datetime import timedelta
from datetime import timedelta, datetime
from decimal import Decimal as D
"""
@ -354,7 +354,6 @@ def getManageCampaignForm ( instance, data=None, *args, **kwargs ):
target = forms.DecimalField( min_value= D(settings.UNGLUEIT_MINIMUM_TARGET), error_messages={'required': 'Please specify a target price.'} )
edition = forms.ModelChoiceField(get_queryset(), widget=RadioSelect(),empty_label='no edition selected',required = False,)
minimum_target = settings.UNGLUEIT_MINIMUM_TARGET
latest_ending = (timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)) + now()).date
publisher = forms.ModelChoiceField(instance.work.publishers(), empty_label='no publisher selected', required = False,)
class Meta:

View File

@ -228,8 +228,8 @@ Please fix the following before launching your campaign:
<h3>Ending date</h3>
<p> This is the ending date of your campaign. Once you launch the campaign, you won't be able to change it.</p>
<p>The ending date can't be more than six months away- that's a practical limit for credit card authorizations. The <i>latest</i> ending you can choose <i>right now</i> is {{ form.latest_ending }}</p>
<p>The ending date can't be more than six months away- that's a practical limit for credit card authorizations. The <i>latest</i> ending you can choose <i>right now</i> is {{ campaign.latest_ending }}</p>
{{ form.deadline.errors }}{{ form.deadline }}
{% else %}

View File

@ -262,6 +262,7 @@ GOODREADS_API_SECRET = ""
UNGLUEIT_MINIMUM_TARGET = '500' # in US Dollars
UNGLUEIT_LONGEST_DEADLINE = '180' # number of days allowed for a campaign
UNGLUEIT_RECOMMENDED_USERNAME = 'unglueit'
B2U_ENDING = datetime.datetime(datetime.datetime.now().year+5,12,31)
TEST_RUNNER = "djcelery.contrib.test_runner.CeleryTestSuiteRunner"
import djcelery