Merge branch 'campaign_close' into charge_failed
commit
02dd7a55da
|
@ -306,6 +306,7 @@ class Campaign(models.Model):
|
||||||
if process_transactions:
|
if process_transactions:
|
||||||
p = PaymentManager()
|
p = PaymentManager()
|
||||||
results = p.execute_campaign(self)
|
results = p.execute_campaign(self)
|
||||||
|
# should be more sophisticated in whether to return True -- look at all the transactions
|
||||||
return True
|
return True
|
||||||
elif self.deadline < now() and self.current_total < self.target:
|
elif self.deadline < now() and self.current_total < self.target:
|
||||||
self.status = 'UNSUCCESSFUL'
|
self.status = 'UNSUCCESSFUL'
|
||||||
|
@ -314,10 +315,11 @@ class Campaign(models.Model):
|
||||||
action.save()
|
action.save()
|
||||||
if send_notice:
|
if send_notice:
|
||||||
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
|
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
|
||||||
return True
|
|
||||||
if process_transactions:
|
if process_transactions:
|
||||||
p = PaymentManager()
|
p = PaymentManager()
|
||||||
results = p.cancel_campaign(self)
|
results = p.cancel_campaign(self)
|
||||||
|
# should be more sophisticated in whether to return True -- look at all the transactions
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from regluit.utils.localdatetime import now, date_today
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import Client
|
from django.test.client import Client
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
from django.test.utils import override_settings
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -24,7 +25,7 @@ from regluit.core import tasks
|
||||||
from celery.task.sets import TaskSet
|
from celery.task.sets import TaskSet
|
||||||
from celery.task import chord
|
from celery.task import chord
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep, mktime
|
||||||
from math import factorial
|
from math import factorial
|
||||||
from urlparse import parse_qs, urlparse
|
from urlparse import parse_qs, urlparse
|
||||||
|
|
||||||
|
@ -649,3 +650,46 @@ class DownloadPageTest(TestCase):
|
||||||
response = anon_client.get("/work/%s/download/" % w.id)
|
response = anon_client.get("/work/%s/download/" % w.id)
|
||||||
self.assertContains(response, "http://example.com", count=4)
|
self.assertContains(response, "http://example.com", count=4)
|
||||||
self.assertContains(response, "http://example2.com", count=3)
|
self.assertContains(response, "http://example2.com", count=3)
|
||||||
|
|
||||||
|
|
||||||
|
class LocaldatetimeTest(TestCase):
|
||||||
|
@override_settings(LOCALDATETIME_NOW=None)
|
||||||
|
def test_LOCALDATETIME_NOW_none(self):
|
||||||
|
|
||||||
|
try:
|
||||||
|
localdatetime.now
|
||||||
|
except NameError:
|
||||||
|
from regluit.utils import localdatetime
|
||||||
|
else:
|
||||||
|
reload(localdatetime)
|
||||||
|
|
||||||
|
self.assertAlmostEqual(mktime(datetime.now().timetuple()), mktime(localdatetime.now().timetuple()), 1.0)
|
||||||
|
|
||||||
|
@override_settings(LOCALDATETIME_NOW=lambda : datetime.now() + timedelta(365))
|
||||||
|
def test_LOCALDATETIME_NOW_year_ahead(self):
|
||||||
|
|
||||||
|
try:
|
||||||
|
localdatetime.now
|
||||||
|
except NameError:
|
||||||
|
from regluit.utils import localdatetime
|
||||||
|
else:
|
||||||
|
reload(localdatetime)
|
||||||
|
|
||||||
|
self.assertAlmostEqual(mktime((datetime.now() + timedelta(365)).timetuple()), mktime(localdatetime.now().timetuple()), 1.0)
|
||||||
|
|
||||||
|
def test_no_time_override(self):
|
||||||
|
|
||||||
|
from regluit.utils import localdatetime
|
||||||
|
self.assertAlmostEqual(mktime(datetime.now().timetuple()), mktime(localdatetime.now().timetuple()), 1.0)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
# restore localdatetime.now() to what's in the settings file
|
||||||
|
try:
|
||||||
|
localdatetime.now
|
||||||
|
except NameError:
|
||||||
|
from regluit.utils import localdatetime
|
||||||
|
else:
|
||||||
|
reload(localdatetime)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,22 +46,20 @@ from django.conf import settings
|
||||||
# for Django 1.4 should switch to django.utils.timezone.now()
|
# for Django 1.4 should switch to django.utils.timezone.now()
|
||||||
# see https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py?rev=17642#L232
|
# see https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py?rev=17642#L232
|
||||||
|
|
||||||
# if there is a LOCALDATETIME_NOW in the Django settings, use that to be _now
|
def now():
|
||||||
|
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
|
||||||
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
|
return settings.LOCALDATETIME_NOW()
|
||||||
_now = settings.LOCALDATETIME_NOW
|
else:
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
_now = django.utils.timezone.now
|
return django.utils.timezone.now()
|
||||||
except AttributeError, e:
|
except AttributeError, e:
|
||||||
_now = datetime.datetime.now
|
return datetime.datetime.now()
|
||||||
|
|
||||||
now = lambda: _now()
|
|
||||||
|
|
||||||
# provide a replacement for datetime.date.today()
|
# provide a replacement for datetime.date.today()
|
||||||
# this will be timezone naive -- is that what we really want?
|
# this will be timezone naive -- is that what we really want?
|
||||||
|
|
||||||
date_today = lambda: _now().date()
|
def date_today():
|
||||||
|
return now().date()
|
||||||
|
|
||||||
# borrow a lot of the routines/code that will be in Django 1.4+ django.utils.timezone
|
# borrow a lot of the routines/code that will be in Django 1.4+ django.utils.timezone
|
||||||
# https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py
|
# https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py
|
||||||
|
|
Loading…
Reference in New Issue