Merge branch 'master' into empty_stripe_token
commit
601a0a3aee
|
@ -285,11 +285,13 @@ class Campaign(models.Model):
|
|||
return may_launch
|
||||
|
||||
|
||||
def update_status(self, ignore_deadline_for_success=False, send_notice=False):
|
||||
def update_status(self, ignore_deadline_for_success=False, send_notice=False, process_transactions=False):
|
||||
"""Updates the campaign's status. returns true if updated.
|
||||
Computes UNSUCCESSFUL only after the deadline has passed
|
||||
Computes SUCCESSFUL only after the deadline has passed if ignore_deadline_for_success is TRUE -- otherwise looks just at amount of pledges accumulated
|
||||
by default, send_notice is False so that we have to explicitly send specify delivery of successful_campaign notice
|
||||
|
||||
if process_transactions is True, also execute or cancel associated transactions
|
||||
|
||||
"""
|
||||
if not self.status=='ACTIVE':
|
||||
|
@ -301,6 +303,10 @@ class Campaign(models.Model):
|
|||
action.save()
|
||||
if send_notice:
|
||||
successful_campaign.send(sender=None,campaign=self)
|
||||
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'
|
||||
|
@ -309,7 +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
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ def send_mail_task(subject, message, from_email, recipient_list,
|
|||
@task
|
||||
def update_active_campaign_status():
|
||||
"""update the status of all active campaigns -- presumed to be run at midnight Eastern time"""
|
||||
return [c.update_status(send_notice=True) for c in Campaign.objects.filter(status='Active') ]
|
||||
return [c.update_status(send_notice=True, ignore_deadline_for_success=True, process_transactions=True) for c in Campaign.objects.filter(status='Active') ]
|
||||
|
||||
@task
|
||||
def emit_notifications():
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -653,3 +654,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)
|
||||
|
||||
|
||||
|
|
@ -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:
|
||||
try:
|
||||
_now = django.utils.timezone.now
|
||||
except AttributeError, e:
|
||||
_now = datetime.datetime.now
|
||||
def now():
|
||||
if hasattr(settings, 'LOCALDATETIME_NOW') and settings.LOCALDATETIME_NOW is not None:
|
||||
return settings.LOCALDATETIME_NOW()
|
||||
else:
|
||||
try:
|
||||
return django.utils.timezone.now()
|
||||
except AttributeError, e:
|
||||
return datetime.datetime.now()
|
||||
|
||||
now = lambda: _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
|
||||
|
|
Loading…
Reference in New Issue