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

Add dates and pass the deadline to the page

parent 5eaf55ba
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-18 16:24
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('funds', '0005_round'),
]
operations = [
migrations.AddField(
model_name='round',
name='end_date',
field=models.DateField(blank=True, default=datetime.date.today),
),
migrations.AddField(
model_name='round',
name='start_date',
field=models.DateField(blank=True, default=datetime.date.today),
),
]
from datetime import date
from django.core.exceptions import ValidationError
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.wagtailadmin.edit_handlers import (
FieldPanel,
InlinePanel,
FieldRowPanel,
MultiFieldPanel,
StreamFieldPanel,
)
from wagtail.wagtailcore.fields import StreamField
......@@ -43,6 +48,13 @@ class FundType(AbstractStreamForm):
def workflow_class(self):
return WORKFLOW_CLASS[self.get_workflow_display()]
def next_deadline(self):
rounds = Round.objects.child_of(self).live().public().specific()
open_rounds = rounds.filter(
end_date__gte=date.today(),
)
return open_rounds.first().end_date
content_panels = AbstractStreamForm.content_panels + [
FieldPanel('workflow'),
InlinePanel('forms', label="Forms"),
......@@ -75,6 +87,26 @@ class Round(AbstractStreamForm):
parent_page_types = ['funds.FundType']
subpage_types = [] # type: ignore
start_date = models.DateField(blank=True, default=date.today)
end_date = models.DateField(blank=True, default=date.today)
content_panels = AbstractStreamForm.content_panels + [
MultiFieldPanel([
FieldRowPanel([
FieldPanel('start_date'),
FieldPanel('end_date'),
]),
], heading="Dates")
]
def get_defined_fields(self):
# Only return the first form, will need updating for when working with 2 stage WF
return self.get_parent().specific.forms.all()[0].fields
def clean(self):
super().clean()
if self.start_date > self.end_date:
raise ValidationError({
'end_date': 'End date must come after the start date',
})
......@@ -47,6 +47,10 @@ class FundPage(BasePage):
InlinePanel('related_pages', label="Related pages"),
]
@property
def deadline(self):
return self.fund_type.specific.next_deadline()
class FundIndex(BasePage):
subpage_types = ['FundPage']
......
......@@ -2,7 +2,7 @@
{% load wagtailcore_tags wagtailimages_tags navigation_tags static %}
{% block content %}
{% include "public_funds/includes/fund_apply_cta.html" with fund_type=page.fund_type.specific %}
{% include "public_funds/includes/fund_apply_cta.html" with fund_page=page %}
<div class="wrapper wrapper--flex">
<section class="section section--main">
<h1>{{ page.title }}</h1>
......@@ -11,6 +11,6 @@
{% include_block page.body %}
</section>
</div>
{% include "public_funds/includes/fund_apply_cta.html" with fund_type=page.fund_type.specific %}
{% include "public_funds/includes/fund_apply_cta.html" with fund_page=page %}
{% include "includes/relatedcontent.html" with related_pages=page.related_pages.all %}
{% endblock %}
......@@ -2,12 +2,12 @@
<div class="wrapper wrapper--flex">
<div class="section section--apply-cta">
{% if fund_type.deadline %}
{% if fund_page.deadline %}
<div class="deadline">
{% trans "Next deadline" %}: {{ fund_type.deadline|date:"M j, Y" }}
{% trans "Next deadline" %}: {{ fund_page.deadline|date:"M j, Y" }}
</div>
<div class="apply-link">
<a class="button" href="{% pageurl fund_type %}">{% trans "Apply for this fund" %}</a>
<a class="button" href="{% pageurl fund_page.fund_type %}">{% trans "Apply for this fund" %}</a>
</div>
{% else %}
<div class="deadline">
......
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