Skip to content
Snippets Groups Projects
Commit fb8906af authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Get the open round and allow for open ended rounds on the front end

parent 45b6fd19
No related branches found
No related tags found
No related merge requests found
...@@ -50,12 +50,16 @@ class FundType(AbstractStreamForm): ...@@ -50,12 +50,16 @@ class FundType(AbstractStreamForm):
def workflow_class(self): def workflow_class(self):
return WORKFLOW_CLASS[self.get_workflow_display()] return WORKFLOW_CLASS[self.get_workflow_display()]
def next_deadline(self): @property
def open_round(self):
rounds = Round.objects.child_of(self).live().public().specific() rounds = Round.objects.child_of(self).live().public().specific()
open_rounds = rounds.filter( return rounds.filter(
end_date__gte=date.today(), Q(start_date__lte=date.today()) &
) Q(Q(end_date__isnull=True) | Q(end_date__gte=date.today()))
return open_rounds.first().end_date ).first()
def next_deadline(self):
return self.open_round.end_date
content_panels = AbstractStreamForm.content_panels + [ content_panels = AbstractStreamForm.content_panels + [
FieldPanel('workflow'), FieldPanel('workflow'),
......
...@@ -8,12 +8,50 @@ from opentech.apply.funds.workflow import SingleStage ...@@ -8,12 +8,50 @@ from opentech.apply.funds.workflow import SingleStage
from .factories import FundTypeFactory, RoundFactory from .factories import FundTypeFactory, RoundFactory
def days_from_today(days):
return date.today() + timedelta(days=days)
class TestFundModel(TestCase): class TestFundModel(TestCase):
def test_can_access_workflow_class(self): def test_can_access_workflow_class(self):
fund = FundTypeFactory(parent=None) fund = FundTypeFactory(parent=None)
self.assertEqual(fund.workflow, 'single') self.assertEqual(fund.workflow, 'single')
self.assertEqual(fund.workflow_class, SingleStage) self.assertEqual(fund.workflow_class, SingleStage)
def test_no_open_rounds(self):
fund = FundTypeFactory(parent=None)
self.assertIsNone(fund.open_round)
def test_open_ended_round(self):
fund = FundTypeFactory(parent=None)
open_round = RoundFactory(end_date=None, parent=fund)
self.assertEqual(fund.open_round, open_round)
def test_normal_round(self):
fund = FundTypeFactory(parent=None)
open_round = RoundFactory(parent=fund)
self.assertEqual(fund.open_round, open_round)
def test_closed_round(self):
fund = FundTypeFactory(parent=None)
yesterday = days_from_today(-1)
last_week = days_from_today(-7)
RoundFactory(start_date=last_week, end_date=yesterday, parent=fund)
self.assertIsNone(fund.open_round)
def test_round_not_open(self):
fund = FundTypeFactory(parent=None)
tomorrow = days_from_today(1)
RoundFactory(start_date=tomorrow, parent=fund)
self.assertIsNone(fund.open_round)
def test_multiple_open_rounds(self):
fund = FundTypeFactory(parent=None)
open_round = RoundFactory(parent=fund)
next_round_start = open_round.end_date + timedelta(days=1)
RoundFactory(start_date=next_round_start, end_date=None, parent=fund)
self.assertEqual(fund.open_round, open_round)
class TestRoundModel(TestCase): class TestRoundModel(TestCase):
def setUp(self): def setUp(self):
......
...@@ -47,6 +47,10 @@ class FundPage(BasePage): ...@@ -47,6 +47,10 @@ class FundPage(BasePage):
InlinePanel('related_pages', label="Related pages"), InlinePanel('related_pages', label="Related pages"),
] ]
@property
def has_open(self):
return bool(self.fund_type.specific.open_round)
@property @property
def deadline(self): def deadline(self):
return self.fund_type.specific.next_deadline() return self.fund_type.specific.next_deadline()
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
<div class="wrapper wrapper--flex"> <div class="wrapper wrapper--flex">
<div class="section section--apply-cta"> <div class="section section--apply-cta">
{% if fund_page.deadline %} {% if fund_page.has_open %}
{% if fund_page.deadline %}
<div class="deadline"> <div class="deadline">
{% trans "Next deadline" %}: {{ fund_page.deadline|date:"M j, Y" }} {% trans "Next deadline" %}: {{ fund_page.deadline|date:"M j, Y" }}
</div> </div>
{% endif %}
<div class="apply-link"> <div class="apply-link">
<a class="button" href="{% pageurl fund_page.fund_type %}">{% trans "Apply for this fund" %}</a> <a class="button" href="{% pageurl fund_page.fund_type %}">{% trans "Apply for this fund" %}</a>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment