diff --git a/hypha/apply/funds/models/applications.py b/hypha/apply/funds/models/applications.py index d8db5792fcfb64b61b7f4dcdc9fb8c304eecda0d..951efbabfe6c26b7c4f6ba4cfb82c396c7d2ac09 100644 --- a/hypha/apply/funds/models/applications.py +++ b/hypha/apply/funds/models/applications.py @@ -1,9 +1,11 @@ from datetime import date +from typing import Optional from django import forms from django.conf import settings from django.contrib.postgres.fields import ArrayField from django.core.exceptions import ValidationError +from django.core.handlers.wsgi import WSGIRequest from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.db.models import ( @@ -232,6 +234,18 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore ) sealed = models.BooleanField(default=False) + def get_url(self, request: Optional[WSGIRequest] = None) -> Optional[str]: + """Generates the live url, primarily used in the wagtail admin for the "view live" button. + + Returns: + str: The live url of the page, or None if the page is not live. + """ + if self.is_open: + return self.fund.url + return None + + url = property(get_url) + content_panels = SubmittableStreamForm.content_panels + [ FieldPanel("lead"), MultiFieldPanel( @@ -302,8 +316,19 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore return self.sealed and self.is_open @property - def is_open(self): - return self.start_date <= date.today() <= self.end_date + def is_open(self) -> bool: + """ + Checks if the application is open based on the current date. + + The application is considered open if the current date is between the start and end dates (inclusive). + If the end date is not set, the application is considered open if the current date is on or after the start date. + + Returns: + bool: True if the application is open, False otherwise. + """ + if self.start_date and self.end_date: + return self.start_date <= date.today() <= self.end_date + return self.start_date <= date.today() def save(self, *args, **kwargs): is_new = not self.id