Merge branch 'master' into webhooks
commit
645c7d41da
|
@ -285,12 +285,14 @@ 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':
|
||||
return False
|
||||
|
@ -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,6 +315,10 @@ class Campaign(models.Model):
|
|||
action.save()
|
||||
if send_notice:
|
||||
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
|
||||
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
|
||||
|
@ -481,15 +491,11 @@ class Campaign(models.Model):
|
|||
def rightsholder(self):
|
||||
"""returns the name of the rights holder for an active or initialized campaign"""
|
||||
try:
|
||||
# BUGBUG: why should the RH be dependent on the status of a campaign?
|
||||
# for the moment, I'll extend this logic to include 'SUCCESSFUL' campaigns too
|
||||
if self.status in ('ACTIVE', 'INITIALIZED', 'SUCCESSFUL'):
|
||||
q = Q(status='ACTIVE') | Q(status='INITIALIZED')
|
||||
rh = self.work.claim.filter(q)[0].rights_holder.rights_holder_name
|
||||
return rh
|
||||
q = Q(status='ACTIVE') | Q(status='INITIALIZED')
|
||||
rh = self.work.claim.filter(q)[0].rights_holder.rights_holder_name
|
||||
return rh
|
||||
except:
|
||||
pass
|
||||
return ''
|
||||
return ''
|
||||
|
||||
@property
|
||||
def license_url(self):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
|
||||
{% block news %}
|
||||
<div class="launch_top">
|
||||
We unglued <a href="/work/81834/">one book</a>. Amazon <a href="http://blog.unglue.it/2012/08/09/open-thread-amazon-forces-unglue-it-to-suspend-crowdfunding-for-creative-commons-ebooks/">shut us down</a>. Now we're back. Help us unglue <a href="https://unglue.it/campaigns/ending">five more books</a>! <br />
|
||||
We unglued <a href="/work/81834/">one book</a>. Amazon <a href="http://blog.unglue.it/2012/08/09/open-thread-amazon-forces-unglue-it-to-suspend-crowdfunding-for-creative-commons-ebooks/">shut us down</a>. Now we're back. Help us unglue <a href="https://unglue.it/campaigns/ending">four more books</a>! <br />
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
now = lambda: _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()
|
||||
|
||||
# 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