Merge branch 'campaign_close' into charge_failed

pull/1/head
Raymond Yee 2012-11-15 14:38:23 -08:00
commit 02dd7a55da
3 changed files with 58 additions and 14 deletions

View File

@ -306,6 +306,7 @@ class Campaign(models.Model):
if process_transactions:
p = PaymentManager()
results = p.execute_campaign(self)
# should be more sophisticated in whether to return True -- look at all the transactions
return True
elif self.deadline < now() and self.current_total < self.target:
self.status = 'UNSUCCESSFUL'
@ -314,10 +315,11 @@ class Campaign(models.Model):
action.save()
if send_notice:
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
return True
if process_transactions:
p = PaymentManager()
results = p.cancel_campaign(self)
# should be more sophisticated in whether to return True -- look at all the transactions
return True
else:
return False

View File

@ -5,6 +5,7 @@ from regluit.utils.localdatetime import now, date_today
from django.test import TestCase
from django.test.client import Client
from django.utils import unittest
from django.test.utils import override_settings
from django.db import IntegrityError
from django.contrib.auth.models import User
from django.conf import settings
@ -24,7 +25,7 @@ from regluit.core import tasks
from celery.task.sets import TaskSet
from celery.task import chord
from time import sleep
from time import sleep, mktime
from math import factorial
from urlparse import parse_qs, urlparse
@ -649,3 +650,46 @@ class DownloadPageTest(TestCase):
response = anon_client.get("/work/%s/download/" % w.id)
self.assertContains(response, "http://example.com", count=4)
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)

View File

@ -46,22 +46,20 @@ from django.conf import settings
# 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
# if there is a LOCALDATETIME_NOW in the Django settings, use that to be _now
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
_now = settings.LOCALDATETIME_NOW
else:
def now():
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
return settings.LOCALDATETIME_NOW()
else:
try:
_now = django.utils.timezone.now
return django.utils.timezone.now()
except AttributeError, e:
_now = datetime.datetime.now
now = lambda: _now()
return datetime.datetime.now()
# provide a replacement for datetime.date.today()
# 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
# https://code.djangoproject.com/browser/django/trunk/django/utils/timezone.py